[Python-Dev] Heap allocate type structs in native extension modules? (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Fri Dec 29 04:25:14 EST 2017
- Previous message (by thread): [Python-Dev] Heap allocate type structs in native extension modules?
- Next message (by thread): [Python-Dev] Heap allocate type structs in native extension modules?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
26.12.17 12:16, Hugh Fisher пише:
I have a Python program which generates the boilerplate code for native extension modules from a Python source definition. (http://bitbucket.org/hughfisher/fullofeels if interested.)
The examples in the Python doco and the "Python Essential Reference" book all use a statically declared PyTypeObject struct and PyTypeReady 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?
Yes, you can create heap types by using PyType_FromSpecWithBases().
But be aware of caveats (https://bugs.python.org/issue26979).
- Previous message (by thread): [Python-Dev] Heap allocate type structs in native extension modules?
- Next message (by thread): [Python-Dev] Heap allocate type structs in native extension modules?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]