[cffi-devel] Callback Symbol Names

James Bielman jamesjb at jamesjb.com
Sun Aug 21 08:40:30 UTC 2005


Luis,

In preparation for pulling in your changes to the main Darcs tree,
I've been looking at the callback support in the cffi-luis branch.

As it stands, I think CFFI-SYS::MAKE-CALLBACK does not safely intern
the symbols it uses for callback names (on all the implementations but
SBCL it seems).  For example, if you use DEFCALLBACK from the REPL,
the callback symbol is interned into the current package; in my test
case, it was interned into CL-USER.  Also, callbacks with the same
symbol name but from different packages will redefine each other.

So, I propose a separate package for callback symbols, and making sure
we also use the package name of the symbol we are defining a callback
for.

Also, thinking back to our earlier conversation about making some sort
of CFFI-UTILS package, I would suggest putting it first in the system
definition so the backends can make use of it as well, then we can put
CALLBACK-SYMBOL-NAME there as well.

Here's a patch against cffi-luis for OpenMCL:

--- old-cffi-luis/src/cffi-openmcl.lisp	2005-08-08 16:47:20.000000000 -0700
+++ new-cffi-luis/src/cffi-openmcl.lisp	2005-08-21 01:27:06.000000000 -0700
@@ -47,6 +47,8 @@
    #:foreign-var-ptr
    #:make-callback))
  
+(defpackage #:cffi-callbacks)
+ 
 (in-package #:cffi-sys)
 
 ;;;# Allocation
@@ -248,8 +250,14 @@
 
 ;;;# Callbacks
 
+(defun callback-symbol-name (name)
+  "Return the symbol to use for the callback for NAME."
+  (intern (format nil "~A.~A"
+                  (package-name (symbol-package name))
+                  (symbol-name name)) :cffi-callbacks))
+
 (defmacro make-callback (name rettype arg-names arg-types body-form)
-  (let ((cb-sym (intern (format nil "%callback/~A" name))))
+  (let ((cb-sym (callback-symbol-name name)))
     `(symbol-value
       (defcallback ,cb-sym (,@(mapcan (lambda (sym type)
                                         (list (convert-foreign-type type) sym))


James



More information about the cffi-devel mailing list