Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3eebdff

Browse files
committedApr 25, 2023·
Recursively immortalize.
1 parent 1d1393a commit 3eebdff

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎Python/pystate.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,23 @@ _Py_EnsureImmortal(PyObject *obj)
28212821

28222822
_Py_SetImmortal(obj);
28232823
immortalized_add(&_PyRuntime.immortalized_objects, obj);
2824+
2825+
if (Py_TYPE(obj) == &PyDict_Type) {
2826+
Py_ssize_t i = 0;
2827+
PyObject *key, *value; // borrowed ref
2828+
while (PyDict_Next(obj, &i, &key, &value)) {
2829+
_Py_EnsureImmortal(key);
2830+
_Py_EnsureImmortal(value);
2831+
}
2832+
}
2833+
else if (Py_TYPE(obj) == &PyTuple_Type) {
2834+
assert(PyTuple_GET_SIZE(obj) > 0);
2835+
Py_ssize_t size = PyTuple_GET_SIZE(obj);
2836+
assert(size > 0);
2837+
for (Py_ssize_t i = 0; i < size; i++) {
2838+
_Py_EnsureImmortal(PyTuple_GET_ITEM(obj, i));
2839+
}
2840+
}
28242841
}
28252842

28262843
void

0 commit comments

Comments
 (0)
Please sign in to comment.