8000 Merge branch 'main' into reenable-stress-tests · python/cpython@87019d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87019d6

Browse files
Merge branch 'main' into reenable-stress-tests
2 parents 81087f5 + 017f047 commit 87019d6

File tree

12 files changed

+136
-147
lines changed

12 files changed

+136
-147
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ opcode
124124
This field was added in 3.12, it was never documented and is not intended for
125125
external usage. (Contributed by Irit Katriel in :gh:`105481`.)
126126

127+
* Removed ``opcode.is_pseudo``, ``opcode.MIN_PSEUDO_OPCODE`` and
128+
``opcode.MAX_PSEUDO_OPCODE``, which were added in 3.12, were never
129+
documented or exposed through ``dis``, and were not intended to be
130+
used externally.
131+
127132
pathlib
128133
-------
129134

Include/opcode.h

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/opcode.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,11 @@
1919

2020
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2121

22-
def is_pseudo(op):
23-
return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
24-
2522
opmap = {}
2623

27-
# pseudo opcodes (used in the compiler) mapped to the values
28-
# they can become in the actual code.
29-
_pseudo_ops = {}
30-
3124
def def_op(name, op):
3225
opmap[name] = op
3326

34-
def pseudo_op(name, op, real_ops):
35-
def_op(name, op)
36-
_pseudo_ops[name] = real_ops
37-
38-
3927
# Instruction opcodes for compiled code
4028
# Blank lines correspond to available opcodes
4129

@@ -212,29 +200,27 @@ def pseudo_op(name, op, real_ops):
212200
# 255 is reserved
213201

214202

215-
MIN_PSEUDO_OPCODE = 256
216-
217-
pseudo_op('SETUP_FINALLY', 256, ['NOP'])
218-
pseudo_op('SETUP_CLEANUP', 257, ['NOP'])
219-
pseudo_op('SETUP_WITH', 258, ['NOP'])
220-
pseudo_op('POP_BLOCK', 259, ['NOP'])
203+
# Pseudo ops are above 255:
221204

222-
pseudo_op('JUMP', 260, ['JUMP_FORWARD', 'JUMP_BACKWARD'])
223-
pseudo_op('JUMP_NO_INTERRUPT', 261, ['JUMP_FORWARD', 'JUMP_BACKWARD_NO_INTERRUPT'])
205+
def_op('SETUP_FINALLY', 256)
206+
def_op('SETUP_CLEANUP', 257)
207+
def_op('SETUP_WITH', 258)
208+
def_op('POP_BLOCK', 259)
224209

225-
pseudo_op('LOAD_METHOD', 262, ['LOAD_ATTR'])
226-
pseudo_op('LOAD_SUPER_METHOD', 263, ['LOAD_SUPER_ATTR'])
227-
pseudo_op('LOAD_ZERO_SUPER_METHOD', 264, ['LOAD_SUPER_ATTR'])
228-
pseudo_op('LOAD_ZERO_SUPER_ATTR', 265, ['LOAD_SUPER_ATTR'])
210+
def_op('JUMP', 260)
211+
def_op('JUMP_NO_INTERRUPT', 261)
229212

230-
pseudo_op('STORE_FAST_MAYBE_NULL', 266, ['STORE_FAST'])
231-
pseudo_op('LOAD_CLOSURE', 267, ['LOAD_FAST'])
213+
def_op('LOAD_METHOD', 262)
214+
def_op('LOAD_SUPER_METHOD', 263)
215+
def_op('LOAD_ZERO_SUPER_METHOD', 264)
216+
def_op('LOAD_ZERO_SUPER_ATTR', 265)
232217

233-
MAX_PSEUDO_OPCODE = MIN_PSEUDO_OPCODE + len(_pseudo_ops) - 1
218+
def_op('STORE_FAST_MAYBE_NULL', 266)
219+
def_op('LOAD_CLOSURE', 267)
234220

235-
del def_op, pseudo_op
221+
del def_op
236222

237-
opname = ['<%r>' % (op,) for op in range(MAX_PSEUDO_OPCODE + 1)]
223+
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
238224
for op, i in opmap.items():
239225
opname[i] = op
240226

Lib/test/test_capi/test_misc.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,36 +2464,40 @@ def testfunc(x):
24642464

