Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.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 | ab13576374b1 |
| children |
comparison
equal
deleted
inserted
replaced
| 40603:e18af28b49da | 40702:6860ba88d67e |
|---|---|
| 970 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); | 970 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); |
| 971 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); | 971 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); |
| 972 if (PyErr_Occurred()) | 972 if (PyErr_Occurred()) |
| 973 return NULL; | 973 return NULL; |
| 974 #ifdef MS_WINDOWS | 974 #ifdef MS_WINDOWS |
| 975 if(isatty(_fileno(stdin))){ | 975 if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) { |
| 976 sprintf(buf, "cp%d", GetConsoleCP()); | 976 sprintf(buf, "cp%d", GetConsoleCP()); |
| 977 if (!PyFile_SetEncoding(sysin, buf)) | 977 if (!PyFile_SetEncoding(sysin, buf)) |
| 978 return NULL; | 978 return NULL; |
| 979 } | 979 } |
| 980 if(isatty(_fileno(stdout))) { | 980 if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) { |
| 981 sprintf(buf, "cp%d", GetConsoleOutputCP()); | 981 sprintf(buf, "cp%d", GetConsoleOutputCP()); |
| 982 if (!PyFile_SetEncoding(sysout, buf)) | 982 if (!PyFile_SetEncoding(sysout, buf)) |
| 983 return NULL; | 983 return NULL; |
| 984 } | 984 } |
| 985 #endif | 985 #endif |
