[Openmcl-devel] patches, and a question

Gary Byers gb at clozure.com
Wed Oct 6 11:49:23 PDT 2004



On Wed, 6 Oct 2004, alex crain wrote:

>
> My question is this: If the append-edits slot is a native lisp type,
> and set the value to t, the call to setf generates the error:
>
> 2004-10-06 12:08:11.958 [9774] Error in event loop:
> #<HEMLOCK-TEXT-STORAGE HemlockTextStorage : string <HemlockBufferString
> for #<Hemlock Buffer "Untitled">> (#x184550)> has no slots.
>
> But if I make it :foreign-type and set the value to 1, it works.
>
> Why?
>

MAKE-OBJC-INSTANCE doesn't know how to make objects that have lisp
slots (MAKE-INSTANCE does).

That's the good news.  The bad news is that those lisp slots never
get GC'ed: there's a hash table which maps a pointer which has the
same address as the ObjC instance to a SLOTS-VECTOR for the instance.
The original plan was to hook into the function used to deallocate
NSObjects and to remove the SLOTS-VECTOR from the hash table whenever
an NSObject with lisp slots was deallocated.

That worked OK, but there were some bizarre problems: any thread that
had ever been used as an NSThread would try to deallocate some thread-
specific data after it had exited; sometimes, it had already deallocated
the data structure that the lisp runtime used to keep track of lisp
threads, and the thread basically entered a state where the GC couldn't
suspend it and nothing could PROCESS-INTERRUPT it.

I think that some of these problems have been at least partially solved,
but I haven't tried enabling the code that hooks into the deallocation
mechanism in a while.

In objc-runtime.lisp:

#+later
(def-ccl-pointers install-deallocate-hook ()
  (install-lisp-deallocate-hook))

Moral:

- it's necessary to use MAKE-INSTANCE to create an NSObject that has
  lisp slots.  As long as it can be used to instantiate any type of
  NSObject (and I don't -think- it'll create empty slot-vectors for
  "pure" ObjC objects), MAKE-OBJC-INSTANCE should probably be deprecated.
- those slots don't get GCed
- I should try to spend a day or two debugging the scenarios that can
  occur if the lisp-dealloc-hook is enabled.  I think that some kernel
  changes will make things better than they were, but I don't know if
  more changes are needed.
- Adding lisp slots to relatively long-lived objects (listeners ...)
  isn't going to have a severe negative effect until you start making
  lots of them.



More information about the Openmcl-devel mailing list