del a[0:10]
self.assertEqual(a.delitem, (slice(0, 10)))
+ def test_load_attr_extended_arg(self):
+ # https://github.com/python/cpython/issues/91625
+ class Numbers:
+ def __getattr__(self, attr):
+ return int(attr.lstrip("_"))
+ attrs = ", ".join(f"Z._{n:03d}" for n in range(280))
+ code = f"def number_attrs(Z):\n return [ {attrs} ]"
+ ns = {}
+ exec(code, ns)
+ number_attrs = ns["number_attrs"]
+ # Warm up the the function for quickening (PEP 659)
+ for _ in range(30):
+ self.assertEqual(number_attrs(Numbers()), list(range(280)))
+
def test_methods(self):
# Testing methods...
class C(object):
raise RuntimeError(f"Premature access to sys.stdout.{attr}")
with redirect_stdout(StdoutGuard()):
- with self.assertRaises(RuntimeError):
- print("Oops!")
+ with self.assertRaises(RuntimeError):
+ print("Oops!")
def test_vicious_descriptor_nonsense(self):
# Testing vicious_descriptor_nonsense...
self.assertEqual(foo(), 7)
+ def test_load_global_specialization_failure_keeps_oparg(self):
+ # https://github.com/python/cpython/issues/91625
+ class MyGlobals(dict):
+ def __missing__(self, key):
+ return int(key.removeprefix("_number_"))
+
+ code = "lambda: " + "+".join(f"_number_{i}" for i in range(1000))
+ sum_1000 = eval(code, MyGlobals())
+ expected = sum(range(1000))
+ # Warm up the the function for quickening (PEP 659)
+ for _ in range(30):
+ self.assertEqual(sum_1000(), expected)
if __name__ == "__main__":
unittest.main()
return tests
+class TestCornerCases(unittest.TestCase):
+ def test_extended_oparg_not_ignored(self):
+ # https://github.com/python/cpython/issues/91625
+ target = "(" + "y,"*400 + ")"
+ code = f"""def unpack_400(x):
+ {target} = x
+ return y
+ """
+ ns = {}
+ exec(code, ns)
+ unpack_400 = ns["unpack_400"]
+ # Warm up the the function for quickening (PEP 659)
+ for _ in range(30):
+ y = unpack_400(range(400))
+ self.assertEqual(y, 399)
+
if __name__ == "__main__":
unittest.main()
DISPATCH_GOTO(); \
}
+#define NOTRACE_DISPATCH_SAME_OPARG() \
+ { \
+ opcode = _Py_OPCODE(*next_instr); \
+ PRE_DISPATCH_GOTO(); \
+ DISPATCH_GOTO(); \
+ }
+
#define CHECK_EVAL_BREAKER() \
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
if (_Py_atomic_load_relaxed(eval_breaker)) { \
if (_Py_Specialize_BinarySubscr(container, sub, next_instr) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(BINARY_SUBSCR, deferred);
if (_Py_Specialize_StoreSubscr(container, sub, next_instr) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(STORE_SUBSCR, deferred);
PyObject *seq = TOP();
next_instr--;
_Py_Specialize_UnpackSequence(seq, next_instr, oparg);
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(UNPACK_SEQUENCE, deferred);
if (_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(LOAD_GLOBAL, deferred);
if (_Py_Specialize_LoadAttr(owner, next_instr, name) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(LOAD_ATTR, deferred);
if (_Py_Specialize_StoreAttr(owner, next_instr, name) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(STORE_ATTR, deferred);
PyObject *left = SECOND();
next_instr--;
_Py_Specialize_CompareOp(left, right, next_instr, oparg);
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(COMPARE_OP, deferred);
if (_Py_Specialize_LoadMethod(owner, next_instr, name) < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(LOAD_METHOD, deferred);
if (err < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(PRECALL, deferred);
if (err < 0) {
goto error;
}
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(CALL, deferred);
PyObject *rhs = TOP();
next_instr--;
_Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, &GETLOCAL(0));
- DISPATCH();
+ NOTRACE_DISPATCH_SAME_OPARG();
}
else {
STAT_INC(BINARY_OP, deferred);
TARGET(EXTENDED_ARG) {
assert(oparg);
- int oldoparg = oparg;
- NEXTOPARG();
- oparg |= oldoparg << 8;
- PRE_DISPATCH_GOTO();
- DISPATCH_GOTO();
+ oparg <<= 8;
+ oparg |= _Py_OPARG(*next_instr);
+ NOTRACE_DISPATCH_SAME_OPARG();
}
TARGET(CACHE) {