summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-16 17:38:16 +0200
committerGitHub <noreply@github.com>2019-05-16 17:38:16 +0200
commit9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9 (patch)
tree56b9b45660cc83960c2752e22ee47090632ebb09 /Python/pythonrun.c
parentae239f6b0626e926613a4a1dbafa323bd41fec32 (diff)
downloadcpython-git-9ef5dcaa0b3c7c7ba28dbb3ec0c9507d9d05e3a9.tar.gz
bpo-36763: Add _Py_InitializeMain() (GH-13362)
* Add a private _Py_InitializeMain() function. * Add again _PyCoreConfig._init_main. * _Py_InitializeFromConfig() now uses _init_main to decide if _Py_InitializeMainInterpreter() should be called. * _PyCoreConfig: rename _frozen to pathconfig_warnings, its value is now the opposite of Py_FrozenFlag. * Add an unit test for _init_main=0 and _Py_InitializeMain().
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 3d83044af9..bc131fd7e5 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1046,6 +1046,15 @@ run_eval_code_obj(PyCodeObject *co, PyObject *globals, PyObject *locals)
* Py_Main() based one.
*/
_Py_UnhandledKeyboardInterrupt = 0;
+
+ /* Set globals['__builtins__'] if it doesn't exist */
+ if (globals != NULL && PyDict_GetItemString(globals, "__builtins__") == NULL) {
+ PyInterpreterState *interp = _PyInterpreterState_Get();
+ if (PyDict_SetItemString(globals, "__builtins__", interp->builtins) < 0) {
+ return NULL;
+ }
+ }
+
v = PyEval_EvalCode((PyObject*)co, globals, locals);
if (!v && PyErr_Occurred() == PyExc_KeyboardInterrupt) {
_Py_UnhandledKeyboardInterrupt = 1;