From 8f6bf2758dbc6d5ec2e433cd5bfd6580d92a1666 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 7 Dec 2024 21:37:27 +0100 Subject: [PATCH] apply same rule to all cases --- Objects/boolobject.c | 4 ++++ Objects/longobject.c | 2 -- Objects/object.c | 12 ++++++++++-- Objects/sliceobject.c | 8 ++++++-- Objects/typevarobject.c | 8 ++++++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Objects/boolobject.c b/Objects/boolobject.c index a88a8ad0cfd560..fa210227b77fbd 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -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! */ diff --git a/Objects/longobject.c b/Objects/longobject.c index 469937a3cfb2ce..66300ddca0ef78 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3614,7 +3614,6 @@ long_richcompare(PyObject *self, PyObject *other, int op) static void long_dealloc(PyObject *self) { -#if SIZEOF_VOID_P <= 4 /* same condition as in refcount.h */ #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, @@ -3633,7 +3632,6 @@ long_dealloc(PyObject *self) } } } -#endif #endif Py_TYPE(self)->tp_free(self); } diff --git a/Objects/object.c b/Objects/object.c index 8868fa29066404..36cd64a36595dd 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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 * @@ -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 diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 4fef0af93fe095..2bdb53a52767e6 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -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 * diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index bacb858978c5d7..84ecc4f6c77b8d 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -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,