24652465
def test_extended_arg(self):
24662466
"Check EXTENDED_ARG handling in superblock creation"
2467-
def many_vars():
2468-
# 260 vars, so z9 should have index 259
2469-
a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 42
2470-
b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = 42
2471-
c0 = c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = c9 = 42
2472-
d0 = d1 = d2 = d3 = d4 = d5 = d6 = d7 = d8 = d9 = 42
2473-
e0 = e1 = e2 = e3 = e4 = e5 = e6 = e7 = e8 = e9 = 42
2474-
f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 42
2475-
g0 = g1 = g2 = g3 = g4 = g5 = g6 = g7 = g8 = g9 = 42
2476-
h0 = h1 = h2 = h3 = h4 = h5 = h6 = h7 = h8 = h9 = 42
2477-
i0 = i1 = i2 = i3 = i4 = i5 = i6 = i7 = i8 = i9 = 42
2478-
j0 = j1 = j2 = j3 = j4 = j5 = j6 = j7 = j8 = j9 = 42
2479-
k0 = k1 = k2 = k3 = k4 = k5 = k6 = k7 = k8 = k9 = 42
2480-
l0 = l1 = l2 = l3 = l4 = l5 = l6 = l7 = l8 = l9 = 42
2481-
m0 = m1 = m2 = m3 = m4 = m5 = m6 = m7 = m8 = m9 = 42
2482-
n0 = n1 = n2 = n3 = n4 = n5 = n6 = n7 = n8 = n9 = 42
2483-
o0 = o1 = o2 = o3 = o4 = o5 = o6 = o7 = o8 = o9 = 42
2484-
p0 = p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = 42
2485-
q0 = q1 = q2 = q3 = q4 = q5 = q6 = q7 = q8 = q9 = 42
2486-
r0 = r1 = r2 = r3 = r4 = r5 = r6 = r7 = r8 = r9 = 42
2487-
s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = 42
2488-
t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = t8 = t9 = 42
2489-
u0 = u1 = u2 = u3 = u4 = u5 = u6 = u7 = u8 = u9 = 42
2490-
v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = 42
2491-
w0 = w1 = w2 = w3 = w4 = w5 = w6 = w7 = w8 = w9 = 42
2492-
x0 = x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = x9 = 42
2493-
y0 = y1 = y2 = y3 = y4 = y5 = y6 = y7 = y8 = 558 y9 = 42
2494-
z0 = z1 = z2 = z3 = z4 = z5 = z6 = z7 = z8 = z9 = 42
2495-
while z9 > 0:
2496-
z9 = z9 - 1
2467+
ns = {}
2468+
exec(textwrap.dedent("""
2469+
def many_vars():
2470+
# 260 vars, so z9 should have index 259
2471+
a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 42
2472+
b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = 42
2473+
c0 = c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = c9 = 42
2474+
d0 = d1 = d2 = d3 = d4 = d5 = d6 = d7 = d8 = d9 = 42
2475+
e0 = e1 = e2 = e3 = e4 = e5 = e6 = e7 = e8 = e9 = 42
2476+
f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 42
2477+
g0 = g1 = g2 = g3 = g4 = g5 = g6 = g7 = g8 = g9 = 42
2478+
h0 = h1 = h2 = h3 = h4 = h5 = h6 = h7 = h8 = h9 = 42
2479+
i0 = i1 = i2 = i3 = i4 = i5 = i6 = i7 = i8 = i9 = 42
2480+
j0 = j1 = j2 = j3 = j4 = j5 = j6 = j7 = j8 = j9 = 42
2481+
k0 = k1 = k2 = k3 = k4 = k5 = k6 = k7 = k8 = k9 = 42
2482+
l0 = l1 = l2 = l3 = l4 = l5 = l6 = l7 = l8 = l9 = 42
2483+
m0 = m1 = m2 = m3 = m4 = m5 = m6 = m7 = m8 = m9 = 42
2484+
n0 = n1 = n2 = n3 = n4 = n5 = n6 = n7 = n8 = n9 = 42
2485+
o0 = o1 = o2 = o3 = o4 = o5 = o6 = o7 = o8 = o9 = 42
2486+
p0 = p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = 42
2487+
q0 = q1 = q2 = q3 = q4 = q5 = q6 = q7 = q8 = q9 = 42
2488+
r0 = r1 = r2 = r3 = r4 = r5 = r6 = r7 = r8 = r9 = 42
2489+
s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = 42
2490+
t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = t8 = t9 = 42
2491+
u0 = u1 = u2 = u3 = u4 = u5 = u6 = u7 = u8 = u9 = 42
2492+
v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = 42
2493+
w0 = w1 = w2 = w3 = w4 = w5 = w6 = w7 = w8 = w9 = 42
2494+
x0 = x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = x9 = 42
2495+
y0 = y1 = y2 = y3 = y4 = y5 = y6 = y7 = y8 = y9 = 42
2496+
z0 = z1 = z2 = z3 = z4 = z5 = z6 = z7 = z8 = z9 = 42
2497+
while z9 > 0:
2498+
z9 = z9 - 1
2499+
"""), ns, ns)
2500+
many_vars = ns["many_vars"]
24972501

24982502
opt = _testinternalcapi.get_uop_optimizer()
24992503
with temporary_optimizer(opt):

