8000 Cleanup deallocation of immortal objects · python/cpython@59513a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59513a7

Browse files
Cleanup deallocation of immortal objects
1 parent 7661541 commit 59513a7

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

Objects/boolobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void
146146
bool_dealloc(PyObject *boolean)
147147
{
148148
/* This should never get called, but we also don't want to SEGV if
149-
* we accidentally decref NotImplemented out of existence. Instead,
149+
* we accidentally decref Booleans out of existence. Instead,
150150
* since Bools are immortal, re-set the reference count.
151151
*/
152152
_Py_SetImmortal(boolean);

Objects/longobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,8 +3322,8 @@ static void
33223322
long_dealloc(PyObject *self)
33233323
{
33243324
/* This should never get called, but we also don't want to SEGV if
3325-
* we accidentally decref NotImplemented out of existence. Instead,
3326-
* since None is an immortal object, re-set the reference count.
3325+
* we accidentally decref small Ints out of existence. Instead,
3326+
* since small Ints are immortal, re-set the reference count.
33273327
*/
33283328
PyLongObject *pylong = (PyLongObject*)self;
33293329
if (pylong && IS_MEDIUM_VALUE(pylong)) {

Objects/object.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,10 +1627,14 @@ none_repr(PyObject *op)
16271627
return PyUnicode_FromString("None");
16281628
}
16291629

1630-
static void _Py_NO_RETURN
1631-
none_dealloc(PyObject* Py_UNUSED(ignore))
1630+
static void
1631+
none_dealloc(PyObject* none)
16321632
{
1633-
_Py_FatalRefcountError("deallocating None");
1633+
/* This should never get called, but we also don't want to SEGV if
1634+
* we accidentally decref None out of existence. Instead,
1635+
* since None is an immortal object, re-set the reference count.
1636+
*/
1637+
_Py_SetImmortal(none);
16341638
}
16351639

16361640
static PyObject *
@@ -1696,7 +1700,7 @@ PyTypeObject _PyNone_Type = {
16961700
"NoneType",
16971701
0,
16981702
0,
1699-
none_dealloc, /*tp_dealloc*/ /*never called*/
1703+
none_dealloc, /*tp_dealloc*/
17001704
0, /*tp_vectorcall_offset*/
17011705
0, /*tp_getattr*/
17021706
0, /*tp_setattr*/
@@ -1769,13 +1773,13 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
17691773
}
17701774

17711775
static void
1772-
notimplemented_dealloc(PyObject *none)
1776+
notimplemented_dealloc(PyObject *notimplemented)
17731777
{
17741778
/* This should never get called, but we also don't want to SEGV if
17751779
* we accidentally decref NotImplemented out of existence. Instead,
1776-
* since None is an immortal object, re-set the reference count.
1780+
* since Notimplemented is an immortal object, re-set the reference count.
17771781
*/
1778-
_Py_SetImmortal(none);
1782+
_Py_SetImmortal(notimplemented);
17791783
}
17801784

17811785
static int

Objects/sliceobject.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
2929
return Py_NewRef(Py_Ellipsis);
3030
}
3131

32+
static void
33+
ellipsis_dealloc(PyObject *ellipsis)
34+
{
35+
/* This should never get called, but we also don't want to SEGV if
36+
* we accidentally decref Ellipsis out of existence. Instead,
37+
* since Ellipsis is an immortal object, re-set the reference count.
38+
*/
39+
_Py_SetImmortal(ellipsis);
40+
}
41+
3242
static PyObject *
3343
ellipsis_repr(PyObject *op)
3444
{
@@ -51,7 +61,7 @@ PyTypeObject PyEllipsis_Type = {
5161
"ellipsis", /* tp_name */
5262
0, /* tp_basicsize */
5363
0, /* tp_itemsize */
54-
0, /*never called*/ /* tp_dealloc */
64+
ellipsis_dealloc, /* tp_dealloc */
5565
0, /* tp_vectorcall_offset */
5666
0, /* tp_getattr */
5767
0, /* tp_setattr */

Objects/unicodeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,8 +1529,8 @@ unicode_dealloc(PyObject *unicode)
15291529
}
15301530
#endif
15311531
/* This should never get called, but we also don't want to SEGV if
1532-
* we accidentally decref NotImplemented out of existence. Instead,
1533-
* since None is an immortal object, re-set the reference count.
1532+
* we accidentally decref the string out of existence. Instead,
1533+
* since the string is an immortal object, re-set the reference count.
15341534
*/
15351535
if (PyUnicode_CHECK_INTERNED(unicode)) {
15361536
_Py_SetImmortal(unicode);

0 commit comments

Comments
 (0)
0