help-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSInvocation does not seem to always assign return value (suite)


From: Richard Frith-Macdonald
Subject: Re: NSInvocation does not seem to always assign return value (suite)
Date: Tue, 22 Apr 2003 16:41:22 +0100


On Tuesday, April 22, 2003, at 04:24  pm, Sebastien Pierre wrote:

[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 ?

The -getReturnValue: method is not asynchronous .... if there is some threading issue causing a problem it is an error in your own code.

If adding/removing the assertions changes the code behavior, the most likely problem is actually with uninitialised variables having different values depending on how the code was compiled.

Unfortunately I can't help beyond that ... your code snippet and explanation leave a lot unclear to me .... 1. when returning an object, you release pool, which might release invocation, which might release the object before you return it.
2. what are you doing about invoking methods which return void
3. is the value of self->returnBuffer big enough to hold the returned value 4. your talk about NSMutableArray alloc seems to indicate that you are only concerned with returning objects (the first half of the code you give) is that the case?
etc.

Putting debug lines inside the code snippet, to print the actual values of each variable throughout might help.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]