On Wed, Dec 15, 2021 at 3:07 AM Victor Stinner <vstinner@python.org> wrote:
I wrote https://bugs.python.org/issue39511 and https://github.com/python/cpython/pull/18301 to have per-interpreter None, True and False singletons. My change is backward compatible on the C API: you can still use "Py_None" in your C code. The code gets the singleton object from the current interpreter with a function call:
#define Py_None Py_GetNone()
Py_GetNone() is implemented as: "return _PyInterpreterState_GET()->none;"
It's backward compatible for the C API, but not for the stable C ABI -- that exports Py_None directly as a symbol. You also need a solution for all the static global PyTypeObjects in C extensions. I don't think there's any API-compatible way to make those heap-allocated. -n -- Nathaniel J. Smith -- https://vorpus.org