diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-23 12:04:53 +0000 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-23 12:04:53 +0000 |
commit | 32366b45e89e52d96dd3fdd8241846ff29d57fae (patch) | |
tree | a2621af9b9818d2cc9be912a2a823d62be644df9 /Python | |
parent | Merged revisions 80402 via svnmerge from (diff) | |
download | cpython-32366b45e89e52d96dd3fdd8241846ff29d57fae.tar.gz cpython-32366b45e89e52d96dd3fdd8241846ff29d57fae.tar.bz2 cpython-32366b45e89e52d96dd3fdd8241846ff29d57fae.zip |
Merged revisions 80404 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r80404 | victor.stinner | 2010-04-23 14:02:30 +0200 (ven., 23 avril 2010) | 4 lines
Issue #8124: PySys_WriteStdout() and PySys_WriteStderr() don't execute
indirectly Python signal handlers anymore because mywrite() ignores exceptions
(KeyboardInterrupt).
........
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c87fd824554..69ee9c1fe89 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1655,6 +1655,45 @@ PySys_SetArgv(int argc, wchar_t **argv) Py_DECREF(av); } +/* Reimplementation of PyFile_WriteString() no calling indirectly + PyErr_CheckSignals(): avoid the call to PyObject_Str(). */ + +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(unicode); + Py_XDECREF(writer); + Py_XDECREF(args); + 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. @@ -1666,6 +1705,10 @@ PySys_SetArgv(int argc, wchar_t **argv) there is a problem, they write to the real (C level) stdout or stderr; no exceptions are raised. + PyErr_CheckSignals() is not called to avoid the execution of the Python + signal handlers: they may raise a new exception whereas mywrite() ignores + all exceptions. + Both take a printf-style format string as their first argument followed by a variable length argument list determined by the format string. @@ -1691,13 +1734,13 @@ mywrite(char *name, FILE *fp, const char *format, va_list va) 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); } |