PEP 803, round two – “abi3t”: Stable ABI for Free-Threaded Builds

I tried porting nanobind to abi3t (with _Py_OPAQUE_PYOBJECT) to see how it would go and ran into one problem.

nanobind uses a custom function object, which derives from PyVarObject. The variable number of entries is related to the number of function overloads (i.e., C++ functions with the same name but different argument type signatures).

With abi3t I can allocate a PyVarObject-derived object of a given size, and I can also query the number of entries via Py_SIZE(..). But it’s not clear to me how I can get a pointer to the N-th data entry of this function object. In the past, I did something like sizeof(PyVarObject) + sizeof(Payload) * index to compute an offset, but my understanding is that that isn’t allowed since extensions should not depend on sizeof(PyVarObject).

If that can be resolved then nanobind should be able to adopt this new abi3t compilation target.

2 Likes