Skip to content

Commit 42e32d1

Browse files
committed
Add test for python#136154
1 parent 525a2de commit 42e32d1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
import gc
77
import os
8+
import types
89

910
import _opcode
1011

@@ -16,6 +17,8 @@
1617

1718
from _testinternalcapi import TIER2_THRESHOLD
1819

20+
#For test of issue 136154
21+
GLOBAL_136154 = 42
1922

2023
@contextlib.contextmanager
2124
def 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

25052532
def global_identity(x):
25062533
return x

0 commit comments

Comments
 (0)