Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 42071:825041fc8e2c
Rip out the file object's implementation.
Fixed test_import.py while I was at it.
However, there's still a problem in import.c -- get_file() can leak a
FILE struct (not a file descriptor though). I'm not sure how to fix
this; closing the FILE* closes the file descriptor, and that's the
wrong thing to do when there's still a Python file object keeping the
file descriptor open. I also would rather not mess with dup(), as it
won't port to Windows.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 12 Jun 2007 23:30:11 +0000 |
| parents | cd125fe83051 |
| children | 29ba6c399090 |
comparison
equal
deleted
inserted
replaced
| 42068:45bb97a4e8b6 | 42071:825041fc8e2c |
|---|---|
| 153 PyObject *bimod, *sysmod; | 153 PyObject *bimod, *sysmod; |
| 154 char *p; | 154 char *p; |
| 155 #if defined(HAVE_LANGINFO_H) && defined(CODESET) | 155 #if defined(HAVE_LANGINFO_H) && defined(CODESET) |
| 156 char *codeset; | 156 char *codeset; |
| 157 char *saved_locale; | 157 char *saved_locale; |
| 158 PyObject *sys_stream, *sys_isatty; | |
| 159 #endif | 158 #endif |
| 160 extern void _Py_ReadyTypes(void); | 159 extern void _Py_ReadyTypes(void); |
| 161 | 160 |
| 162 if (initialized) | 161 if (initialized) |
| 163 return; | 162 return; |
| 271 codeset = NULL; | 270 codeset = NULL; |
| 272 setlocale(LC_CTYPE, saved_locale); | 271 setlocale(LC_CTYPE, saved_locale); |
| 273 free(saved_locale); | 272 free(saved_locale); |
| 274 | 273 |
| 275 if (codeset) { | 274 if (codeset) { |
| 276 sys_stream = PySys_GetObject("stdin"); | |
| 277 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | |
| 278 if (!sys_isatty) | |
| 279 PyErr_Clear(); | |
| 280 if(sys_isatty && PyObject_IsTrue(sys_isatty) && | |
| 281 PyFile_Check(sys_stream)) { | |
| 282 if (!PyFile_SetEncoding(sys_stream, codeset)) | |
| 283 Py_FatalError("Cannot set codeset of stdin"); | |
| 284 } | |
| 285 Py_XDECREF(sys_isatty); | |
| 286 | |
| 287 sys_stream = PySys_GetObject("stdout"); | |
| 288 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | |
| 289 if (!sys_isatty) | |
| 290 PyErr_Clear(); | |
| 291 if(sys_isatty && PyObject_IsTrue(sys_isatty) && | |
| 292 PyFile_Check(sys_stream)) { | |
| 293 if (!PyFile_SetEncoding(sys_stream, codeset)) | |
| 294 Py_FatalError("Cannot set codeset of stdout"); | |
| 295 } | |
| 296 Py_XDECREF(sys_isatty); | |
| 297 | |
| 298 sys_stream = PySys_GetObject("stderr"); | |
| 299 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | |
| 300 if (!sys_isatty) | |
| 301 PyErr_Clear(); | |
| 302 if(sys_isatty && PyObject_IsTrue(sys_isatty) && | |
| 303 PyFile_Check(sys_stream)) { | |
| 304 if (!PyFile_SetEncoding(sys_stream, codeset)) | |
| 305 Py_FatalError("Cannot set codeset of stderr"); | |
| 306 } | |
| 307 Py_XDECREF(sys_isatty); | |
| 308 | |
| 309 if (!Py_FileSystemDefaultEncoding) | 275 if (!Py_FileSystemDefaultEncoding) |
| 310 Py_FileSystemDefaultEncoding = codeset; | 276 Py_FileSystemDefaultEncoding = codeset; |
| 311 else | 277 else |
| 312 free(codeset); | 278 free(codeset); |
| 313 } | 279 } |
