diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-25 22:30:32 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-25 22:30:32 (GMT) |
commit | c49dfcc8dcf5aec3151f7a76fd860ce0247f9bf9 (patch) | |
tree | 0a895906ec8058f18419b4a5cd19d7747d8f6280 /Python | |
parent | 7c4d7d3e17cc683f1094cc8c33fd7435008f4ada (diff) | |
download | cpython-c49dfcc8dcf5aec3151f7a76fd860ce0247f9bf9.zip cpython-c49dfcc8dcf5aec3151f7a76fd860ce0247f9bf9.tar.gz cpython-c49dfcc8dcf5aec3151f7a76fd860ce0247f9bf9.tar.bz2 |
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
error handler, instead of writing to the C stderr file in utf-8
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index f203618..db5d0a7 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1106,7 +1106,13 @@ handle_system_exit(void) if (PyInt_Check(value)) exitcode = (int)PyInt_AsLong(value); else { - PyObject_Print(value, stderr, Py_PRINT_RAW); + PyObject *sys_stderr = PySys_GetObject("stderr"); + if (sys_stderr != NULL && sys_stderr != Py_None) { + PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); + } else { + PyObject_Print(value, stderr, Py_PRINT_RAW); + fflush(stderr); + } PySys_WriteStderr("\n"); exitcode = 1; } |