Hi David

Sorry I think I was not understandable.

For example in Smalltalk I want to send the message 
#initWithContentRectPointer:styleMask:backing:defer:
to a NSWindow

So in smalltalk I have something similar to:

nsWindowClass :=  Objc.ObjcRuntime at: 'NSWindow'.
nsWindow := nsWindowClass alloc.
nsWindow send: #initWithContentRectPointer:styleMask:backing:defer: 
              with: {nsRect. 15. Objc.ObjcAppKit nsBackingStoreBuffered. 1}.


The method #send:with: is just calling the function LKSendMessage.
In gnu-smalltalk the c-call-out mechanism transform the Smallinteger to the 
C-integer (unsing right-shift...)

But LKSendMessage is unboxing each parameter before doing the ffi call to the 
objc runtime:

    for (i = 0; i < argc; i++)
    {
        const char *objCType = [sig getArgumentTypeAtIndex: i + 2];
        UnboxValue(args[i], unboxedArgumentsBuffer[i + 2], objCType);
        unboxedArguments[i + 2] = unboxedArgumentsBuffer[i + 2];
    }

So the first parameter "args[i]"  of the UnboxValue call is an plain c-integer 
which is not what UnboxValue is expecting.
The call to [value unsignedIntValue] fail.

Let me know if I make it more clear.

Thanks

--Mathk






----- Message d'origine ----
> De : David Chisnall <[email protected]>
> À : Discussion list for Étoilé desktop environment <[email protected]>
> Envoyé le : Mer 13 avril 2011, 13h 41min 59s
> Objet : Re: [Etoile-discuss] Using LKSendMessage
> 
> Hi Mathieu,
> 
> On 13 Apr 2011, at 10:29, Mathieu Suen wrote:
> 
> > I  use LKSendMessage for writing the binding to gnu-smalltalk. 
> > I had pick  most of the implementation from the LanguageKit.
> > (I don't know if  LanguageKit build on osx without gnustep)
> 
> The interpreter can, the  compiler can't (well, it should built, it just 
> won't 
>work).
> 
> > But I  cam across an issue when sending a message with integer parameter 
>like:
> > 
> > NSWindows  class>>#initWithContentRectPointer:styleMask:backing:defer:
> > 
> > LKSendMessage unbox does integer as follow:
> > 
> > 
> >        case 'I':
> >             *(unsigned int*)dest = [value unsignedIntValue];
> >             break;
> 
> Yup, this is extracting the  unsigned integer representation (Objective-C 
> type 
>encoding 'I') from the  object.
> 
> >> From gnu-smalltalk I can't build the NSNumber because I  need to send a 
>message 
>
> > like 
> > 
> > #numberWithInt: which  should take a NSNumber as parameter...
> 
> I'm not sure why you are building  an NSNumber here at all.  You just need 
> the 
>object to return an unsigned  integer when sent an unsignedIntValue.  The 
>simplest way of doing this from  Smalltalk code is likely to be right-shifting 
>a 
>SmallInt by one and then  possibly zero-extending the result.
> 
> NSNumber is a class that boxes C  primitive integer values as objects, but in 
>this case we are trying to unbox,  not box, a value.  The only time you'd need 
>an NSNumber would be if one  existed already and you passed it as a parameter 
>to 
>the method that expected an  integer.  
>
> 
> > Any idea on how to solve this  recursion?
> 
> There shouldn't be any recursion here.
> 
> David
> 
> --  Sent from my  STANTEC-ZEBRA
> 
> 
> _______________________________________________
> Etoile-discuss  mailing list
> [email protected]
> https://mail.gna.org/listinfo/etoile-discuss
> 

_______________________________________________
Etoile-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-discuss

Répondre à