mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
gh-121459: Deferred LOAD_GLOBAL (GH-123128)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Sam Gross <655866+colesbury@users.noreply.github.com>
This commit is contained in:
parent
74330d992b
commit
8810e286fa
8 changed files with 108 additions and 29 deletions
|
@ -3110,15 +3110,14 @@ _PyEval_GetANext(PyObject *aiter)
|
|||
return awaitable;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name)
|
||||
void
|
||||
_PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name, _PyStackRef *writeto)
|
||||
{
|
||||
PyObject *res;
|
||||
if (PyDict_CheckExact(globals) && PyDict_CheckExact(builtins)) {
|
||||
res = _PyDict_LoadGlobal((PyDictObject *)globals,
|
||||
_PyDict_LoadGlobalStackRef((PyDictObject *)globals,
|
||||
(PyDictObject *)builtins,
|
||||
name);
|
||||
if (res == NULL && !PyErr_Occurred()) {
|
||||
name, writeto);
|
||||
if (PyStackRef_IsNull(*writeto) && !PyErr_Occurred()) {
|
||||
/* _PyDict_LoadGlobal() returns NULL without raising
|
||||
* an exception if the key doesn't exist */
|
||||
_PyEval_FormatExcCheckArg(PyThreadState_GET(), PyExc_NameError,
|
||||
|
@ -3128,13 +3127,16 @@ _PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name)
|
|||
else {
|
||||
/* Slow-path if globals or builtins is not a dict */
|
||||
/* namespace 1: globals */
|
||||
PyObject *res;
|
||||
if (PyMapping_GetOptionalItem(globals, name, &res) < 0) {
|
||||
return NULL;
|
||||
*writeto = PyStackRef_NULL;
|
||||
return;
|
||||
}
|
||||
if (res == NULL) {
|
||||
/* namespace 2: builtins */
|
||||
if (PyMapping_GetOptionalItem(builtins, name, &res) < 0) {
|
||||
return NULL;
|
||||
*writeto = PyStackRef_NULL;
|
||||
return;
|
||||
}
|
||||
if (res == NULL) {
|
||||
_PyEval_FormatExcCheckArg(
|
||||
|
@ -3142,8 +3144,8 @@ _PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name)
|
|||
NAME_ERROR_MSG, name);
|
||||
}
|
||||
}
|
||||
*writeto = PyStackRef_FromPyObjectSteal(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue