Ok, I've just realized that I've been mislocating the problem at
hands. It seems that defcfun works just fine, and the issue I'm
getting resides on the foreign pointers. I've made tests to cffi,
cffi-uffi-compat, ffi (answering to Ken's "CLisp exe vs FFI"
post), and all have worked for a simple function definition/call.
So I delved again to clsql initial situation, and I've traced the
error to a call to %new-environment-handle, that uses a null
pointer as an argument to the ff call to SQLAllocHandle. I also
noticed that the null pointer was indeed showing up at the error
message, so I tried this simple test:

,-----
| (asdf:operate 'asdf:load-op 'cffi)
| (asdf:operate 'asdf:load-op 'cffi-uffi-compat)
| (defvar my-null-ptr (ffi:unsigned-foreign-address 0))
| (format t "- Before loading image, null ptr is: ~A!~%" my-null-ptr)
| (ext:saveinitmem "test.exe"
|                :init-function #'(lambda ()
|                                   (format t "- After loading image, my-null-ptr 
yelds: ~A.~%"
my-null-ptr)
|                                   (ext:quit))
|                :NORC t
|                :script t
|                :executable t
|                :quiet t)
`-----


The output I get when I run this code is (after the initial load messages),
,-----
| (...)
| - Before loading image, null ptr is: #<FOREIGN-ADDRESS #x00000000>!
| C:\dev\test>test
| test
| - After loading image, my-null-ptr yelds: #<INVALID FOREIGN-ADDRESS
#x00000000>.
`-----

What makes a foreign address valid or invalid? Is there some way
I can validate a simple null pointer? I could understand if a
given non-null pointer in C would be hard to validate after
restarting an image, but a null pointer is, and always will be,
0x0, right?

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


On 2/13/07, Edgar Gonçalves <[EMAIL PROTECTED]> wrote:
On 2/13/07, Edgar Gonçalves <[EMAIL PROTECTED]> wrote:
> I'll try again making it work with my clsql project, and I'll post
> back my success.
>

Eh, guess not, after all. The problem seems to reside somewhere betwee
clsql-odbc and CFFI's uffi-compat.lisp.

The following is related to the initialization function of the saved
image. It assumes the cl-sql library was already loaded AND used
properly before the image was saved.

What I do before using the foreign functions is to call
(clsql-sys:database-type-load-foreign :odbc), and this calls
uffi:load-foreign-library, defined in cffi's uffi-compat.lisp, with
the odbc32.dll filename. This, by its turn, calls
cffi:load-foreign-library, which is the same as to call
cffi::use-foreign-library. So, even though the result should
apparently be the same, I still get this:

** - Continuable Error
FFI::FOREIGN-CALL-OUT: no dynamic object named "SQLAllocHandle" in
library :DEFAULT

But then again, if I manually call (cffi::use-foreign-library
"odbc32.dll"), what I get is something different:

*** - FFI::FOREIGN-CALL-OUT: #<INVALID FOREIGN-POINTER #x00000000>
comes from a previous Lisp session and is
      invalid

What am I missing here?

--
Edgar Gonçalves

_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to