Hi All After thcating with Paolo in irc. It reveal that c-call-out does not support call by value on struct. Especially struct that is more than 8bit size on x64.
So I have made a example with FFI to see if that is in fact supported: #include <stdlib.h> #include <ffi.h> #include <stdio.h> typedef struct rect { double f; double g; double h; } rect; void foo (rect argStruct) { printf ("Receive a strcut by value f=%f, g=%f, h=%f\n", argStruct.f, argStruct.g, argStruct.h); } int main () { int i; ffi_cif cif; ffi_type * arg[1]; ffi_type structType; ffi_type * element[4]; void * value[1]; rect aStruct; arg[0] = &structType; structType.size = 0; structType.alignment = 0; value[0] = (void*)&aStruct; for (i = 0; i < 3; i++) element[i] = &ffi_type_double; element[3] = NULL; structType.elements = &element; if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, arg) == FFI_OK) { aStruct.g = 5.5; aStruct.h = 3.4; aStruct.f = 9.0; ffi_call (&cif, foo, NULL, value); } else { return EXIT_FAILURE; } return EXIT_SUCCESS; } compiled with: gcc `pkg-config --libs libffi` `pkg-config --cflags libffi` testffi.c -o test Testing that on OSX x64 shows that it is fine. So other platform need to be test to see if that is working. Thanks Mth On Feb 18, 2011, at 5:26 PM, Mathieu Suen wrote: > Hi > > I have break into the #initWithContentRect:styleMask:backing:defer: > objective-c > method > and I get the first argument passed as a pointer in $rdx which is wrong since > the method expected to be in the stack (The size of the struct is more than > 8byte and the ABI specify that it should be on the stack). > > So I have made it explicitly be a struct: > > ObjcRuntime class >> specialObjcMsgSend: receiver selector: sel arg1: arg1 > args: args [ > <cCall: 'objc_msgSend' returning: #cObject args: #( #cObject #cObject > #{NSRect} #variadic )> > ] > > NSRect being a subclass of CStruct... > > But it doesn't work either. > > -- Mathieu > > > > ----- Message d'origine ---- >> De : Holger Hans Peter Freyther <hol...@freyther.de> >> À : Mathieu Suen <mathieus...@yahoo.fr> >> Cc : help-smalltalk@gnu.org >> Envoyé le : Ven 18 février 2011, 11h 01min 40s >> Objet : Re: Re : Re : [Help-smalltalk] Passing a struct to a c-callout >> >> On 02/18/2011 10:54 AM, Mathieu Suen wrote: >> >>> I do not have error. instead I get those NSlog: >>> 2011-02-18 10:46:56.986 gst[60568:903] NSWindow does not support >> nonactivating >> >>> panel styleMask 0x80 >>> 2011-02-18 10:46:56.988 gst[60568:903] NSWindow does not support HUD >> styleMask >> >>> 0x2000 >> >> my hint would be start gst. Then attach with gdb to it (gdb -p `pidof gst`) >> and set a breakpoint in this objective c function, then execute your program >> and use gdb to inspect your arguments. Maybe you see a pattern of what is >> going wrong, e.g. the size of the SEL is wrong or such. >> > > > > > _______________________________________________ > help-smalltalk mailing list > help-smalltalk@gnu.org > http://lists.gnu.org/mailman/listinfo/help-smalltalk __________________________________________________ Do You Yahoo!? En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités http://mail.yahoo.fr Yahoo! Mail _______________________________________________ help-smalltalk mailing list help-smalltalk@gnu.org http://lists.gnu.org/mailman/listinfo/help-smalltalk