[pypy-dev] How to convert python string to C char*?
Armin Rigo
arigo at tunes.org
Thu May 14 12:29:19 CEST 2015
Hi Yicong,
On 14 May 2015 at 11:33, Yicong Huang <hengha.mao at gmail.com> wrote:
> To my understanding, "ALL_RESULTS" is used to prevent pypy GC the pointing
> buffer.
> And thus, it is the C callback function's responsibility to free the buffer.
> Am I right?
No. In my example I just keep storing ffi.new("char[]") objects in
the list, so this list grows forever and leaks.
You really need to see the documentation of the C code for which you
are making a callback. Maybe it says that the callback needs to
return a string obtained by ``malloc()``, and it will be ``free()``-ed
for you. In that case you need to call ``lib.malloc()`` from the
library obtained by cffi, after adding "char *malloc(size_t);" to the
cdef().
But I can't guess if I'm correct; it depends on the C code.
A bientôt,
Armin.
More information about the pypy-dev
mailing list