@@ -4065,6 +4065,55 @@ def hot_loop():
40654065 self .assertNotIn ('_PyJit_TryInitializeTracing' , stderr ,
40664066 f"JIT tracer memory leak detected:\n { stderr } " )
40674067
4068+ def test_cold_exit_on_init_cleanup_frame (self ):
4069+
4070+ result = script_helper .run_python_until_end ('-c' , textwrap .dedent ("""
4071+ class A:
4072+ __slots__ = ('x', 'y', 'z', 'w')
4073+ def __init__(self):
4074+ self.x = self.y = -1
4075+ self.z = self.w = None
4076+
4077+ class B(A):
4078+ __slots__ = ('a', 'b', 'c', 'd', 'e')
4079+ def __init__(self):
4080+ super().__init__()
4081+ self.a = self.b = None
4082+ self.c = ""
4083+ self.d = self.e = False
4084+
4085+ class C(B):
4086+ __slots__ = ('name', 'flag')
4087+ def __init__(self, name):
4088+ super().__init__()
4089+ self.name = name
4090+ self.flag = False
4091+
4092+ funcs = []
4093+ for n in range(20, 80):
4094+ lines = [f"def f{n}(names, info):"]
4095+ for j in range(n):
4096+ lines.append(f" v{j} = names[{j % 3}]")
4097+ if j % 3 == 0:
4098+ lines.append(f" if v{j} in info:")
4099+ lines.append(f" v{j} = info[v{j}]")
4100+ elif j % 5 == 0:
4101+ lines.append(f" v{j} = len(v{j}) if isinstance(v{j}, str) else 0")
4102+ lines.append(" return C(names[0])")
4103+ ns = {'C': C}
4104+ exec("\\ n".join(lines), ns)
4105+ funcs.append(ns[f"f{n}"])
4106+
4107+ names = ['alpha', 'beta', 'gamma']
4108+ info = {'alpha': 'x', 'beta': 'y', 'gamma': 'z'}
4109+
4110+ for f in funcs:
4111+ for _ in range(10):
4112+ f(names, info)
4113+ """ ), PYTHON_JIT = "1" , PYTHON_JIT_STRESS = "1" ,
4114+ PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE = "1" )
4115+ self .assertEqual (result [0 ].rc , 0 , result )
4116+
40684117def global_identity (x ):
40694118 return x
40704119
0 commit comments