Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 40702:6860ba88d67e 2.4
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 15:09:19 +0000 |
| parents | e65836815791 |
| children |
comparison
equal
deleted
inserted
replaced
| 40603:e18af28b49da | 40702:6860ba88d67e |
|---|---|
| 255 if (codeset) { | 255 if (codeset) { |
| 256 sys_stream = PySys_GetObject("stdin"); | 256 sys_stream = PySys_GetObject("stdin"); |
| 257 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | 257 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
| 258 if (!sys_isatty) | 258 if (!sys_isatty) |
| 259 PyErr_Clear(); | 259 PyErr_Clear(); |
| 260 if(sys_isatty && PyObject_IsTrue(sys_isatty)) { | 260 if(sys_isatty && PyObject_IsTrue(sys_isatty) && |
| 261 PyFile_Check(sys_stream)) { | |
| 261 if (!PyFile_SetEncoding(sys_stream, codeset)) | 262 if (!PyFile_SetEncoding(sys_stream, codeset)) |
| 262 Py_FatalError("Cannot set codeset of stdin"); | 263 Py_FatalError("Cannot set codeset of stdin"); |
| 263 } | 264 } |
| 264 Py_XDECREF(sys_isatty); | 265 Py_XDECREF(sys_isatty); |
| 265 | 266 |
| 266 sys_stream = PySys_GetObject("stdout"); | 267 sys_stream = PySys_GetObject("stdout"); |
| 267 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); | 268 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
| 268 if (!sys_isatty) | 269 if (!sys_isatty) |
| 269 PyErr_Clear(); | 270 PyErr_Clear(); |
| 270 if(sys_isatty && PyObject_IsTrue(sys_isatty)) { | 271 if(sys_isatty && PyObject_IsTrue(sys_isatty) && |
| 272 PyFile_Check(sys_stream)) { | |
| 271 if (!PyFile_SetEncoding(sys_stream, codeset)) | 273 if (!PyFile_SetEncoding(sys_stream, codeset)) |
| 272 Py_FatalError("Cannot set codeset of stdout"); | 274 Py_FatalError("Cannot set codeset of stdout"); |
| 273 } | 275 } |
| 274 Py_XDECREF(sys_isatty); | 276 Py_XDECREF(sys_isatty); |
| 275 | 277 |
