Skip to content

Commit 99872b1

Browse files
ericsnowcurrentlymiss-islington
authored andcommitted
pythongh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (pythongh-134758)
This is a small follow-up to pythongh-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 9b5e800) Co-authored-by: Eric Snow <[email protected]>
1 parent 00122c8 commit 99872b1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Python/crossinterp_data_lookup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,14 @@ _PyFunction_FromXIData(_PyXIData_t *xidata)
701701
Py_DECREF(code);
702702
return NULL;
703703
}
704+
PyThreadState *tstate = _PyThreadState_GET();
705+
if (PyDict_SetItem(globals, &_Py_ID(__builtins__),
706+
tstate->interp->builtins) < 0)
707+
{
708+
Py_DECREF(code);
709+
Py_DECREF(globals);
710+
return NULL;
711+
}
704712
PyObject *func = PyFunction_New(code, globals);
705713
Py_DECREF(code);
706714
Py_DECREF(globals);

0 commit comments

Comments
 (0)