Skip to content

Commit

Permalink
apply same rule to all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Dec 7, 2024
1 parent 56f4133 commit 8f6bf27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
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
2 changes: 0 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -3633,7 +3632,6 @@ long_dealloc(PyObject *self)
}
}
}
#endif
#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

0 comments on commit 8f6bf27

Please sign in to comment.