We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
python
Learn more about funding links in repositories.
Report abuse
There was an error while loading. Please reload this page.
1 parent 1d1393a commit 3eebdffCopy full SHA for 3eebdff
Python/pystate.c
@@ -2821,6 +2821,23 @@ _Py_EnsureImmortal(PyObject *obj)
2821
2822
_Py_SetImmortal(obj);
2823
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
2841
}
2842
2843
void
0 commit comments