Skip to content

Commit 1a5356b

Browse files
committed
Fix test crashes by fiddling DECREF order in BINARY_SUBSCR_DICT
1 parent 14e75f1 commit 1a5356b

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,17 @@ dummy_func(
421421
DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR);
422422
STAT_INC(BINARY_SUBSCR, hit);
423423
res = PyDict_GetItemWithError(dict, sub);
424-
Py_DECREF(dict);
425424
if (res == NULL) {
426425
if (!_PyErr_Occurred(tstate)) {
427426
_PyErr_SetKeyError(sub);
428427
}
429-
else {
430-
Py_DECREF(sub);
431-
}
428+
Py_DECREF(dict);
429+
Py_DECREF(sub);
432430
ERROR_IF(1, error);
433431
}
432+
Py_INCREF(res); // Do this before DECREF'ing dict, sub
433+
Py_DECREF(dict);
434434
Py_DECREF(sub);
435-
Py_INCREF(res);
436435
}
437436

438437
inst(BINARY_SUBSCR_GETITEM, (container, sub, unused/1, type_version/2, func_version/1 -- unused)) {

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)