Lib/test/test_import/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def _ready_to_import(name=None, source=""):
150150
def restore__testsinglephase(*, _orig=_testsinglephase):
151151
# We started with the module imported and want to restore
152152
# it to its nominal state.
153+
sys.modules.pop('_testsinglephase', None)
153154
_orig._clear_globals()
154155
_testinternalcapi.clear_extension('_testsinglephase', _orig.__file__)
155156
import _testsinglephase
@@ -2125,7 +2126,7 @@ def clean_up():
21252126
_interpreters.run_string(interpid, textwrap.dedent(f'''
21262127
name = {self.NAME!r}
21272128
if name in sys.modules:
2128-
sys.modules[name]._clear_globals()
2129+
sys.modules.pop(name)._clear_globals()
21292130
_testinternalcapi.clear_extension(name, {self.FILE!r})
21302131
'''))
21312132
_interpreters.destroy(interpid)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Clear generators' exception state after ``return`` to break reference
2+
cycles.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove ``opcode.is_pseudo``, ``opcode.MIN_PSEUDO_OPCODE`` and ``opcode.MAX_PSEUDO_OPCODE``,
2+
which were added in 3.12, were never documented and were not intended to be used externally.

Objects/genobject.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ gen_dealloc(PyGenObject *gen)
149149
gen->gi_frame_state = FRAME_CLEARED;
150150
frame->previous = NULL;
151151
_PyFrame_ClearExceptCode(frame);
152+
_PyErr_ClearExcState(&gen->gi_exc_state);
152153
}
154+
assert(gen->gi_exc_state.exc_value == NULL);
153155
if (_PyGen_GetCode(gen)->co_flags & CO_COROUTINE) {
154156
Py_CLEAR(((PyCoroObject *)gen)->cr_origin_or_finalizer);
155157
}
156158
Py_DECREF(_PyGen_GetCode(gen));
157159
Py_CLEAR(gen->gi_name);
158160
Py_CLEAR(gen->gi_qualname);
159-
_PyErr_ClearExcState(&gen->gi_exc_state);
161+
160162
PyObject_GC_Del(gen);
161163
}
162164

@@ -252,10 +254,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
252254
!PyErr_ExceptionMatches(PyExc_StopAsyncIteration));
253255
}
254256

255-
/* generator can't be rerun, so release the frame */
256-
/* first clean reference cycle through stored exception traceback */
257-
_PyErr_ClearExcState(&gen->gi_exc_state);
258-
257+
assert(gen->gi_exc_state.exc_value == NULL);
259258
assert(gen->gi_frame_state == FRAME_CLEARED);
260259
*presult = result;
261260
return result ? PYGEN_RETURN : PYGEN_ERROR;

Python/ceval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
14661466
tstate->c_recursion_remaining--;
14671467
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
14681468
_PyFrame_ClearExceptCode(frame);
1469+
_PyErr_ClearExcState(&gen->gi_exc_state);
14691470
tstate->c_recursion_remaining++;
14701471
frame->previous = NULL;
14711472
}

Python/import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ _extensions_cache_delete(PyObject *filename, PyObject *name)
10731073
However, this decref would be problematic if the module def were
10741074
dynamically allocated, it were the last ref, and this function
10751075
were called with an interpreter other than the def's owner. */
1076+
assert(_Py_IsImmortal(entry->value));
10761077
entry->value = NULL;
10771078

10781079
finally:

Tools/build/generate_opcode_h.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ def main(opcode_py,
7272
opcode = get_python_module_dict(opcode_py)
7373
opmap = opcode['opmap']
7474
opname = opcode['opname']
75-
is_pseudo = opcode['is_pseudo']
7675

77-
MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"]
78-
MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"]
7976
MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"]
8077

8178
NUM_OPCODES = len(opname)
@@ -101,16 +98,11 @@ def main(opcode_py,
10198
for name in opname:
10299
if name in opmap:
103100
op = opmap[name]
104-
if op == MIN_PSEUDO_OPCODE:
105-
fobj.write(DEFINE.format("MIN_PSEUDO_OPCODE", MIN_PSEUDO_OPCODE))
106101
if op == MIN_INSTRUMENTED_OPCODE:
107102
fobj.write(DEFINE.format("MIN_INSTRUMENTED_OPCODE", MIN_INSTRUMENTED_OPCODE))
108103

109104
fobj.write(DEFINE.format(name, op))
110105

111-
if op == MAX_PSEUDO_OPCODE:
112-
fobj.write(DEFINE.format("MAX_PSEUDO_OPCODE", MAX_PSEUDO_OPCODE))
113-
114106

115107
for name, op in specialized_opmap.items():
116108
fobj.write(DEFINE.format(name, op))
@@ -126,7 +118,7 @@ def main(opcode_py,
126118

127119
deoptcodes = {}
128120
for basic, op in opmap.items():
129-
if not is_pseudo(op):
121+
if op < 256:
130122
deoptcodes[basic] = basic
131123
for basic, family in _opcode_metadata["_specializations"].items():
132124
for specialized in family:

0 commit comments

Comments
 (0)
0