mirror of
https://github.com/python/cpython.git
synced 2025-07-13 06:15:17 +00:00
gh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (gh-134758)
This is a small follow-up to gh-133481. There's a corner case in the behavior of PyImport_ImportModuleAttrString(), where it expects __builtins__ to be set if __globals__ is set.
This commit is contained in:
parent
c3c88064f5
commit
9b5e80000e
1 changed files with 8 additions and 0 deletions
|
@ -701,6 +701,14 @@ _PyFunction_FromXIData(_PyXIData_t *xidata)
|
|||
Py_DECREF(code);
|
||||
return NULL;
|
||||
}
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
if (PyDict_SetItem(globals, &_Py_ID(__builtins__),
|
||||
tstate->interp->builtins) < 0)
|
||||
{
|
||||
Py_DECREF(code);
|
||||
Py_DECREF(globals);
|
||||
return NULL;
|
||||
}
|
||||
PyObject *func = PyFunction_New(code, globals);
|
||||
Py_DECREF(code);
|
||||
Py_DECREF(globals);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue