Hi William,
On Wed, 21 Apr 2021 at 16:59, William Roberts <
bill.c....@gmail.com> wrote:
> How do we set a free function for x[0]? I tried using ffi.gc like so:
> ffi.gc(x[0], lib.custom_free)
>
> but that bombed.
Every call to x[0] returns a new CFFI pointer object (pointing to the
same thing). Additionally, ffi.gc() returns yet another pointer
object (again pointing to the same thing). That's the one that must
be kept alive in Python. So:
return ffi.gc(x[0], lib.custom_free)
will call lib.custom_free(y) at some point after the pointer returned
by this py_foo() function is forgotten.
A bientôt,
Armin.