Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 43569:19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Changes to make __file__ a proper Unicode object, using the default
filesystem encoding.
This is a bit tricky because the default filesystem encoding isn't
set by the time we import the first modules; at that point we fudge
things a bit. This is okay since __file__ isn't really used much
except for error reporting.
Tested on OSX and Linux only so far.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 15 Oct 2007 02:52:41 +0000 |
| parents | b9d19d51de36 |
| children | a2bb76d11d66 |
comparison
equal
deleted
inserted
replaced
| 43568:90294d80a3c5 | 43569:19319e70fc3e |
|---|---|
| 865 m = PyImport_AddModule("__main__"); | 865 m = PyImport_AddModule("__main__"); |
| 866 if (m == NULL) | 866 if (m == NULL) |
| 867 return -1; | 867 return -1; |
| 868 d = PyModule_GetDict(m); | 868 d = PyModule_GetDict(m); |
| 869 if (PyDict_GetItemString(d, "__file__") == NULL) { | 869 if (PyDict_GetItemString(d, "__file__") == NULL) { |
| 870 PyObject *f = PyString_FromString(filename); | 870 PyObject *f; |
| 871 f = PyUnicode_DecodeFSDefault(filename); | |
| 871 if (f == NULL) | 872 if (f == NULL) |
| 872 return -1; | 873 return -1; |
| 873 if (PyDict_SetItemString(d, "__file__", f) < 0) { | 874 if (PyDict_SetItemString(d, "__file__", f) < 0) { |
| 874 Py_DECREF(f); | 875 Py_DECREF(f); |
| 875 return -1; | 876 return -1; |
