mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Patches for mywrite() by Marc Lemburg: save/restore the error state
reliably; check return value of vsprintf().
This commit is contained in:
parent
41f0a98f8f
commit
8442af35fe
1 changed files with 6 additions and 3 deletions
|
@ -594,8 +594,7 @@ PySys_SetArgv(argc, argv)
|
||||||
|
|
||||||
The first function writes to sys.stdout; the second to sys.stderr. When
|
The first function writes to sys.stdout; the second to sys.stderr. When
|
||||||
there is a problem, they write to the real (C level) stdout or stderr;
|
there is a problem, they write to the real (C level) stdout or stderr;
|
||||||
no exceptions are raised (but a pending exception may be cleared when a
|
no exceptions are raised.
|
||||||
new exception is caught).
|
|
||||||
|
|
||||||
Both take a printf-style format string as their first argument followed
|
Both take a printf-style format string as their first argument followed
|
||||||
by a variable length argument list determined by the format string.
|
by a variable length argument list determined by the format string.
|
||||||
|
@ -619,18 +618,22 @@ mywrite(name, fp, format, va)
|
||||||
va_list va;
|
va_list va;
|
||||||
{
|
{
|
||||||
PyObject *file;
|
PyObject *file;
|
||||||
|
PyObject *error_type, *error_value, *error_traceback;
|
||||||
|
|
||||||
|
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||||
file = PySys_GetObject(name);
|
file = PySys_GetObject(name);
|
||||||
if (file == NULL || PyFile_AsFile(file) == fp)
|
if (file == NULL || PyFile_AsFile(file) == fp)
|
||||||
vfprintf(fp, format, va);
|
vfprintf(fp, format, va);
|
||||||
else {
|
else {
|
||||||
char buffer[1001];
|
char buffer[1001];
|
||||||
vsprintf(buffer, format, va);
|
if (vsprintf(buffer, format, va) >= sizeof(buffer))
|
||||||
|
Py_FatalError("PySys_WriteStdout/err: buffer overrun");
|
||||||
if (PyFile_WriteString(buffer, file) != 0) {
|
if (PyFile_WriteString(buffer, file) != 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
fputs(buffer, fp);
|
fputs(buffer, fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PyErr_Restore(error_type, error_value, error_traceback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue