[cffi-devel] foreign strings

Stelian Ionescu sionescu at common-lisp.net
Wed Sep 10 22:20:36 UTC 2008


On Wed, 2008-09-10 at 22:35 +0100, Andy Chambers wrote:
> 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...

from the sqlite documentation:
The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
string after SQLite has finished with it. If the fifth argument is the
special value SQLITE_STATIC, then SQLite assumes that the information is
in static, unmanaged space and does not need to be freed. If the fifth
argument has the value SQLITE_TRANSIENT, then SQLite makes its own
private copy of the data immediately, before the sqlite3_bind_*()
routine returns.

You're passing 0 as fifth parameter, which is SQLITE_STATIC, but that's
only for static data, while CFFI C-strings are dynamically allocated.
Use SQLITE_TRANSIENT instead.

-- 
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20080911/0cd706c5/attachment.sig>


More information about the cffi-devel mailing list