mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
gh-84436: Implement Immortal Objects (gh-19474)
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.
This commit is contained in:
parent
916de04fd1
commit
ea2c001650
35 changed files with 483 additions and 171 deletions
|
|
@ -11,8 +11,7 @@ PyAPI_DATA(PyTypeObject) PyBool_Type;
|
|||
|
||||
#define PyBool_Check(x) Py_IS_TYPE((x), &PyBool_Type)
|
||||
|
||||
/* Py_False and Py_True are the only two bools in existence.
|
||||
Don't forget to apply Py_INCREF() when returning either!!! */
|
||||
/* Py_False and Py_True are the only two bools in existence. */
|
||||
|
||||
/* Don't use these directly */
|
||||
PyAPI_DATA(PyLongObject) _Py_FalseStruct;
|
||||
|
|
@ -31,8 +30,8 @@ PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
|
|||
#define Py_IsFalse(x) Py_Is((x), Py_False)
|
||||
|
||||
/* Macros for returning Py_True or Py_False, respectively */
|
||||
#define Py_RETURN_TRUE return Py_NewRef(Py_True)
|
||||
#define Py_RETURN_FALSE return Py_NewRef(Py_False)
|
||||
#define Py_RETURN_TRUE return Py_True
|
||||
#define Py_RETURN_FALSE return Py_False
|
||||
|
||||
/* Function to return a bool from a C long */
|
||||
PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue