mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.14] gh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (gh-134794)
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.
(cherry picked from commit 9b5e80000
, AKA gh-134758)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
parent
a1b6252c88
commit
6493395f4b
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