mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
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:
parent
12f0bbd6e0
commit
1161c14e8c
3 changed files with 30 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue