mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-111654: remove redundant decref in LOAD_FROM_DICT_OR_DEREF (#111655)
This commit is contained in:
parent
93206d19a3
commit
3a1b09e6d0
5 changed files with 12 additions and 6 deletions
|
@ -1844,6 +1844,13 @@ class NameErrorTests(unittest.TestCase):
|
||||||
self.assertIn("nonsense", err.getvalue())
|
self.assertIn("nonsense", err.getvalue())
|
||||||
self.assertIn("ZeroDivisionError", err.getvalue())
|
self.assertIn("ZeroDivisionError", err.getvalue())
|
||||||
|
|
||||||
|
def test_gh_111654(self):
|
||||||
|
def f():
|
||||||
|
class TestClass:
|
||||||
|
TestClass
|
||||||
|
|
||||||
|
self.assertRaises(NameError, f)
|
||||||
|
|
||||||
# Note: name suggestion tests live in `test_traceback`.
|
# Note: name suggestion tests live in `test_traceback`.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix runtime crash when some error happens in opcode
|
||||||
|
``LOAD_FROM_DICT_OR_DEREF``.
|
|
@ -1535,10 +1535,8 @@ dummy_func(
|
||||||
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
||||||
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
||||||
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
||||||
Py_DECREF(class_dict);
|
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(class_dict);
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
PyObject *cell = GETLOCAL(oparg);
|
PyObject *cell = GETLOCAL(oparg);
|
||||||
value = PyCell_GET(cell);
|
value = PyCell_GET(cell);
|
||||||
|
@ -1548,6 +1546,7 @@ dummy_func(
|
||||||
}
|
}
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(class_dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
inst(LOAD_DEREF, ( -- value)) {
|
inst(LOAD_DEREF, ( -- value)) {
|
||||||
|
|
3
Python/executor_cases.c.h
generated
3
Python/executor_cases.c.h
generated
|
@ -1241,10 +1241,8 @@
|
||||||
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
||||||
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
||||||
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
||||||
Py_DECREF(class_dict);
|
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(class_dict);
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
PyObject *cell = GETLOCAL(oparg);
|
PyObject *cell = GETLOCAL(oparg);
|
||||||
value = PyCell_GET(cell);
|
value = PyCell_GET(cell);
|
||||||
|
@ -1254,6 +1252,7 @@
|
||||||
}
|
}
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(class_dict);
|
||||||
stack_pointer[-1] = value;
|
stack_pointer[-1] = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
3
Python/generated_cases.c.h
generated
3
Python/generated_cases.c.h
generated
|
@ -2204,10 +2204,8 @@
|
||||||
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
|
||||||
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg);
|
||||||
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
if (PyMapping_GetOptionalItem(class_dict, name, &value) < 0) {
|
||||||
Py_DECREF(class_dict);
|
|
||||||
GOTO_ERROR(error);
|
GOTO_ERROR(error);
|
||||||
}
|
}
|
||||||
Py_DECREF(class_dict);
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
PyObject *cell = GETLOCAL(oparg);
|
PyObject *cell = GETLOCAL(oparg);
|
||||||
value = PyCell_GET(cell);
|
value = PyCell_GET(cell);
|
||||||
|
@ -2217,6 +2215,7 @@
|
||||||
}
|
}
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(class_dict);
|
||||||
stack_pointer[-1] = value;
|
stack_pointer[-1] = value;
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue