[Ecls-list] load-foreign-library
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Tue Oct 24 21:33:34 UTC 2006
2006/10/24, Rick Taube <taube at uiuc.edu>:
> Your version works. But a defcfun will not work that depends on the
> define-foreign-type will not work if the file is loaded from the fasl
> without compiling.
>From the code you sent me was not clear what was going on. One must
really macroexpand it. The problem is actually rather simple and it is
related to object externalization.
CFFI uses CLOS objects to represent types. The definition of a
function contains indeed several of those objects, as shown below.
Now, when you compile that code, ECL must produce additional lisp code
to create those standard objects (See HyperSpec Sect. 3.2.4.4 and
definition of make-load-form). When that code is to be evaluated is
_not_ specified by the standard and indeed what ECL does is to create
them before all statements in the file are executed.
The previous behavior is not what people expect. Other implementations
wait until the statement in which the object is referenced, so that
compiled files behave much like loaded files. This allows you to have
the class definition for a standard object (in our case
define-foreign-type) in the same file in which an instance of that
object appears (in our case, in the macroexpansion of defcfun).
I am still thinking about the way to fix this.
Juanjo
> (cffi:define-foreign-type pm-timestamp () ':long)
PM-TIMESTAMP
> (macroexpand '(cffi:defcfun ("c_foo" foo) :int (when pm-timestamp) ))
(PROGN
NIL
(DEFUN FOO (WHEN)
(MULTIPLE-VALUE-BIND
(#:G53 #:PARAM54)
(CFFI::TRANSLATE-TYPE-TO-FOREIGN WHEN
#<CFFI::FOREIGN-TYPEDEF PM-TIMESTAMP>)
(UNWIND-PROTECT
(PROGN (VALUES (CFFI-SYS:%FOREIGN-FUNCALL "c_foo" :LONG #:G53 :INT)))
(CFFI::FREE-TYPE-TRANSLATED-OBJECT #:G53
#<CFFI::FOREIGN-TYPEDEF PM-TIMESTAMP>
#:PARAM54)))))
More information about the ecl-devel
mailing list