[sorry, I hit the wrong key in my mua]
Hi all,
I am trying to port a scripting language named Io Objective-C bridge
from Cocoa to GNUstep. I have experienced some issues in this process,
and most notably when using NSInvocation objects.
Here is the code snippet that executes an NSInvocation object (the
Io2Objc_perform function, which translates a Io message to an Objc
message) and gets the result:
<snip>
if (*cType == '@')
{
id obj;
[invocation getReturnValue:&obj];
//assert(obj!=nil);
[pool release];
return IoObjcBridge_ioValueForCValue_ofType_(self->bridge, obj,
cType);
}
else
{
[invocation getReturnValue:&(self->returnBuffer)];
//assert(self->returnBuffer!=NULL);
[pool release];
return IoObjcBridge_ioValueForCValue_ofType_(self->bridge,
self->returnBuffer, cType);
}
</snip>
When the "assert" are commented, as shown in the example, Io does not
get the return value:
2003-04-22 15:07:45.599 DebugTest[3173] [NSMutableArray<1075777504>
alloc]
2003-04-22 15:07:45.649 DebugTest[3173] Pisces:Io > Io -> Objc
'alloc'
2003-04-22 15:07:45.696 DebugTest[3173] Pisces:Io > ERROR
'Io.Primitive.doesNotRespond':Nil does not respond to message 'init'
This can be interpreted as "NSMutableArray alloc" did not return the
right thing (and this thing is unable to respond to "init"), but did
not return nil either.
But when I uncomment the assertions, "NSMutableArray alloc init" works
fine:
2003-04-22 15:07:02.475 DebugTest[3081] [NSMutableArray<1075777504>
alloc]
2003-04-22 15:07:02.523 DebugTest[3081] Pisces:Io > Io -> Objc
'alloc'
2003-04-22 15:07:02.572 DebugTest[3081] [GSMutableArray<135113432>
init]
2003-04-22 15:07:02.620 DebugTest[3081] Pisces:Io > Io -> Objc
'init'
Which means that "NSMutableArray" alloc created a "GSMutableArray"
that was properly wrapped by Io. I would also add that this works
*most of the time*, which means that sometimes we fallback to the
first situation.
The only reason for the different behaviour generated by the addition
of assertions is that [NSInvocation getReturnValue:] is executed
*asynchronously*, and that sometimes the return value is not
completely assigned or not assigned at all when the
"IoObjcBridge_ioValueForCValue_ofType_" is executed.
So my question is : how can we ask NSInvocation to synchronously
(blocking) call the getReturnValue method ?