summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 05b7dfa..0e118b0 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -413,10 +413,11 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit,
PyObject *dict = PyModule_GetDict(main_module); // borrowed ref
int set_file_name = 0;
- if (_PyDict_GetItemStringWithError(dict, "__file__") == NULL) {
- if (PyErr_Occurred()) {
- goto done;
- }
+ int has_file = PyDict_ContainsString(dict, "__file__");
+ if (has_file < 0) {
+ goto done;
+ }
+ if (!has_file) {
if (PyDict_SetItemString(dict, "__file__", filename) < 0) {
goto done;
}
@@ -1713,13 +1714,17 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py
_PyRuntime.signals.unhandled_keyboard_interrupt = 0;
/* Set globals['__builtins__'] if it doesn't exist */
- if (globals != NULL && _PyDict_GetItemStringWithError(globals, "__builtins__") == NULL) {
- if (PyErr_Occurred() ||
- PyDict_SetItemString(globals, "__builtins__",
- tstate->interp->builtins) < 0)
- {
+ if (globals != NULL) {
+ int has_builtins = PyDict_ContainsString(globals, "__builtins__");
+ if (has_builtins < 0) {
return NULL;
}
+ if (!has_builtins) {
+ if (PyDict_SetItemString(globals, "__builtins__",
+ tstate->interp->builtins) < 0) {
+ return NULL;
+ }
+ }
}
v = PyEval_EvalCode((PyObject*)co, globals, locals);