[Cython] CEP1000: Native dispatch through callables

Nathaniel Smith njs at pobox.com
Tue Apr 17 14:40:35 CEST 2012

On Tue, Apr 17, 2012 at 12:54 PM, Dag Sverre Seljebotn
<d.s.seljebotn at astro.uio.no> wrote:
> I don't believe doing interning right without a common dependency .so is all
> that easy. I'd love to see a concrete spec for it (e.g., if you use Python
> bytes in a dict in sys.modules['_nativecall'], the bytes objects could be
> deallocated before callables containing the interned string -- unless you
> Py_INCREF once too many, but then valgrind complains -- and so on).

I don't understand. A C-callable object would hold a reference to each
interned string it contains, just like any other Python data structure
does. When the C-callable object is deallocated, then it drops this
reference, and if it there are no other live C-callable objects that
use the same signature, and there are no callers that are statically
caching the signature, then it will drop out of the intern table.
Otherwise it doesn't.

Basically you do the memory management like you would for any other
bytes object, and everything just works.

-- Nathaniel

More information about the cython-devel mailing list