diff options
| author | Thomas Wouters <thomas@python.org> | 2007-01-23 15:09:19 (GMT) |
|---|---|---|
| committer | Thomas Wouters <thomas@python.org> | 2007-01-23 15:09:19 (GMT) |
| commit | 1e42ab6e434044fdfcdc99b5b631ed972825a92c (patch) | |
| tree | aac6ac06981e283a12b2308d278a97dfb5edc110 /Python/sysmodule.c | |
| parent | 741e0bb5f46588ad71d3ac940a430e46e8d77df1 (diff) | |
| download | cpython-1e42ab6e434044fdfcdc99b5b631ed972825a92c.zip cpython-1e42ab6e434044fdfcdc99b5b631ed972825a92c.tar.gz cpython-1e42ab6e434044fdfcdc99b5b631ed972825a92c.tar.bz2 | |
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/sysmodule.c')
| -rw-r--r-- | Python/sysmodule.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 0883178..d2229a6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -972,12 +972,12 @@ _PySys_Init(void) if (PyErr_Occurred()) return NULL; #ifdef MS_WINDOWS - if(isatty(_fileno(stdin))){ + if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) { sprintf(buf, "cp%d", GetConsoleCP()); if (!PyFile_SetEncoding(sysin, buf)) return NULL; } - if(isatty(_fileno(stdout))) { + if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) { sprintf(buf, "cp%d", GetConsoleOutputCP()); if (!PyFile_SetEncoding(sysout, buf)) return NULL; |
