mirror of
https://github.com/python/cpython.git
synced 2025-07-27 05:04:15 +00:00
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
This commit is contained in:
parent
7c4d7d3e17
commit
c49dfcc8dc
3 changed files with 30 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue