[Cython] CEP 1001 - Custom PyTypeObject extensions
njs at pobox.com
Mon May 14 14:29:06 CEST 2012
On Sun, May 13, 2012 at 8:35 PM, Dag Sverre Seljebotn
<d.s.seljebotn at astro.uio.no> wrote:
> On 05/12/2012 08:44 PM, Nathaniel Smith wrote:
>> On Fri, May 11, 2012 at 2:25 PM, Dag Sverre Seljebotn
>> <d.s.seljebotn at astro.uio.no> wrote:
>>> This comes from a refactor of the work on CEP 1000: A PEP proposal, with
>>> hack for use in current Python versions and in the case of PEP rejection,
>>> that allows 3rd party libraries to agree on extensions to PyTypeObject.
>>> If this makes it as a PEP, I don't think we need to think about having
>>> 1000 accepted as a PEP.
>> There should probably be some discussion of memory management for the
>> tpe_data pointers. (I assume it's "guaranteed to be valid for as long
>> as the associated PyTypeObject, and the PyTypeObject is responsible
>> for making sure any necessary cleanup happens if it gets deallocated",
>> but a note to this effect would be good.)
>> What happens if I want to inherit from PyTypeObject (a "metaclass")
>> and also implement this interface? It is possible? What if I want to
>> inherit from an existing subclass of PyTypeObject and add on this
>> interface? I don't know enough gnarly details about how new style
>> classes are implemented to tell. Would it make sense to make this
>> memory-layout-equivalent to a PyTypeObject subclass with extra fields?
> Hmm. You know what -- this whole thing could probably be a metaclass.
Well, yes, conceptually, that's exactly what it is -- the question is
how and whether it relates to the Python metaclass machinery, since
you are speed freaks :-).
> I think a PyObject_TypeCheck on the type would be a bit more expensive than
> just checking a flag. I think I like having a flag better...
A number of existing flags are actually used exactly to make
type-checking faster for some key types (PY_TPFLAGS_INT_SUBCLASS,
etc.). I guess doing it the same way would put the flag in
obj->tp_class->tp_class->tp_flags, though, instead of
More information about the cython-devel