[Python-checkins] python/dist/src/Python pythonrun.c,2.167,2.168
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Thu, 17 Oct 2002 14:25:01 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv22540
Modified Files:
pythonrun.c
Log Message:
If we have a filename and __main__.__file__ hasn't already been set,
set it.
Closes SF issue #624729.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.167
retrieving revision 2.168
diff -C2 -d -r2.167 -r2.168
*** pythonrun.c 5 Oct 2002 01:47:34 -0000 2.167
--- pythonrun.c 17 Oct 2002 21:24:58 -0000 2.168
***************
*** 676,679 ****
--- 676,689 ----
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)) {
***************
*** 681,685 ****
if (closeit)
fclose(fp);
! if( (fp = fopen(filename, "rb")) == NULL ) {
fprintf(stderr, "python: Can't reopen .pyc file\n");
return -1;
--- 691,695 ----
if (closeit)
fclose(fp);
! if ((fp = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "python: Can't reopen .pyc file\n");
return -1;