[Openmcl-devel] FF call by reference

Gary Byers gb at clozure.com
Tue Jul 15 20:27:39 PDT 2008



On Tue, 15 Jul 2008, Ron Garret wrote:

>
> On Jul 15, 2008, at 4:22 PM, Gary Byers wrote:
>
>>
>>
>> On Tue, 15 Jul 2008, Ron Garret wrote:
>>
>>> I'm trying to call an ObjC method that takes a pointer to a pointer
>>> to
>>> an ns-error as an argument.  I tried this:
>>>
>>> ? (rlet ((err (:* ns:ns-error))) (#/foo: thing err)))
>>>> Error: Unknown foreign type: NS:NS-ERROR
>>
>> (rlet ((err (:* #>NSError +null-ptr+))) (#/foo: thing err))
>>
>> should complain about #/foo being undefined.
>
> You'd think.
>
> ? (rlet ((err (:* #>NSError +null-ptr+))) (#/foo: thing err))
> > Error: Extra arguments in (:* :<NSE>RROR +NULL-PTR+) don't match
> lambda list (CCL::TO).
>
> This didn't work either:
>
> ? (rlet ((err (:* #>NSError))) (#/foo: thing err))
> > Error: Unknown foreign type: :<NSE>RROR


(rlet ((err (:* (:struct #>NSError)) +null-ptr+))
   ...)


The type "pointer to structure whose first field is called :isa and
whose type is "pointer to ObjC class") is generally abbreviated
as :id, so:

(rlet ((err :id +null-ptr+))
   ...)

is probably about as clear.  (I think that this idiom is used 
in a few places in the IDE source.)

>
> (FWIW, the actual method I'm trying to call is #/open:)
>
>> Initializing the pointer (err) to a null-pointer isn't strictly
>> necessary (in CCL or ObjC), but might be good style: you're allocating
>> space (64 or 32 bits) for a pointer, but unless that those bits are
>> explicitly initialized they'll just be "whatever was on the stack"
>> and unlikely to be meaningful.
>
> I don't think that matters.  It's just an output parameter.

I don't know if it's set at all if no error occurs (I don't remember.)






More information about the Openmcl-devel mailing list