[cffi-devel] Patch: FOREIGN-FUNCALL for LispWorks
Edi Weitz
edi at agharta.de
Sat Jan 14 23:18:50 UTC 2006
Hi!
Attached is a hasty patch to enable CFFI-SYS:%FOREIGN-FUNCALL and
CFFI-SYS:%FOREIGN-FUNCALL-POINTER for LispWorks. The idea is to
create one foreign funcallable per signature and cache those in a hash
table. I took a quick glance at the source code of CMUCL's
ALIEN-FUNCALL and my impression (not really understanding the details)
was that CMUCL actually does something similar internally - it creates
a "stub" if necessary, depending on the types. As you can observe at
the REPL it compiles /something/ when ALIEN-FUNCALL is called.
Granted, it is kind of ugly to call FLI:DEFINE-FOREIGN-FUNCALLABLE in
non-top-level position but I think this solution is better than
nothing. It looks to me as if FOREIGN-FUNCALL is mostly intended for
interactive use and for "one-shot" invocations - correct me if I'm
wrong.
I don't know if CMUCL's "stubs" will ever be garbage-collected, the
foreign funcallables in my patch certainly won't. I don't expect this
to be a big problem, though.
I tried the CFFI test suite and it basically ran through with three
exceptions - FUNCALL.FLOAT, DEREF.FLOAT.2, and DEREF.FLOAT.3. My
guess is that these are due to LispWorks identifying FLOAT and
DOUBLE-FLOAT and are not related to my patch.
Two minor quibbles, unrelated:
1. The documentation says it is only about the cffi-luis branch but it
seems to me that the main branch and cffi-luis are almost identical
- or did I miss something?
2. This form
(define-foreign-library libcurl
(:unix (:or "libcurl.so.3" "libcurl.so"))
(t (:default "libcurl")))
in the (very nice, BTW) tutorial didn't work for me on Linux,
neither with LispWorks nor with CMUCL. I had to remove the second
(:UNIX) line to make it work.
edi at vmware:~$ ls -l /usr/lib/libcurl*
lrwxrwxrwx 1 root root 16 Dec 28 19:29 /usr/lib/libcurl.so.3 -> libcurl.so.3.0.0
-rw-r--r-- 1 root root 196632 Dec 7 12:39 /usr/lib/libcurl.so.3.0.0
Cheers,
Edi.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cffi_lw_ff.diff
Type: text/x-patch
Size: 3505 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20060115/a1a5ddfb/attachment.bin>
More information about the cffi-devel
mailing list