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

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Fri Dec 19 21:55:46 CET 2008


For the refcount nanny, I have a file refcheck.pyx which exports several
functions which is called from Cython-generated C code if a flag is set,
to do the reference nannying (basically they are "filters" for Py_...REF
calls, called (__Pyx_RefcheckerIncRef and so on).

Currently, I hack this to work by manually including "cimport refcheck" in
my (single) testcase, and declare the functions as "api", leaving it to
the Cython-specific protocol to do the "linking"/pointer retrieval. This
give me what I need for developing it, but no more...

I could build on this and use the __pyx_capi protocol under the hood etc.,
but it would be kind of nicer to do the linking at the C level (especially
as one would like to refcount the module importing etc. as well) -- so
that my functions (__Pyx_RefcheckerIncRef etc.) was linked in the same way
modules links to the C/Python API. Is this easy/possible? Starting the
Python interpreter in some special way would be acceptable in this case.

I'm afraid this question may demonstrate my ignorance of C linkage :-)

Dag Sverre



More information about the Cython-dev mailing list