[Ecls-list] CFFI typedefs not noticed in compiled code

Daniel Dickison danieldickison at gmail.com
Fri Sep 15 04:40:52 UTC 2006

I've been having some strange problems with CFFI typedefs.  In a  
file, I have a def-foreign-type along with a def-function that uses  
the previously defined type.  If I load the source file then it works  
fine.  However, if I compile the file and then load the .fas file in  
a new ECL run, I get the error:

It seems that when loading compiled code, CFFI's hash table that  
stores user-defined types is not getting updated properly, even  
though, as far as I can tell, the def-foreign-type macro expands to  
include an all-inclusive eval-when.

Here's an example of the problem:

;;; curl-ecl.lisp
(defpackage :ecl-user
   (:use :common-lisp :ffi))
(in-package :ecl-user)

(ffi:load-foreign-library "curl")
(def-foreign-type curl-code :int)
(def-function "curl_global_init" ((flags :long))
   :returning curl-code)

Loading the source works fine, but not when loading the .fas in a  
fresh environment.

I haven't been able to reproduce the problem outside of CFFI, so I  
don't know if this is an ECL issue or CFFI bug.  For what it's worth,  
the following works fine, even though I thought it is analogous to  
what CFFI does as far as hash tables go.:

;;; hash-test.lisp
(defvar *my-hash* (make-hash-table))
(defmacro set-hash-value (key val)
   `(setf (gethash ,key *my-hash*) ,val))
(defmacro print-hash-value (key)
   `(print ,(gethash key *my-hash*)))

(eval-when (:compile-toplevel :load-toplevel :execute)
   (set-hash-value :key "hello world"))
(print-hash-value :key)

Thanks in advance for any help.


More information about the ecl-devel mailing list