Skip to content

Commit 9b5e800

Browse files
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.
1 parent c3c8806 commit 9b5e800

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)