[Ecls-list] updating refererence pointers in UFFI

Dustin Long dlong at stevens.edu
Wed Aug 30 06:34:14 UTC 2006

I've got some ecl+sqlite code lying around that I believe demonstrates 
what you are looking for.
Here err-message is a c-string passed back by the dll:

(ffi:def-foreign-type str-pointer (* (* :unsigned-char)))

(ffi:def-function ("sqlite3_exec" sqlite3_exec)
                  ((db sqlite3-db)
                   (sqlcmd :cstring)
                   (callback :pointer-void)
                   (dunno :int)
                   (err-message (* (* :unsigned-char))))
                  :module "sqlite.dll"
                  :returning :int)

  (let ((err-ptr (ffi:allocate-foreign-object 'str-pointer)))
    (sqlite3_exec db-conn sql-stm (ffi:callback 'sql-callback) 0 err-ptr))

To my knowledge, sqlite is giving back pointers to statically allocated 
strings. If, in your case, the c code is allocating the memory, you'll 
need to call it again when you want to free.

Hope this helps!

Dean O'Connor wrote:
> I may have asked his ages ago but can't seem to find any record of it.
> I should probably post this on some UFFI mail list if I can find one
> aswell, but any ideas with ECL.
> I am using UFFI to call our DLL (written in C) functions and most of it
> works ok.
> I can pass cstrings ok as in cl_init().
> But other functions such as cl_elementGetAttachment() creates C strings
> and return them by assigning them to dereferenced argument pointers.
> Also pointers to longs are dereferenced.
> Eg. for the "attachment" argument, in C we pass the address of a C
> string pointer. This get updated with the newly allocated C string
> pointer.
> So is there any way to pass the C-function via UFFI a C pointer arg of
> somekind and have it updated when returning to Lisp ??
> It doesn't seem to fit in with the Lisp way of doing things, but is this
> possible in any way ?
> I am not compiling any of this in Windows. Its just pure interpretive.
> long cl_init(const char *configFileName);
> ((ffi:def-function ("cl_init" init)
>   ((configFileName :cstring ))
>   :returning :long
> )
> long cl_elementGetAttachment(long hDoc, unsigned int index, char **name,
> char **attachment, unsigned long *attachmentSize, bool detach);
> ((ffi:def-function ("cl_elementgetattachment" element-get-attachment)
>                   ((hdoc :long) (index :unsigned-short) (name
> :pointer-void)
>                    (attachment :pointer-void) (attachmentsize
> :pointer-void)
>                    (detach :unsigned-char))
>                   :returning
>                   :long
>                   :module
>                   :default))
> Cheers
> deano
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Ecls-list mailing list
> Ecls-list at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list

More information about the ecl-devel mailing list