Trouble with compiled file using UFFI

From: Dave Roberts (ldave-re-move_at_re-move.droberts.com)
Date: 04/30/04


Date: Fri, 30 Apr 2004 06:13:12 GMT

Okay, so I'm working on my DNS resolver library. Everything works peachy
under SBCL, but I'm having trouble with CMUCL. In particular, I'm using
UFFI to load the Linux resolver.so library and then define a foreign
function with the following two forms:

(uffi:load-foreign-library #p"/usr/lib/libresolv.so"
                             :supporting-libraries '("c"))
                                                                                
(uffi:def-function ("res_query" res-query-c)
                   ((dname (:cstring))
                    (class :int)
                    (type :int)
                    (answer (* :unsigned-byte))
                    (anslen :int))
                   :returning :int)

With SBCL, this works great. I have packaged up the library and you can
download it via asdf-install (though it looks like the recent CLiki
restoration blew away my page there, so you'll have to download it directly
from http://www.findinglisp.com/packages/resolver/resolver-latest.tar.gz).

The problem starts when you try to use CMUCL. Everything works. If you have
asdf and asdf-install, you can download it and install it. Asdf will try to
compile all the files the first time it is loaded. This works great, right
up until the time when CMUCL tries to the load the .x86f file. Then I get:

* (asdf:oos 'asdf:load-op :resolver)
 
; loading system definition from
; /home/dave/.asdf-install-dir/systems/resolver.asd into
; #<The ASDF1183 package, 0/9 internal, 0/9 external>
; Loading #p"/home/dave/.asdf-install-dir/site/resolver-0.2/resolver.asd".
; registering #<SYSTEM :RESOLVER {48873835}> as RESOLVER
; [GC threshold exceeded with 12,015,824 bytes in use. Commencing GC.]
; [GC completed with 3,737,944 bytes retained and 8,277,880 bytes freed.]
; [GC will next occur when at least 15,737,944 bytes are in use.]
; loading system definition from
/home/dave/.asdf-install-dir/systems/uffi.asd
; into #<The ASDF1186 package, 0/9 internal, 0/9 external>
; Loading #p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/uffi.asd".
; registering #<SYSTEM UFFI {48117DDD}> as UFFI
; Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/package.x86f".
; Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/primitives.x86f".;
Loading #p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/objects.x86f".
; Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/aggregates.x86f".;
Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/functions.x86f".
; Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/strings.x86f".
; Loading
#p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/libraries.x86f".
; Loading #p"/home/dave/.asdf-install-dir/site/uffi-1.4.12/src/os.x86f".
; Loading #p"/home/dave/.asdf-install-dir/site/resolver-0.2/packages.x86f".
; Loading #p"/home/dave/.asdf-install-dir/site/resolver-0.2/resolver.x86f".
 
Undefined foreign symbol: "res_query"
 
Restarts:
  0: [CONTINUE] Return NIL from load of
#p"/home/dave/.asdf-install-dir/site/resolver-0.2/resolver.x86f".
  1: [RETRY ] Retry performing #<ASDF:LOAD-OP NIL {487D95AD}> on
                #<ASDF:CL-SOURCE-FILE "resolver" {48B9C3D5}>.
  2: [ACCEPT ] Continue, treating #<ASDF:LOAD-OP NIL {487D95AD}> on
                #<ASDF:CL-SOURCE-FILE "resolver" {48B9C3D5}> as having been
                successful.
  3: [ABORT ] Return to Top-Level.
 
Debug (type H for help)
 
(KERNEL:UNDEFINED-FOREIGN-SYMBOL-ERROR-HANDLER "<error finding name>"
                                               #.(SYSTEM:INT-SAP #x3FFFE1B0)
                                               #<Alien (* #) at #x3FFFDE48>
                                               (14))
Source: Error finding source:
Error in function DEBUG::GET-FILE-TOP-LEVEL-FORM: Source file no longer
exists: target:code/interr.lisp.
0]

So, it looks like it isn't executing the (uffi:load-foreign-library ...)
form. Indeed, if I execute this by hand and then reload the resolver.x86f
file containing the (uffi:def-function ...) form, things work great. Also,
if I blow away the .x86f files and load the .lisp files by hand (asdf
always tries to compile them if they aren't already), things also work
great. So, somehow, in the compiled file, it isn't executing that when
loaded. I thought I would try to wrap the form in an EVAL-WHEN form, like
so:

(eval-when (:load-toplevel :compile-toplevel :execute)
  (uffi:load-foreign-library #p"/usr/lib/libresolv.so"
                             :supporting-libraries '("c")))

but that didn't work, either.

Does anybody have any hints?

-- 
Dave Roberts
ldave-re-move@re-move.droberts.com
http://www.findinglisp.com/blog


Relevant Pages

  • Re: Next Version of GDI+ (maybe GDI+ 2.0)
    ... loading and manipulating of such files isn't lightning fast unless you have really powerfull dedicated hardware. ... to see whole image you need to read whole image, and then eventualy generate a smaller sample for display. ... BUT to have this smaler sample you need to load ALL the pixels of oryginal image. ...
    (microsoft.public.dotnet.framework.drawing)
  • RE: 66 running processes?
    ... Win XP, a firewall and an AV and about seven background utilities, and with ... want it to load right from boot up, or could you take it off the load list ... Stopping programs you use loading early is only likely to make much ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Next Version of GDI+ (maybe GDI+ 2.0)
    ... Alejandro Lapeyre ... > loading and manipulating of such files isn't lightning fast unless you ... > smaller sample for display. ... > load ALL the pixels of oryginal image. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Filter on a forms recordsource
    ... What I'm trying to do is to load a record with its sub details in a subform. ... without loading the whole records and details of the database. ...
    (microsoft.public.access.queries)
  • Re: MVP please help - ShowDialog() very slow
    ... You should also consider using asynchronous delegates to load your data. ... can either disable the listbox while the data is loading or show some kind ... > You need to remember that the ListBox control is a wrapper around the old ... >>when the list box switches to visible as part of ShowDialog(). ...
    (microsoft.public.dotnet.framework.windowsforms.controls)