mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
gh-109118: Fix runtime crash when NameError happens in PEP 695 function (#109123)
This commit is contained in:
parent
e9e2ca7a7b
commit
17f994174d
7 changed files with 203 additions and 120 deletions
|
@ -1286,7 +1286,7 @@ dummy_func(
|
|||
}
|
||||
}
|
||||
|
||||
op(_LOAD_LOCALS, ( -- locals)) {
|
||||
inst(LOAD_LOCALS, ( -- locals)) {
|
||||
locals = LOCALS();
|
||||
if (locals == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||
|
@ -1296,15 +1296,45 @@ dummy_func(
|
|||
Py_INCREF(locals);
|
||||
}
|
||||
|
||||
macro(LOAD_LOCALS) = _LOAD_LOCALS;
|
||||
|
||||
op(_LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
|
||||
inst(LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
|
||||
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (v == NULL) {
|
||||
v = PyDict_GetItemWithError(GLOBALS(), name);
|
||||
if (v != NULL) {
|
||||
Py_INCREF(v);
|
||||
}
|
||||
else if (_PyErr_Occurred(tstate)) {
|
||||
goto error;
|
||||
}
|
||||
else {
|
||||
if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (v == NULL) {
|
||||
_PyEval_FormatExcCheckArg(
|
||||
tstate, PyExc_NameError,
|
||||
NAME_ERROR_MSG, name);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
DECREF_INPUTS();
|
||||
}
|
||||
|
||||
inst(LOAD_NAME, (-- v)) {
|
||||
PyObject *mod_or_class_dict = LOCALS();
|
||||
if (mod_or_class_dict == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||
"no locals found");
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
|
||||
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
|
||||
Py_DECREF(mod_or_class_dict);
|
||||
goto error;
|
||||
}
|
||||
Py_DECREF(mod_or_class_dict);
|
||||
if (v == NULL) {
|
||||
v = PyDict_GetItemWithError(GLOBALS(), name);
|
||||
if (v != NULL) {
|
||||
|
@ -1327,10 +1357,6 @@ dummy_func(
|
|||
}
|
||||
}
|
||||
|
||||
macro(LOAD_NAME) = _LOAD_LOCALS + _LOAD_FROM_DICT_OR_GLOBALS;
|
||||
|
||||
macro(LOAD_FROM_DICT_OR_GLOBALS) = _LOAD_FROM_DICT_OR_GLOBALS;
|
||||
|
||||
family(LOAD_GLOBAL, INLINE_CACHE_ENTRIES_LOAD_GLOBAL) = {
|
||||
LOAD_GLOBAL_MODULE,
|
||||
LOAD_GLOBAL_BUILTIN,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue