[Openmcl-devel] initforms in objc classes ?

R. Matthew Emerson rme at clozure.com
Fri Feb 1 13:46:26 PST 2008


On Jan 31, 2008, at 8:38 AM, Didier Verna wrote:

> Gary Byers <gb at clozure.com> wrote:
>
>> (If we -do- have examples that use initforms on foreign slots, we
>> should fix the examples or change how this case is handled.)
>
>  I was actually led to think it was possible because of this (from
> apropos-window.lisp):
>
> (defclass apropos-window-controller (ns:ns-window-controller)
>  ((apropos-array :foreign-type :id :initform +null-ptr+
>                  :reader apropos-array
>                  [...]
>
> Of course, the actual initform value seemed to me somewhat redundant
> with what I read from the doc (the site seems to be back online) and
> from your replay (+null-ptr+ *is* what you call "binary 0" right ?).

Er, well, in my lame defense, I think that the :initform is left over  
from when I was trying to have the apropos-array slot be a lisp  
array.  When I changed it to an Objective-C array (so I could bind it  
to an NSArrayController), I left in the :initform slot option.  Note  
that I cleverly changed the NIL to +null-ptr+, though.  Good thing I  
was paying attention. :-/

Sorry for the bad example.

On a somewhat unrelated note, taking a look at that apropos-window  
code makes me remember wondering if @property-style slot options might  
be an interesting feature.

In Objective-C 2.0, it's my understanding that you can say something  
like

@property(retain) NSArray *aproposArray;

in the @interface section, and then in the @implementation section, say

@synthesize aproposArray;

and the compiler will provide accessor methods for aproposArray for  
you, implementing the appropriate retain/release code in the setter  
method.

I thought it might be cool if there were some rational way to get CLOS  
automatically generate reader/writer methods that would do the right  
thing wrt retain and release.  I didn't do much of anything more than  
play around briefly before deciding that I would actually have to  
think hard about it, so I went on to easier things.

Anyway, the upshot is that I wanted to point out that using CLOS's  
automatically defined setter methods for slots containing Objective-C  
objects is likely to cause leaks.

Hence the setf method for the apropos-array slot that I defined by  
hand (instead of using the :accessor slot option) that does the retain/ 
release.





More information about the Openmcl-devel mailing list