Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (révision 80345) +++ Python/sysmodule.c (copie de travail) @@ -1763,7 +1763,47 @@ Py_DECREF(av); } +/* Implementation of PyFile_WriteString() no calling PyErr_CheckSignals(): + * mywrite() should not execute any Python signal handler to avoid raising an + * error because mywrite() ignores all errors */ +static int +sys_pyfile_write(const char *text, PyObject *file) +{ + PyObject *unicode = NULL, *writer = NULL, *args = NULL, *result = NULL; + int err; + + unicode = PyUnicode_FromString(text); + if (unicode == NULL) + goto error; + + writer = PyObject_GetAttrString(file, "write"); + if (writer == NULL) + goto error; + + args = PyTuple_Pack(1, unicode); + if (args == NULL) + goto error; + + result = PyEval_CallObject(writer, args); + if (result == NULL) { + goto error; + } else { + err = 0; + goto finally; + } + +error: + err = -1; +finally: + Py_XDECREF(args); + Py_XDECREF(unicode); + Py_XDECREF(writer); + Py_XDECREF(result); + return err; +} + + /* APIs to write to sys.stdout or sys.stderr using a printf-like interface. Adapted from code submitted by Just van Rossum. @@ -1799,13 +1839,13 @@ PyErr_Fetch(&error_type, &error_value, &error_traceback); file = PySys_GetObject(name); written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va); - if (PyFile_WriteString(buffer, file) != 0) { + if (sys_pyfile_write(buffer, file) != 0) { PyErr_Clear(); fputs(buffer, fp); } if (written < 0 || (size_t)written >= sizeof(buffer)) { const char *truncated = "... truncated"; - if (PyFile_WriteString(truncated, file) != 0) { + if (sys_pyfile_write(truncated, file) != 0) { PyErr_Clear(); fputs(truncated, fp); }