Fwd: [cffi-devel] Re: Clisp, cffi and defcfuns in a saved image
Edgar Gonçalves
edgar.goncalves at gmail.com
Tue Feb 13 02:52:12 UTC 2007
Viva,
On 2/12/07, Luís Oliveira <luismbo at gmail.com> wrote:
> On 12/02/07, Edgar Gonçalves <edgar.goncalves at gmail.com> wrote:
> > 1) Unlike AllegroCL or Lispworks, Clisp (and SBCL too, btw) requires me to
> > precede all defcfuns related to a library with:
> >
> > #+clisp (cffi::use-foreign-library Tcl)
> > (defcfun ("Tcl_FindExecutable" tcl-find-executable) :void
> > (argv0 :string))
>
> That doesn't sound right. You should only need to call
> (use-foreign-library tcl) only once, some time before you load your
> bindings.
Let me rephrase it a bit, to avoid misunderstandings. Yes, I call
(use-foreign-library tcl) only once. The point is that I *need* to
call it, whereas with ACL, for instance, I don't - the defcfuns just
work for themselves.
> > 2) When I load the saved image (using the code from above), I get an error
> > when applying defcfun'ed functions, telling me the library wasn't found:
>
> Just tested with GNU CLISP 2.41 (2006-10-13) on OSX. Loaded cffi-test,
> saved an image (tried with ":executable t" too), restarted with the
> image, and ran (rt:do-tests) and it works. (Except some funcall.*
> tests fail at first, for some reason. I blame it on some RT
> weirdness.)
>
> AFAICT, CLISP correctly reloads the libraries at startup. Can you try
> this with cffi-test or otherwise provide some sort of test case?
Actually, I haven't tried tests, but I can't seem to get past the
library bindings.lisp. It seems to be a problem with the dll (I'm
running Windows 2003), given that my cl.exe (version 14.00.50727.42
for 80x86 ) won't recognize the <stdint.h>, and that my cygwin
(latest, just checked for updates) makes a dll that hangs bindings.fas
while loading.
As for a short test case, here's the smallest I can make that fires up
my error. After loading clisp, and loading asdf, I eval:
,-----
| (asdf:operate 'asdf:load-op :cffi)
|
| (cffi:define-foreign-library odbc
| (:windows (:or "odbc32.dll"))
| (t (:default "odbc32.dll")))
|
| (cffi:defcfun ("SQLAllocHandle" sql-handle) :short)
|
| (sql-handle)
`-----
The last form brings me to the following error:
WARNING: FFI::FOREIGN-LIBRARY-FUNCTION: no dynamic object named
"SQLAllocHandle" in library :DEFAULT
*** - FUNCALL: undefined function NIL
with the relevant backtrace being:
<11> #<SYSTEM-FUNCTION ERROR>
<12> #<COMPILED-FUNCTION SYSTEM::CHECK-VALUE>
<13> #<SYSTEM-FUNCTION FUNCALL> 1
EVAL frame for form
(VALUES
(FUNCALL
(LOAD-TIME-VALUE
(MULTIPLE-VALUE-BIND (CFFI-SYS::FF ERROR)
(IGNORE-ERRORS
(FFI::FOREIGN-LIBRARY-FUNCTION "SQLAllocHandle"
(FFI::FOREIGN-LIBRARY :DEFAULT) NIL NIL
(FFI:PARSE-C-TYPE '(FFI:C-FUNCTION (:ARGUMENTS) (:RETURN-TYPE
FFI:SHORT) (:LANGUAGE :STDC)))))
(OR CFFI-SYS::FF
(WARN
(FORMAT NIL "~?" (SIMPLE-CONDITION-FORMAT-CONTROL ERROR)
(SIMPLE-CONDITION-FORMAT-ARGUMENTS ERROR))))))))
APPLY frame for call (SQL-HANDLE)
<14>
#<FUNCTION SQL-HANDLE NIL (DECLARE (SYSTEM::IN-DEFUN SQL-HANDLE))
(BLOCK SQL-HANDLE (VALUES (CFFI-SYS:%FOREIGN-FUNCALL
"SQLAllocHandle" :SHORT)))> 0
EVAL frame for form (SQL-HANDLE)
Hope this helps tracing out something, tell me if you need anything more.
Thanks,
Edgar Gonçalves
More information about the cffi-devel
mailing list