Skip to content

Commit

Permalink
Recursively immortalize.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Apr 25, 2023
1 parent 1d1393a commit 3eebdff
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,23 @@ _Py_EnsureImmortal(PyObject *obj)

_Py_SetImmortal(obj);
immortalized_add(&_PyRuntime.immortalized_objects, obj);

if (Py_TYPE(obj) == &PyDict_Type) {
Py_ssize_t i = 0;
PyObject *key, *value; // borrowed ref
while (PyDict_Next(obj, &i, &key, &value)) {
_Py_EnsureImmortal(key);
_Py_EnsureImmortal(value);
}
}
else if (Py_TYPE(obj) == &PyTuple_Type) {
assert(PyTuple_GET_SIZE(obj) > 0);
Py_ssize_t size = PyTuple_GET_SIZE(obj);
assert(size > 0);
for (Py_ssize_t i = 0; i < size; i++) {
_Py_EnsureImmortal(PyTuple_GET_ITEM(obj, i));
}
}
}

void
Expand Down

0 comments on commit 3eebdff

Please sign in to comment.