Skip to content

Commit 8f6bf27

Browse files
committed
apply same rule to all cases
1 parent 56f4133 commit 8f6bf27

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

Objects/boolobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,15 @@ static PyNumberMethods bool_as_number = {
159159
static void
160160
bool_dealloc(PyObject *boolean)
161161
{
162+
#ifndef Py_GIL_DISABLED
162163
/* This should never get called, but we also don't want to SEGV if
163164
* we accidentally decref Booleans out of existence. Instead,
164165
* since bools are immortal, re-set the reference count.
166+
*
167+
* See PEP 683, section Accidental De-Immortalizing for details
165168
*/
166169
_Py_SetImmortal(boolean);
170+
#endif
167171
}
168172

169173
/* The type object for bool. Note that this cannot be subclassed! */

Objects/longobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,7 +3614,6 @@ long_richcompare(PyObject *self, PyObject *other, int op)
36143614
static void
36153615
long_dealloc(PyObject *self)
36163616
{
3617-
#if SIZEOF_VOID_P <= 4 /* same condition as in refcount.h */
36183617
#ifndef Py_GIL_DISABLED
36193618
/* This should never get called, but we also don't want to SEGV if
36203619
* we accidentally decref small Ints out of existence. Instead,
@@ -3633,7 +3632,6 @@ long_dealloc(PyObject *self)
36333632
}
36343633
}
36353634
}
3636-
#endif
36373635
#endif
36383636
Py_TYPE(self)->tp_free(self);
36393637
}

Objects/object.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,11 +2015,15 @@ none_repr(PyObject *op)
20152015
static void
20162016
none_dealloc(PyObject* none)
20172017
{
2018+
#ifndef Py_GIL_DISABLED
20182019
/* This should never get called, but we also don't want to SEGV if
2019-
* we accidentally decref None out of existence. Instead,
2020-
* since None is an immortal object, re-set the reference count.
2020+
* we accidentally decref NotImplemented out of existence. Instead,
2021+
* since Notimplemented is an immortal object, re-set the reference count.
2022+
*
2023+
* See PEP 683, section Accidental De-Immortalizing for details
20212024
*/
20222025
_Py_SetImmortal(none);
2026+
#endif
20232027
}
20242028

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

21712179
static int

Objects/sliceobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
3434
static void
3535
ellipsis_dealloc(PyObject *ellipsis)
3636
{
37+
#ifndef Py_GIL_DISABLED
3738
/* This should never get called, but we also don't want to SEGV if
38-
* we accidentally decref Ellipsis out of existence. Instead,
39-
* since Ellipsis is an immortal object, re-set the reference count.
39+
* we accidentally decref NotImplemented out of existence. Instead,
40+
* since Notimplemented is an immortal object, re-set the reference count.
41+
*
42+
* See PEP 683, section Accidental De-Immortalizing for details
4043
*/
4144
_Py_SetImmortal(ellipsis);
45+
#endif
4246
}
4347

4448
static PyObject *

Objects/typevarobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ nodefault_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
9191
static void
9292
nodefault_dealloc(PyObject *nodefault)
9393
{
94+
#ifndef Py_GIL_DISABLED
9495
/* This should never get called, but we also don't want to SEGV if
95-
* we accidentally decref NoDefault out of existence. Instead,
96-
* since NoDefault is an immortal object, re-set the reference count.
96+
* we accidentally decref NotImplemented out of existence. Instead,
97+
* since Notimplemented is an immortal object, re-set the reference count.
98+
*
99+
* See PEP 683, section Accidental De-Immortalizing for details
97100
*/
98101
_Py_SetImmortal(nodefault);
102+
#endif
99103
}
100104

101105
PyDoc_STRVAR(nodefault_doc,

0 commit comments

Comments
 (0)