Py_TYPE() and Py_REFCNT() are opaque function calls in limited C API 3.14

Hi,

I modified the limited C API version to implement the following PyObject functions as opaque function calls:

  • Py_TYPE() (since 3.14)
  • Py_REFCNT() (since 3.14), Py_SET_REFCNT() (since 3.13)
  • Py_INCREF(), Py_XINCREF() (since 3.12)
  • Py_DECREF(), Py_XDECREF() (since 3.12)

It became important to hide implementation details, since the implementation of these functions is now way more complicated with Free Threading than before.

Using opaque function calls, it becomes easier to draw a path towards a stable ABI for Free Threading. These changes are not enough, PyObject ABI is still different: there are additional members.

Note: Py_SET_TYPE() is not implemented as an opaque function call since it should not be used in the limited C API, it’s only useful with static types.

See also Limited C API: implement Py_INCREF() and Py_DECREF() as function calls discussion of last year.

3 Likes