[Cython] Best way to link in Cython utility code?

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Sat Dec 20 19:45:34 CET 2008


Lisandro Dalcin wrote:
> On Dec 20, 2008, at 10:21 AM, Lisandro Dalcin wrote:
>
>> Then It would be really easy to implement some ctypes hackery to make
>> globally visible the API required for nanny refcounting.
>
> This won't work for the trickiest part, all the temp variables and
> exceptions that need to be handled correctly. On the other hand, the
> external variables can't always be refcounted automatically, because
> the semantics may dictate that the refcounts increase or decrease
> (e.g. inserting into a list).

If I understand correctly, Lisandro simply recommends loading the library
loading my refchecker.so utility code (basically a twenty-liner raising
the right diagnostics at the right times) using ctypes with the
RTLD_GLOBAL flag (which I didn't know about until I just now read the
ctypes docs).

Over to something else: Does anyone have an opinion on a choice between
these two:

 - I change Cython to always generate __Pyx_INCREF/DECREF/GOTREF/GIVEREF.
Whether to install the refcount nanny or not only affects the definition
of these macros (the latter two being noops when the nanny is not in
operation). I'm +1 on this one.

 - If the refcount nanny is not installed, generate direct
Py_INCREF/DECREF and do not generate GOTREF/GIVEREF.

Dag Sverre



More information about the Cython-dev mailing list