File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 55import unittest
66import gc
77import os
8+ import types
89
910import _opcode
1011
1617
1718from _testinternalcapi import TIER2_THRESHOLD
1819
20+ #For test of issue 136154
21+ GLOBAL_136154 = 42
1922
2023@contextlib .contextmanager
2124def clear_executors (func ):
@@ -2501,6 +2504,30 @@ def testfunc(n):
25012504 # For now... until we constant propagate it away.
25022505 self .assertIn ("_BINARY_OP" , uops )
25032506
2507+ def test_jitted_code_sees_changed_globals (self ):
2508+ "Issue 136154: Check that jitted code spots the change in the globals"
2509+
2510+ def make_f ():
2511+ def f ():
2512+ return GLOBAL_136154
2513+ return f
2514+
2515+ make_f_with_bad_globals = types .FunctionType (make_f .__code__ , {})
2516+
2517+ def jitted (funcs ):
2518+ for func in funcs :
2519+ func ()
2520+
2521+ # Make a "good" f:
2522+ f = make_f ()
2523+ # Compile jitted for the "good" f:
2524+ jitted ([f ] * TIER2_THRESHOLD )
2525+ # This "bad" f has different globals, but the *same* code/function versions:
2526+ f_with_bad_globals = make_f_with_bad_globals ()
2527+ # A "good" f to enter the JIT code, and a "bad" f to trigger the bug:
2528+ with self .assertRaises (NameError ):
2529+ jitted ([f , f_with_bad_globals ])
2530+
25042531
25052532def global_identity (x ):
25062533 return x
You can’t perform that action at this time.
0 commit comments