[3.13] gh-119821: Support non-dict globals in LOAD_FROM_DICT_OR_GLOBALS (#119822) (#119889)

dSupport non-dict globals in LOAD_FROM_DICT_OR_GLOBALS

The implementation basically copies LOAD_GLOBAL. Possibly it could be deduplicated,
but that seems like it may get hairy since the two operations have different operands.

This is important to fix in 3.14 for PEP 649, but it's a bug in earlier versions too,
and we should backport to 3.13 and 3.12 if possible.

(cherry picked from commit 80a4e38994)
This commit is contained in:
Jelle Zijlstra 2024-05-31 21:56:26 -07:00 committed by GitHub
parent 0a266f7e74
commit a0559849ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 76 additions and 59 deletions

View file

@ -1394,35 +1394,7 @@
break;
}
case _LOAD_FROM_DICT_OR_GLOBALS: {
PyObject *mod_or_class_dict;
PyObject *v;
oparg = CURRENT_OPARG();
mod_or_class_dict = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
JUMP_TO_ERROR();
}
if (v == NULL) {
if (PyDict_GetItemRef(GLOBALS(), name, &v) < 0) {
JUMP_TO_ERROR();
}
if (v == NULL) {
if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
JUMP_TO_ERROR();
}
if (v == NULL) {
_PyEval_FormatExcCheckArg(
tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
JUMP_TO_ERROR();
}
}
}
Py_DECREF(mod_or_class_dict);
stack_pointer[-1] = v;
break;
}
/* _LOAD_FROM_DICT_OR_GLOBALS is not a viable micro-op for tier 2 because it has both popping and not-popping errors */
/* _LOAD_NAME is not a viable micro-op for tier 2 because it has both popping and not-popping errors */