Opened 8 years ago

Closed 8 years ago

#873 closed defect (invalid)

Segfault entering #'inspect during make-instance :around

Reported by: ec Owned by:
Priority: normal Milestone: Clozure CL 1.7
Component: Runtime (threads, GC) Version: trunk
Keywords: Cc:

Description

? (defclass test () ())
? (defmethod make-instance :around ((a standard-class) &rest args) (inspect (call-next-method)))
? (make-instance 'test)
Segfault

Change History (1)

comment:1 Changed 8 years ago by gb

  • Resolution set to invalid
  • Status changed from new to closed

You're saying that you want to call INSPECT every time that MAKE-INSTANCE is used to instantiate a standard-class.

Does INSPECT itself call MAKE-INSTANCE ? (It happens to in CCL.) Does this lead to unbounded recursion, and why am I talking like Donald Rumsfeld ?

It doesn't take too long for this to stack-overflow. Does calling MAKE-CONDITION (of a condition describing the stack-overflow) call MAKE-INSTANCE ? (It might, and happens to in CCL.)

I suppose that you could do something like:

(defvar *inspect-new-instances* nil)

(defclass test () ())

(defmethod make-instance :around ((a standard-class) &rest initargs)
  (declare (ignorable initargs))
  (if *inspect-new-instances*
    (let* ((*inspect-new-instances* nil))
      (inspect (call-next-method)))
    (call-next-method)))

(let* ((*inspect-new-instances* t)) (make-instance 'test))

If you don't do something to limit recursion like that, you'll just keep recursing until the stack is exhausted and you'll segfault.

Portable code shouldn't be defining methods on MAKE-INSTANCE and STANDARD-CLASS anyway; if the implementation defines such a method (and it's free to do so), your method would have overridden some (possibly critical) part of the implementation. (That happens not to be the case in CCL, but if it caused problems for some other implementation that wouldn't be that other implementation's fault ...)

I don't know whether it's worth having the implementation try to enforce this; there's something to be said for giving the user enough rope (as long as they don't act surprised when they hang themselves.)

Note: See TracTickets for help on using tickets.