Skip to content

Commit 5e01840

Browse files
committed
Fix SUBSCR_LIST_INT/STORE_SUBSCR_LIST_INT asserting on wide ints
_GUARD_TOS_INT only checks PyLong_CheckExact, so wide (non-compact) ints can reach _BINARY_OP_SUBSCR_LIST_INT and _STORE_SUBSCR_LIST_INT, both of which call _PyLong_CompactValue unconditionally. The specializer correctly gates on _PyLong_IsNonNegativeCompact, but the runtime guard did not enforce that invariant. Add EXIT_IF / DEOPT_IF(!_PyLong_IsNonNegativeCompact) before each _PyLong_CompactValue call so wide-int indices fall back to the slow path instead of hitting the assertion. The bug was latent before this branch because BINARY_OP_ADD_INT would deopt on wide-int operands, so wide results rarely appeared as list subscripts that had already been specialised for compact ints.
1 parent d608803 commit 5e01840

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

Modules/_testinternalcapi/test_cases.c.h

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

Python/bytecodes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ dummy_func(
11351135

11361136
assert(PyLong_CheckExact(sub));
11371137
assert(PyList_CheckExact(list));
1138+
EXIT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
11381139

11391140
Py_ssize_t index = _PyLong_CompactValue((PyLongObject *)sub);
11401141
if (index < 0) {
@@ -1413,6 +1414,7 @@ dummy_func(
14131414

14141415
assert(PyLong_CheckExact(sub));
14151416
assert(PyList_CheckExact(list));
1417+
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
14161418

14171419
Py_ssize_t index = _PyLong_CompactValue((PyLongObject *)sub);
14181420
DEOPT_IF(!LOCK_OBJECT(list));

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)