diff Python/pythonrun.c @ 61920:bd5f5df7ed78 legacy-trunk

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
author Victor Stinner <victor.stinner@haypocalc.com>
date Tue, 25 May 2010 22:30:32 +0000
parents fd25030223b0
children 55397533da51
line wrap: on
line diff
--- a/Python/pythonrun.c	Tue May 25 20:06:02 2010 +0000
+++ b/Python/pythonrun.c	Tue May 25 22:30:32 2010 +0000
@@ -1106,7 +1106,13 @@
     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;
     }