diff options
author | Thomas Wouters <thomas@python.org> | 2007-01-23 13:54:30 +0000 |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2007-01-23 13:54:30 +0000 |
commit | e471317a084512d558fd3bfd84592a6a7126cdee (patch) | |
tree | 976e72558989488d7101ff57976a27335e4c79f7 /Python/pythonrun.c | |
parent | 1e4bb440488e7b982c62fe117cd5409402818d02 (diff) | |
download | cpython-git-e471317a084512d558fd3bfd84592a6a7126cdee.tar.gz |
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....)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index e8f4fa2e56..e83c4cb423 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -275,7 +275,8 @@ Py_InitializeEx(int install_sigs) sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); if (!sys_isatty) PyErr_Clear(); - if(sys_isatty && PyObject_IsTrue(sys_isatty)) { + if(sys_isatty && PyObject_IsTrue(sys_isatty) && + PyFile_Check(sys_stream)) { if (!PyFile_SetEncoding(sys_stream, codeset)) Py_FatalError("Cannot set codeset of stdin"); } @@ -285,7 +286,8 @@ Py_InitializeEx(int install_sigs) sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); if (!sys_isatty) PyErr_Clear(); - if(sys_isatty && PyObject_IsTrue(sys_isatty)) { + if(sys_isatty && PyObject_IsTrue(sys_isatty) && + PyFile_Check(sys_stream)) { if (!PyFile_SetEncoding(sys_stream, codeset)) Py_FatalError("Cannot set codeset of stdout"); } @@ -295,7 +297,8 @@ Py_InitializeEx(int install_sigs) sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); if (!sys_isatty) PyErr_Clear(); - if(sys_isatty && PyObject_IsTrue(sys_isatty)) { + if(sys_isatty && PyObject_IsTrue(sys_isatty) && + PyFile_Check(sys_stream)) { if (!PyFile_SetEncoding(sys_stream, codeset)) Py_FatalError("Cannot set codeset of stderr"); } |