On Sun, 6 Jun 2004, blake wrote: > In looking at the CMUCL ffi manual, it explicitly says that structures > can't be passed by value. Is there some other way to call the Intel > functions which require such structues by value? For example, is this > possible using UFFI?
On the binary level structures are passed on the stack pretty much like any other argument, so you should be able to lie to the CMUCL FFI about the actual argument types, and arrange the call so that the library function gets the correct arguments. The only problem is alignment: all non-structure arguments including chars and shorts are aligned to 4 or 8 bytes, while chars and shorts inside structures are packed more tightly. If you have a structure that consists of ints, floats and doubles, perhaps with the occasional char or short in between, you should be able to get away with simply passing each structure element in a consecutive function argument. If the structure contains several consecutive chars and/or shorts, you will have to pack them into int arguments to get them passed properly to the library function. One way to do the packing would be to fill the appropriate C structure in lisp, and then use low-level lisp functions to read ints directly from the memory area of the structure. With best regards, Hannu Rummukainen
