mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +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
|
@ -29,6 +29,16 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
return Py_NewRef(Py_Ellipsis);
|
||||
}
|
||||
|
||||
static void
|
||||
ellipsis_dealloc(PyObject *ellipsis)
|
||||
{
|
||||
/* This should never get called, but we also don't want to SEGV if
|
||||
* we accidentally decref Ellipsis out of existence. Instead,
|
||||
* since Ellipsis is an immortal object, re-set the reference count.
|
||||
*/
|
||||
_Py_SetImmortal(ellipsis);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ellipsis_repr(PyObject *op)
|
||||
{
|
||||
|
@ -51,7 +61,7 @@ PyTypeObject PyEllipsis_Type = {
|
|||
"ellipsis", /* tp_name */
|
||||
0, /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
0, /*never called*/ /* tp_dealloc */
|
||||
ellipsis_dealloc, /* tp_dealloc */
|
||||
0, /* tp_vectorcall_offset */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
|
@ -89,7 +99,8 @@ PyTypeObject PyEllipsis_Type = {
|
|||
|
||||
PyObject _Py_EllipsisObject = {
|
||||
_PyObject_EXTRA_INIT
|
||||
1, &PyEllipsis_Type
|
||||
{ _Py_IMMORTAL_REFCNT },
|
||||
&PyEllipsis_Type
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue