[Openmcl-devel] More Involved Example FFI example for OS X

Cyrus Harmon cyrus at bobobeach.com
Tue Mar 9 10:29:40 PST 2004


Last month's (brief) thread about the Simple C FFI example was very 
helpful. Now for the next step. Does anyone have a more involved FFI 
example?

The simple examples involves a C source file and a lisp program that 
loads a shared library and calls a C function from the library.

I'd like to:

Starting with a C source file with, corresponding header (.h) file and 
shared library

1. run h-to-ffi.sh on the .h file to generate the .ffi file
2. have lisp code that will read the .ffi and generate the appropriate 
types
3. load the shared library
4. have lisp code to call the C function in the library

1 and 3 are pretty straightforward, although 1 is a bit more convoluted 
than I would like since the ffigen doesn't really build from any 
sources I could find, but that's for another day. That leaves items 2 
and 4. There is the parse-standard-ffi-files stuff but this looks like 
it's pretty tied up with the whole interface database and .cdb stuff. 
What is the .cdb stuff? Do I need it for my own ffi stuff? I'd like the 
ffi stuff I'm doing to be separate from the main interface stuff. I can 
write my own wrappers like:

(defun TIFFOpen (file mode)
   (with-cstrs ((c-file file)
                (c-mode mode))
               (ccl::external-call "_TIFFOpen" :address c-file :address 
c-mode :address)))

but this is tedious and it would be nice to use the ffi stuff if 
possible.

Thanks again,

Cyrus




More information about the Openmcl-devel mailing list