[cffi-devel] Calling function expecting char**
James Bielman
jamesjb at jamesjb.com
Tue Dec 27 21:20:12 UTC 2005
On Wed, 2005-12-28 at 00:59 +0700, JoeSB COE9 wrote:
> ;; Lisp side
> (cffi:with-foreign-object (argv :pointer 2)
> (setf (cffi:mem-ref argv :pointer 0)
> (cffi:foreign-string-alloc "Hello"))
> (setf (cffi:mem-ref argv :pointer 1)
> (cffi:foreign-string-alloc "Hello"))
> (cffi:foreign-funcall "expect_charpp" :pointer argv))
>
> And I got a memory fault error in SBCL.
You want to use MEM-AREF here, not MEM-REF. The optional third argument
to MEM-REF is a byte offset to add to the pointer, whereas the third
argument to MEM-AREF is an array index.
I admit this is a little confusing---I wonder if MEM-AREF might be
better given a more generic name and documented as the default accessor
for foreign pointers. I don't think user code will need to use the more
primitive features of MEM-REF directly very often...
James
More information about the cffi-devel
mailing list