C extension custom types in abi3 module
Robin Becker
robin at reportlab.com
Thu Dec 8 07:52:25 EST 2022
I am trying to split off reportlab C extensions to simplify installations and make use of more advanced packages.
A simple extension is easily converted to being an abi3 module. However, another has a custom type which uses the old
style mechanisms here
https://docs.python.org/3.7/extending/newtypes_tutorial.html#the-basics
I made a simple setup based on this abi3 example modified to allow switching between abi3 and normal build
https://github.com/joerick/python-abi3-package-sample
I made a tiny change to the code example in the newtypes tutorial page the code is here
https://github.com/MrBitBucket/custom-type
In a python 3.7 - 3.12a3 environment I find I can build the wheel OK with
ABI3_WHEEL=0 pip wheel -w dist .
but I get lots of compile errors if I switch to an abi3 build with
ABI3_WHEEL=1 pip wheel -w dist .
looking at the errors
> src/_custom.c:10:1: error: variable ‘CustomType’ has initializer but incomplete type
> 10 | static PyTypeObject CustomType = {
> | ^~~~~~
> In file included from /home/robin/LOCAL/3.7.16/include/python3.7m/Python.h:90,
> from src/_custom.c:2:
> /home/robin/LOCAL/3.7.16/include/python3.7m/object.h:90:5: error: extra brace group at end of initializer
> 90 | { PyObject_HEAD_INIT(type) size },
> | ^
> src/_custom.c:11:9: note: in expansion of macro ‘PyVarObject_HEAD_INIT’
> 11 | PyVarObject_HEAD_INIT(NULL, 0)
it looks like I have to use a different mechanism to setup custom types in the abi3 world.
I looked in Modules/xxlimited_35.c, but that seems much more complex and provides for a type which supports GC.
Are there any ABI3 examples using the old style strategy?
--
Robin Becker
More information about the Python-list
mailing list