Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 25827:093fe5b9f6f9 legacy-trunk
If we have a filename and __main__.__file__ hasn't already been set,
set it.
Closes SF issue #624729.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Thu, 17 Oct 2002 21:24:58 +0000 |
| parents | 0231cc54f87e |
| children | 244e8fbe4e20 |
line wrap: on
line diff
--- a/Python/pythonrun.c Thu Oct 17 20:37:50 2002 +0000 +++ b/Python/pythonrun.c Thu Oct 17 21:24:58 2002 +0000 @@ -675,12 +675,22 @@ 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 */ if (closeit) fclose(fp); - if( (fp = fopen(filename, "rb")) == NULL ) { + if ((fp = fopen(filename, "rb")) == NULL) { fprintf(stderr, "python: Can't reopen .pyc file\n"); return -1; }
