[cffi-devel] vararg

James Bielman jamesjb at jamesjb.com
Fri Jan 6 11:41:59 UTC 2006


Yaroslav Kavenchuk <kavenchuk at jenty.by> writes:

>>>I do not know what library contains bad sprintf function.
>> 
>> Maybe you can figure it out using (foreign-address
>> #<foreign-function>) and see if you can relate that to the
>> addresses of the .dll loaded into the current process?
>
> I have found it! This is ntdll.dll (in this library still more many
> other functions). F&%k!
>
> It is caused from ole32.dll.
>
> win32 *.dll hell...
>
> Use CFFI with Windows without cpecification of library is
> problematic :(

Hmm, that sounds awful.

What sort of interface should CFFI export for this?  I've been
reluctant to add this because several Lisps don't support it at all,
but perhaps silently ignoring :LIBRARY options on those
implementations and proceeding with the global lookup is okay for
now...

If we added an option syntax to DEFCFUN (I know everyone hates this
syntax, but it's backwards compatible), we could have something like:

(defcfun "sprintf" :int
  :library "msvcrt.dll"
  (fmt :string)
  ...)

If we want to break everyone and change the syntax of DEFCFUN, we can
make it look like DEFCLASS:

(defcfun "sprintf" :int
  ((fmt :string)
   ...)
  (:library "msvcrt.dll"))

Or, for a completely different approach, what about:

(with-default-library ("msvcrt.dll")
  (defcfun "sprintf" :int
    (fmt :string)
    ...))

Thoughts?

James



More information about the cffi-devel mailing list