Skip to content

gh-127119: Remove check on accidental deallocation of immortal objects for free-threaded build #127120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Slightly optimize the :class:`int` deallocator by removing a redundant check.
4 changes: 4 additions & 0 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ static PyNumberMethods bool_as_number = {
static void
bool_dealloc(PyObject *boolean)
{
#ifndef Py_GIL_DISABLED
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref Booleans out of existence. Instead,
* since bools are immortal, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(boolean);
#endif
}

/* The type object for bool. Note that this cannot be subclassed! */
Expand Down
4 changes: 4 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3614,9 +3614,12 @@ long_richcompare(PyObject *self, PyObject *other, int op)
static void
long_dealloc(PyObject *self)
{
#ifndef Py_GIL_DISABLED
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
PyLongObject *pylong = (PyLongObject*)self;
if (pylong && _PyLong_IsCompact(pylong)) {
Expand All @@ -3629,6 +3632,7 @@ long_dealloc(PyObject *self)
}
}
}
#endif
Py_TYPE(self)->tp_free(self);
}

Expand Down
12 changes: 10 additions & 2 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,11 +2015,15 @@ none_repr(PyObject *op)
static void
none_dealloc(PyObject* none)
{
#ifndef Py_GIL_DISABLED
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref None out of existence. Instead,
* since None is an immortal object, re-set the reference count.
* we accidentally decref NotImplemented out of existence. Instead,
* since Notimplemented is an immortal object, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(none);
#endif
}

static PyObject *
Expand Down Expand Up @@ -2161,11 +2165,15 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void
notimplemented_dealloc(PyObject *notimplemented)
{
#ifndef Py_GIL_DISABLED
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref NotImplemented out of existence. Instead,
* since Notimplemented is an immortal object, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(notimplemented);
#endif
}

static int
Expand Down
8 changes: 6 additions & 2 deletions Objects/sliceobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void
ellipsis_dealloc(PyObject *ellipsis)
{
#ifndef Py_GIL_DISABLED
/* 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.
* we accidentally decref NotImplemented out of existence. Instead,
* since Notimplemented is an immortal object, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(ellipsis);
#endif
}

static PyObject *
Expand Down
8 changes: 6 additions & 2 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ nodefault_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
static void
nodefault_dealloc(PyObject *nodefault)
{
#ifndef Py_GIL_DISABLED
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref NoDefault out of existence. Instead,
* since NoDefault is an immortal object, re-set the reference count.
* we accidentally decref NotImplemented out of existence. Instead,
* since Notimplemented is an immortal object, re-set the reference count.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
_Py_SetImmortal(nodefault);
#endif
}

PyDoc_STRVAR(nodefault_doc,
Expand Down
Loading