Add Py_GetConstant() and Py_GetConstantBorrowed() functions.
In the limited C API version 3.13, getting Py_None, Py_False,
Py_True, Py_Ellipsis and Py_NotImplemented singletons is now
implemented as function calls at the stable ABI level to hide
implementation details. Getting these constants still return borrowed
references.
Add _testlimitedcapi/object.c and test_capi/test_object.py to test
Py_GetConstant() and Py_GetConstantBorrowed() functions.
This is the implementation of PEP683
Motivation:
The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime.
Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
As part of the PEP-652 implementation, I'll tighten the CI check
for functions/data defined with `Py_LIMITED_API`.
Discussion in https://discuss.python.org/t/pep-652-maintaining-the-stable-abi/6986
suggests that parsing C headers is OK (though personally I'd rather generate it...),
but writing a full C parser is a monumental task and adding an existing one as a
dependency brings too many vendoring/bootstraping issues.
So, for the check I'll use a "simple" regex on preprocessor output, and adapt
the few trivial places where the regex won't work.
- Keep declarations in the limited API to one item per line
- Make it possible to override `_Py_NO_RETURN`, so the annotation can be
removed from preprocessor output.
https://bugs.python.org/issue43795
Add the Py_Is(x, y) function to test if the 'x' object is the 'y'
object, the same as "x is y" in Python. Add also the Py_IsNone(),
Py_IsTrue(), Py_IsFalse() functions to test if an object is,
respectively, the None singleton, the True singleton or the False
singleton.
I banged on the code (beyond what's in that branch) to make fewer tests fail;
the only tests that fail now are:
test_descr -- can't pickle ints?!
test_pickletools -- ???
test_socket -- See python.org/sf/1619659
test_sqlite -- ???
I'll deal with those later.
Rewrote Py_RETURN_{NONE, TRUE, FALSE} to expand to comma expressions
rather than "do {} while(0)" thingies. The OP complained because he
likes using MS /W4 sometimes, and then all his uses of these things
generate nuisance warnings about testing a constant expression (in
the "while(0)" part). Comma expressions don't have this problem
(although it's a lucky accident that comma expressions suffice for these
macros!).