mirror of https://github.com/python/cpython
gh-111789: Simplify ceval.c by using PyDict_GetItemRef() (GH-111980)
This commit is contained in:
parent
95365625f4
commit
16055c1604
|
@ -1592,14 +1592,14 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
|
|||
continue;
|
||||
PyObject *varname = PyTuple_GET_ITEM(co->co_localsplusnames, i);
|
||||
if (func->func_kwdefaults != NULL) {
|
||||
PyObject *def = PyDict_GetItemWithError(func->func_kwdefaults, varname);
|
||||
if (def) {
|
||||
localsplus[i] = Py_NewRef(def);
|
||||
continue;
|
||||
}
|
||||
else if (_PyErr_Occurred(tstate)) {
|
||||
PyObject *def;
|
||||
if (PyDict_GetItemRef(func->func_kwdefaults, varname, &def) < 0) {
|
||||
goto fail_post_args;
|
||||
}
|
||||
if (def) {
|
||||
localsplus[i] = def;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
missing++;
|
||||
}
|
||||
|
@ -2401,13 +2401,9 @@ PyEval_GetBuiltins(void)
|
|||
PyObject *
|
||||
_PyEval_GetBuiltin(PyObject *name)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
PyObject *attr = PyDict_GetItemWithError(PyEval_GetBuiltins(), name);
|
||||
if (attr) {
|
||||
Py_INCREF(attr);
|
||||
}
|
||||
else if (!_PyErr_Occurred(tstate)) {
|
||||
_PyErr_SetObject(tstate, PyExc_AttributeError, name);
|
||||
PyObject *attr;
|
||||
if (PyDict_GetItemRef(PyEval_GetBuiltins(), name, &attr) == 0) {
|
||||
PyErr_SetObject(PyExc_AttributeError, name);
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
@ -2558,12 +2554,12 @@ static PyObject *
|
|||
import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||
PyObject *name, PyObject *fromlist, PyObject *level)
|
||||
{
|
||||
PyObject *import_func = _PyDict_GetItemWithError(frame->f_builtins,
|
||||
&_Py_ID(__import__));
|
||||
PyObject *import_func;
|
||||
if (PyDict_GetItemRef(frame->f_builtins, &_Py_ID(__import__), &import_func) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (import_func == NULL) {
|
||||
if (!_PyErr_Occurred(tstate)) {
|
||||
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
|
||||
}
|
||||
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -2574,6 +2570,7 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
|||
|
||||
/* Fast path for not overloaded __import__. */
|
||||
if (_PyImport_IsDefaultImportFunc(tstate->interp, import_func)) {
|
||||
Py_DECREF(import_func);
|
||||
int ilevel = PyLong_AsInt(level);
|
||||
if (ilevel == -1 && _PyErr_Occurred(tstate)) {
|
||||
return NULL;
|
||||
|
@ -2587,7 +2584,6 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
|||
}
|
||||
|
||||
PyObject* args[5] = {name, frame->f_globals, locals, fromlist, level};
|
||||
Py_INCREF(import_func);
|
||||
PyObject *res = PyObject_Vectorcall(import_func, args, 5, NULL);
|
||||
Py_DECREF(import_func);
|
||||
return res;
|
||||
|
|
Loading…
Reference in New Issue