Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 40701:da30a26dfeb3 2.5
Backport trunk revision 53527:
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
When running the interpreter in an environment that would cause it to set
stdout/stderr/stdin's encoding, having a sitecustomize that would replace
them with something other than PyFile objects would crash the interpreter.
Fix it by simply ignoring the encoding-setting for non-files.
This could do with a test, but I can think of no maintainable and portable
way to test this bug, short of adding a sitecustomize.py to the buildsystem
and have it always run with it (hmmm....)
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Tue, 23 Jan 2007 13:54:30 +0000 |
| parents | 783c5e2803f9 |
| children | 1080de49c81e |
comparison
equal
deleted
inserted
replaced
| 40697:29b8b65bae3f | 40701:da30a26dfeb3 |
|---|---|
| 273 if (codeset) { | 273 if (codeset) { |
| 274 sys_stream = PySys_GetObject("stdin"); | 274 sys_stream = PySys_GetObject("stdin"); |
| 275 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | 275 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
| 276 if (!sys_isatty) | 276 if (!sys_isatty) |
| 277 PyErr_Clear(); | 277 PyErr_Clear(); |
| 278 if(sys_isatty && PyObject_IsTrue(sys_isatty)) { | 278 if(sys_isatty && PyObject_IsTrue(sys_isatty) && |
| 279 PyFile_Check(sys_stream)) { | |
| 279 if (!PyFile_SetEncoding(sys_stream, codeset)) | 280 if (!PyFile_SetEncoding(sys_stream, codeset)) |
| 280 Py_FatalError("Cannot set codeset of stdin"); | 281 Py_FatalError("Cannot set codeset of stdin"); |
| 281 } | 282 } |
| 282 Py_XDECREF(sys_isatty); | 283 Py_XDECREF(sys_isatty); |
| 283 | 284 |
| 284 sys_stream = PySys_GetObject("stdout"); | 285 sys_stream = PySys_GetObject("stdout"); |
| 285 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | 286 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
| 286 if (!sys_isatty) | 287 if (!sys_isatty) |
| 287 PyErr_Clear(); | 288 PyErr_Clear(); |
| 288 if(sys_isatty && PyObject_IsTrue(sys_isatty)) { | 289 if(sys_isatty && PyObject_IsTrue(sys_isatty) && |
| 290 PyFile_Check(sys_stream)) { | |
| 289 if (!PyFile_SetEncoding(sys_stream, codeset)) | 291 if (!PyFile_SetEncoding(sys_stream, codeset)) |
| 290 Py_FatalError("Cannot set codeset of stdout"); | 292 Py_FatalError("Cannot set codeset of stdout"); |
| 291 } | 293 } |
| 292 Py_XDECREF(sys_isatty); | 294 Py_XDECREF(sys_isatty); |
| 293 | 295 |
| 294 sys_stream = PySys_GetObject("stderr"); | 296 sys_stream = PySys_GetObject("stderr"); |
| 295 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | 297 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
| 296 if (!sys_isatty) | 298 if (!sys_isatty) |
| 297 PyErr_Clear(); | 299 PyErr_Clear(); |
| 298 if(sys_isatty && PyObject_IsTrue(sys_isatty)) { | 300 if(sys_isatty && PyObject_IsTrue(sys_isatty) && |
| 301 PyFile_Check(sys_stream)) { | |
| 299 if (!PyFile_SetEncoding(sys_stream, codeset)) | 302 if (!PyFile_SetEncoding(sys_stream, codeset)) |
| 300 Py_FatalError("Cannot set codeset of stderr"); | 303 Py_FatalError("Cannot set codeset of stderr"); |
| 301 } | 304 } |
| 302 Py_XDECREF(sys_isatty); | 305 Py_XDECREF(sys_isatty); |
| 303 | 306 |
