Using CFFI: dealing with a writeback buffer

Luís Oliveira luismbo at gmail.com
Wed Jul 15 00:20:51 UTC 2015


Hello Victor,

I think you're looking for something along these lines.

(with-foreign-object (proj :pointer)
  (osr-export-to-proj-4 handle proj)
  (let ((p (mem-ref proj :pointer)))
    (write-line (foreign-string-to-lisp p))
    (cpl-free p)))

Cheers,
Luís

(painstakingly typed on a phone)

On Tue, Jul 14, 2015, 14:37 Victor <bobbie at ua.fm> wrote:

> Hi all,
>
> I don't know if it is the best place to ask this question, but I'll try
> it. I am trying to wrap around a following function:
>
> OGRErr OSRExportToProj4(OGRSpatialReferenceH r, char **buff);
>
> This function allocates the string and assigns it to the (char*) pointer
> passed as buff and then its contents should be copied into a C string and
> the obtained pointer released via CPLFree();
>
> So, basically, in C a typical usage would be:
>
>   char *proj = NULL:
>   OSRExportToProj4(handle, &proj);
>   printf("%s\n", proj);
>   CPLFree(proj);
>
> And the question is: how is this function should be wrapped with CFFI?
>
> Thanks,
> Victor
>
> -- реклама -----------------------------------------------------------
> FREEhost.UA - быстрый и удобный хостинг доступный каждому.
> http://freehost.com.ua/unix/
>
> --

Luís

(sent from my phone)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20150715/607f7f5a/attachment.html>


More information about the cffi-devel mailing list