From: Hoehle, Joerg-C. <Joe...@t-...> - 2005-02-09 11:19:07
|
Hi, John Small [mailto:jwe...@co...] wrote: >Hi Joerg, Bruno, Please send such stuff fo clisp-list directly, where it gets archived, = becomes searchable for everyone and more people get a change to answer. =20 >The mysql fetch row function returns a variable length array of = strings: > char ** mysql_fetch_row(result) [...] >So I defined my call out as > (FFI:DEF-CALL-OUT mysql_fetch_row > ... > (:return-type ffi:c-pointer)) >But then when I go to access row > (setf row (mysql_fetch_row result)) >since row is a foreign address and not a place I'm stuck and can't use >any of the cast , offset, etc. macros. >[...]which is similar to your article on compression. Ah, you read some of my stuff. Good! You indeed need to move from a pointer to a place. o WITH-FOREIGN-OBJECT / WITH-C-VAR is one of your friends here: you can = use it to allocate a pointer on the stack initialized to your pointer, = then cast that to the correct type. (with-c-var (p 'c-pointer row-pointer) (offset p `(c-array c-string ,actual-size) 0) o You can use (:return-type (ffi:c-pointer (c-string))) ; limited = declaration returning a single string or (ffi:c-pointer (c-array c-string 1)) which will yield a FOREIGN-VARIABLE object, which makes casting (offset = 0 trick) to an array of strings more direct than the above, with the = help of WITH-C-PLACE. o You can use the FOREIGN-VARIABLE constructor to create the = foreign-variable object out of the foreign-pointer, then apply = WITH-C-PLACE. Oddly, this constructor is not documented. I thought I had added it to = CVS?!? Which you choose may depend on your needs, e.g. whether to dereference = the whole array at once or only a few elements. Regards, J=F6rg H=F6hle. |