If we have a filename and __main__.__file__ hasn't already been set,
set it. Closes SF issue #624729.
This commit is contained in:
parent
5134a54df9
commit
8ed0204bc9
|
@ -675,6 +675,16 @@ PyRun_SimpleFileExFlags(FILE *fp, char *filename, int closeit,
|
|||
if (m == NULL)
|
||||
return -1;
|
||||
d = PyModule_GetDict(m);
|
||||
if (PyDict_GetItemString(d, "__file__") == NULL) {
|
||||
PyObject *f = PyString_FromString(filename);
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
if (PyDict_SetItemString(d, "__file__", f) < 0) {
|
||||
Py_DECREF(f);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(f);
|
||||
}
|
||||
ext = filename + strlen(filename) - 4;
|
||||
if (maybe_pyc_file(fp, filename, ext, closeit)) {
|
||||
/* Try to run a pyc file. First, re-open in binary */
|
||||
|
|
Loading…
Reference in New Issue