[Python-Dev] Heap allocate type structs in native extension modules?

Erik Bray erik.m.bray at gmail.com
Thu Dec 28 06:29:10 EST 2017


On Tue, Dec 26, 2017 at 3:00 PM, Benjamin Peterson <benjamin at python.org> wrote:
> I imagine Cython already takes care of this?

This appears to have a distinct purpose, albeit not unrelated to
Cython.  The OP's program would generate boilerplate C code for
extension types the rest of which would perhaps be implemented by hand
in C.  Cython does this as well to an extent, but the generated code
contains quite a bit of Cython-specific cruft and is not really meant
to be edited by hand or read by humans in most cases.

Anyways I don't think this answers the OP's question.

> On Tue, Dec 26, 2017, at 02:16, Hugh Fisher wrote:
>> I have a Python program which generates the boilerplate code for
>> native extension modules from a Python source definition.
>> (http://bitbucket.org/hugh_fisher/fullofeels if interested.)
>>
>> The examples in the Python doco and the "Python Essential Reference"
>> book all use a statically declared PyTypeObject struct and
>> PyType_Ready in the module init func, so I'm doing the same. Then
>> Python 3.5 added a check for statically allocated types inheriting
>> from heap types, which broke a couple of my classes. And now I'm
>> trying to add a __dict__ to native classes so end users can add their
>> own attributes, and this is turning out to be painful with static
>> PyTypeObject structs
>>
>> Would it be better to use dynamically allocated type structs in native
>> modules?


More information about the Python-Dev mailing list