gh-112716: Fix SystemError when __builtins__ is not a dict (GH-112770)
It was raised in two cases: * in the import statement when looking up __import__ * in pickling some builtin type when looking up built-ins iter, getattr, etc.
This commit is contained in:
@@ -2417,7 +2417,7 @@ PyObject *
|
||||
_PyEval_GetBuiltin(PyObject *name)
|
||||
{
|
||||
PyObject *attr;
|
||||
if (PyDict_GetItemRef(PyEval_GetBuiltins(), name, &attr) == 0) {
|
||||
if (PyMapping_GetOptionalItem(PyEval_GetBuiltins(), name, &attr) == 0) {
|
||||
PyErr_SetObject(PyExc_AttributeError, name);
|
||||
}
|
||||
return attr;
|
||||
@@ -2570,7 +2570,7 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||
PyObject *name, PyObject *fromlist, PyObject *level)
|
||||
{
|
||||
PyObject *import_func;
|
||||
if (PyDict_GetItemRef(frame->f_builtins, &_Py_ID(__import__), &import_func) < 0) {
|
||||
if (PyMapping_GetOptionalItem(frame->f_builtins, &_Py_ID(__import__), &import_func) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (import_func == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user