
On 16. 12. 21 11:52, Victor Stinner wrote:
On Thu, Dec 16, 2021 at 2:29 AM Nathaniel Smith <njs@pobox.com> wrote:
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're right. But we can add a macro like Py_SUBINTERPRETER_API which would change the implementation:
* By default, "Py_None" would continue returning "&_Py_NoneStruct". * If Py_SUBINTERPRETER_API macro is defined, Py_None would call Py_GetNone().
=> no impact on the stable ABI (if used, the stable ABI is not supported)
The stable ABI could be orthogonal here -- you could compile for the stable ABI even with Py_SUBINTERPRETER_API. This would require (_PyInterpreterState_GET()->none == Py_None) in the "main" interpreter, and extrensions without Py_SUBINTERPRETER_API only loadable in the "main" interpreter.
=> no impact on performance (if not used)
But it *would* be used in all of the stdlib, right?
=> only C extensions which opt-in for "subinterpreter running in parallel" support (define Py_SUBINTERPRETER_API) would be impacted.
Stdlib C extensions would have to be built with Py_SUBINTERPRETER_API, but it is ok if the require a recent ABI since they are shipped with Python directly (and not currently built with the limited C API).
Victor