0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 17:47:13 +01:00

gh-121863: Immortalize names in code objects to avoid crash (GH-121903)

This commit is contained in:
Petr Viktorin 2024-07-17 11:31:28 +02:00 committed by GitHub
parent bfdbeac355
commit cffad5c6ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -810,6 +810,30 @@ class ScopeTests(unittest.TestCase):
gc_collect() # For PyPy or other GCs. gc_collect() # For PyPy or other GCs.
self.assertIsNone(ref()) self.assertIsNone(ref())
def test_multiple_nesting(self):
# Regression test for https://github.com/python/cpython/issues/121863
class MultiplyNested:
def f1(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g(_MultiplyNested__arg=2)
def f2(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g
inst = MultiplyNested()
with self.assertRaises(TypeError):
inst.f1()
closure = inst.f2()
with self.assertRaises(TypeError):
closure(_MultiplyNested__arg=2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -147,7 +147,7 @@ intern_strings(PyObject *tuple)
"non-string found in code slot"); "non-string found in code slot");
return -1; return -1;
} }
_PyUnicode_InternMortal(interp, &_PyTuple_ITEMS(tuple)[i]); _PyUnicode_InternImmortal(interp, &_PyTuple_ITEMS(tuple)[i]);
} }
return 0; return 0;
} }