[cffi-devel] Re: Clisp, cffi and defcfuns in a saved image

Edgar Gonçalves edgar.goncalves at gmail.com
Tue Feb 13 11:52:33 UTC 2007


-- 
Edgar Gonçalves
  Instituto Superior Técnico,
  INESC-ID - Software Engineering Group,
  Portugal


On 2/13/07, Luís Oliveira <luismbo at gmail.com> wrote:
> On 13/02/07, Edgar Gonçalves <edgar.goncalves at gmail.com> wrote:
> > ,-----
> > | (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)
> > `-----
>
> OK, yes, you need to load the library before the defcfun. Some lisps
> won't mind but others do. They'll all complain by the time the call to
> sql-handle is evaluated though.
>
> Why aren't you loading the library? What are you trying to accomplish?
> What am I missing?

I was trying to explain my first problem, but if it's assumed that
"some lisps won't mind" while others do, I guess the problem rolls
back to us, developers, to do the use-foreign-library.

About my second issue, I've come to the conclusion that this simple
example (below) works all-right, given that you call
use-foreign-library after loading the image (before calling the
foreign functions). This is what I find most annoying, since I have to
scoop through all 3rd party libraries for used dll's. Any chance to
make this work for clisp just like it does for (e.g.) ACL (i.e.,
without having to call use-foreign-library)?

,-----
| (asdf:operate 'asdf:load-op :cffi)
|
| (cffi:define-foreign-library odbc
|   (:windows (:or "odbc32.dll"))
|   (t (:default "odbc32.dll")))
|
| (cffi::use-foreign-library odbc)
|
| (cffi:defcfun ("SQLAllocHandle" sql-handle) :short)
|
| (format t "---------------Before loading image, dll call yelds:
~A!~%" (sql-handle))
|
| (ext:saveinitmem "test.exe"
| 		 :init-function #'(lambda ()
| 				    (cffi::use-foreign-library odbc)
| 				    (format t "---------------After loading image, dll call
yelds: ~A!~%" (sql-handle))
| 				    (ext:quit)
| 				    )
| 		 :NORC t
| 		 :script t
| 		 :executable t
| 		 :quiet t)
| (ext:quit)
`-----

I'll try again making it work with my clsql project, and I'll post
back my success.



More information about the cffi-devel mailing list