[cffi-devel] foreign strings
Stephen Compall
s11 at member.fsf.org
Wed Sep 10 22:00:19 UTC 2008
"Andy Chambers" <achambers.home at googlemail.com> writes:
> (value :string)
> (len :int)
> ;; not really an int but cffi takes care of this for us
> (destructor :int))
>
> Everything is pretty straightforward apart from the last two
> parameters. Length is supposed to be the length of the value being
> passed in (or -1 if the value is null terminated).
> The destructor is supposed to be a function that frees the memory
> required by `value' after sqlite is finished with it. For destructor,
> you can use the special value 0 if the memory
> is in "unmanaged" space. So I have a few questions...
>
> 1. If you specify the type as :string, does cffi pass it through as a
> null terminated string?
Yes.
> 2. Does cffi take care of freeing a string once the C library is
> finished with it or should I define a callback to use for the
> destructor.
The semantics described in
http://common-lisp.net/project/cffi/manual/html_node/Tutorial_002dMemory.html
are still accurate.
So the answer is "just what does `once the C library is finished with
it' mean anyway?"
> 3. With my current code, I'm not getting any memory errors but I am
> getting weird values in the database.
>
> ˆ|Ñø·Ñø·IBUTE|ˆ|˜Â'ø|ˆ|˜Â'ø|Ñø·Ñø·IBUTE||
>
> Any ideas what's going on here?
See footnote ¹ on the page I linked above.
--
I write stuff at http://failex.blogspot.com/ now. But the post
formatter and themes are terrible for sharing code, the primary
content, so it might go away sooner or later.
More information about the cffi-devel
mailing list