From: Sam S. <sd...@gn...> - 2003-07-31 14:34:36
|
> * In message <9F8582E37B2EE5498E76392AEDDCD3FE05C96F51@G8PQD.blf01.telekom.de> > * On the subject of "Re: FFI Code Generation Bug" > * Sent on Thu, 31 Jul 2003 12:18:33 +0200 > * Honorable "Hoehle, Joerg-Cyril" <Joe...@t-...> writes: > > When generating a C-struct definition, to-c-typedecl must precisely respect the foreign type. The current implementation is good at this. > > When generating a function specification, to-c-typedecl ought to produce something slightly different. > > Example of c-struct: > (ffi::to-c-typedecl (ffi::parse-c-type > '(c-struct list (seed16v (c-ptr (c-array ushort 3))))) "seed48") > "struct t494 { uint16 (* SEED16V)[3]; } seed48" > which is TRT. > > Example of function: > (ffi::to-c-typedecl (ffi::parse-c-type > '(c-function (:arguments (seed16v (c-ptr (c-array ushort 3)))) > (:return-type (c-ptr ushort) :none) (:language :stdc))) "seed48") > "uint16 * (seed48) (uint16 (* arg496)[3])" > which is not the right declaration for this function: one indirection > too much. > > The CLISP impnotes clearly say that C-PTR must surround C-ARRAY. > However, straightforward translation as done by to-c-typedecl leads to > the above wrong declaration > which would work with code like: (*arg496)[2] > but not with the code written as arg496[2], which is the one > that corresponds to the Lisp-level interface description. > > The needed change would make the current, very straightforward > structure of this function seemingly more complicated. please try this patch: @@ -591,7 +588,12 @@ (c-array-max (to-c-typedecl (svref c-type 1) (format nil "(~A)[~D]" name (svref c-type 2)))) - ((c-ptr c-ptr-null c-array-ptr) + ((c-ptr) + (let ((pointed (svref c-type 1))) + (to-c-typedecl pointed + (if (eq 'c-array (ctype-type pointed)) name + (format nil "* ~A" name))))) + ((c-ptr-null c-array-ptr) (to-c-typedecl (svref c-type 1) (format nil "* ~A" name))) (c-function (to-c-typedecl (svref c-type 1) > What form exactly, and how do :typdef and :external affect it? <http://cvs2.cons.org/ftp-area/clisp/snapshots/impnotes/dffi.html#def-c-struct> :TYPEDEF means that the name of this structure is a C type defined with typedef elsewhere. [i.e., to-c-typedecl will use the name as is without the "struct" prefix] :EXTERNAL means that this structure is defined in a #P".c" file that you include with, e.g., (FFI:C-LINES "#include <filename.h>"). [i.e., to-c-typedecl will not print the structure definition] These options determine how the struct is written to the #P".c". text in [] is not in the impnotes because it is an implementation detail. -- Sam Steingold (http://www.podval.org/~sds) running w2k <http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/> <http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html> main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);} |