----- Message d'origine ---- > De : Paolo Bonzini <bonz...@gnu.org> > À : Mathieu Suen <mathieus...@yahoo.fr> > Cc : help-smalltalk@gnu.org > Envoyé le : Mar 22 février 2011, 16h 52min 43s > Objet : Re: [Help-smalltalk] c-call-out and c-call-in with struct. > > On 02/22/2011 03:47 PM, Mathieu Suen wrote: > > I have a quick look at ffi to see if pass-by-value of a struct (with a size > > greater than 8bit) was available > > How do you do that? (Serious question, I'm busy so I'm not looking it up >right now).
I have made a small test: #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; } So for example all you have to do is to declare the struct like this: ffi_type structType; ffi_type * element[4]; for (i = 0; i < 3; i++) element[i] = &ffi_type_double; element[3] = NULL; structType.elements = &element; > > > Now in gst everything is bound to a cparam so that is going to make a lot of > > refactoring in other to have c struct pass-by-value. > > This may or may not be true depending on the answer to question 1... > > Paolo > _______________________________________________ help-smalltalk mailing list help-smalltalk@gnu.org http://lists.gnu.org/mailman/listinfo/help-smalltalk