How do I access a char ** through ffi in plt-scheme?
Question
I'm mocking about with plt-scheme's ffi and I have a C-function that returns a char ** (array of strings). If I declare my function as (_fun _pointer -> _pointer)
, how do I convert the result to a list of strings in scheme?
Here are the relevant C-declarations:
typedef char **MYSQL_ROW; /* return data as array of strings */
// ...
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
Solution
I think that what you want is the cvector:
http://docs.plt-scheme.org/foreign/Derived_Utilities.html#(part._foreign~3acvector)
A cvector of _string/utf-8 or whichever encoding you need seems reasanable.
But that's from a quick survey of the docs - I haven't tried this myself. Please let me know if it works!
OTHER TIPS
I know it's not exactly what you are looking for, but it might help a little bit. I've done some work on a basic Gambit Scheme FFI for MySQL. I don't know how PLT Scheme and Gambit differ in terms of their FFI implementation (I'd venture with "quite a bit") but maybe you can get something out of it:
http://bunny.jonnay.net/zengarden/trunk/lib/mysql/mysql-ffi.scm
Aha, I figured it out myself.
I have to use the _cpointer
procedure, described at the page that mike linked to:
(_fun _pointer -> (_cpointer/null 'mysql-row (make-ctype _pointer #f #f)))
It also seems that someone already beat me to creating a ffi to mysqlclient. Not to worry; My main goal is understanding the ffi api, and it's going forward.