From: Eric Snow Date: Tue, 27 May 2025 15:42:24 +0000 (-0600) Subject: gh-132775: Always Set __builtins__ In _PyFunction_FromXIData() (gh-134758) X-Git-Tag: v3.15.0a1~1489 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b5e80000ee179eb028841709f10dac9af7c36e7;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Python/crossinterp_data_lookup.h b/Python/crossinterp_data_lookup.h index 88eb41da89ee..b16f38b847fc 100644 --- a/Python/crossinterp_data_lookup.h +++ b/Python/crossinterp_data_lookup.h @@ -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);