Skip to content

Commit 018ee57

Browse files
Do the work in _PyStaticType_InitBuiltin().
1 parent c3d292c commit 018ee57

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

Include/internal/pycore_object.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ static inline void _Py_SetImmortal(PyObject *op)
7373
}
7474
#define _Py_SetImmortal(op) _Py_SetImmortal(_PyObject_CAST(op))
7575

76-
static inline void
77-
_Py_EnsureImmortal(PyObject *op)
78-
{
79-
if (_Py_IsImmortal(op)) {
80-
return;
81-
}
82-
assert(op->ob_type != &PyTuple_Type || PyTuple_GET_SIZE(op) > 0);
83-
_Py_SetImmortal(op);
84-
}
85-
8676
static inline void
8777
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
8878
{

Objects/typeobject.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,9 +2357,6 @@ mro_internal(PyTypeObject *type, PyObject **p_old_mro)
23572357
}
23582358

23592359
type->tp_mro = new_mro;
2360-
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
2361-
_Py_EnsureImmortal(new_mro);
2362-
}
23632360

23642361
type_mro_modified(type, type->tp_mro);
23652362
/* corner case: the super class might have been hidden
@@ -6599,9 +6596,6 @@ type_ready_set_bases(PyTypeObject *type)
65996596
return -1;
66006597
}
66016598
type->tp_bases = bases;
6602-
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
6603-
_Py_EnsureImmortal(bases);
6604-
}
66056599
}
66066600
return 0;
66076601
}
@@ -6619,9 +6613,6 @@ type_ready_set_dict(PyTypeObject *type)
66196613
return -1;
66206614
}
66216615
type->tp_dict = dict;
6622-
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
6623-
_Py_SetImmortal(dict);
6624-
}
66256616
return 0;
66266617
}
66276618

@@ -7063,6 +7054,17 @@ _PyStaticType_InitBuiltin(PyTypeObject *self)
70637054
if (res < 0) {
70647055
static_builtin_state_clear(self);
70657056
}
7057+
7058+
_Py_SetImmortal(self->tp_dict);
7059+
if (!_Py_IsImmortal(self->tp_bases)) {
7060+
assert(PyTuple_GET_SIZE(self->tp_bases) > 0);
7061+
_Py_SetImmortal(self->tp_bases);
7062+
}
7063+
if (!_Py_IsImmortal(self->tp_mro)) {
7064+
assert(PyTuple_GET_SIZE(self->tp_mro) > 0);
7065+
_Py_SetImmortal(self->tp_mro);
7066+
}
7067+
70667068
return res;
70677069
}
70687070

0 commit comments

Comments
 (0)