• C extension custom types in abi3 module

    From Robin Becker@21:1/5 to All on Thu Dec 8 12:52:25 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robin Becker@21:1/5 to Robin Becker on Thu Dec 8 15:35:55 2022
    On 08/12/2022 12:52, Robin Becker wrote:
    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
    ............

    it looks like I have to use a different mechanism to setup custom types in the abi3 world.

    In the docs I see this

    "Also, since PyTypeObject is only part of the Limited API as an opaque struct, any extension modules using static types
    must be compiled for a specific Python minor version."

    So it seems I must switch to using a heap allocated type or keep compiling in the old way.


    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

    --
    Robin Becker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)