https://github.com/python/cpython/commit/6493395f4b69c561db14fdb5c10a819fda52138d
commit: 6493395f4b69c561db14fdb5c10a819fda52138d
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: ericsnowcurrently <ericsnowcurren...@gmail.com>
date: 2025-05-27T16:07:44Z
summary:

[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 <ericsnowcurren...@gmail.com>

files:
M Python/crossinterp_data_lookup.h

diff --git a/Python/crossinterp_data_lookup.h b/Python/crossinterp_data_lookup.h
index 88eb41da89ee40..b16f38b847fc66 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);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to