Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 9328:81574e4646b4 legacy-trunk
Patches for mywrite() by Marc Lemburg: save/restore the error state
reliably; check return value of vsprintf().
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 12 Oct 1998 18:22:10 +0000 |
| parents | 44baef8ab5c8 |
| children | 9342c60eaac0 |
comparison
equal
deleted
inserted
replaced
| 9327:c91e4d87f694 | 9328:81574e4646b4 |
|---|---|
| 592 PySys_WriteStdout(format, ...) | 592 PySys_WriteStdout(format, ...) |
| 593 PySys_WriteStderr(format, ...) | 593 PySys_WriteStderr(format, ...) |
| 594 | 594 |
| 595 The first function writes to sys.stdout; the second to sys.stderr. When | 595 The first function writes to sys.stdout; the second to sys.stderr. When |
| 596 there is a problem, they write to the real (C level) stdout or stderr; | 596 there is a problem, they write to the real (C level) stdout or stderr; |
| 597 no exceptions are raised (but a pending exception may be cleared when a | 597 no exceptions are raised. |
| 598 new exception is caught). | |
| 599 | 598 |
| 600 Both take a printf-style format string as their first argument followed | 599 Both take a printf-style format string as their first argument followed |
| 601 by a variable length argument list determined by the format string. | 600 by a variable length argument list determined by the format string. |
| 602 | 601 |
| 603 *** WARNING *** | 602 *** WARNING *** |
| 617 FILE *fp; | 616 FILE *fp; |
| 618 const char *format; | 617 const char *format; |
| 619 va_list va; | 618 va_list va; |
| 620 { | 619 { |
| 621 PyObject *file; | 620 PyObject *file; |
| 622 | 621 PyObject *error_type, *error_value, *error_traceback; |
| 622 | |
| 623 PyErr_Fetch(&error_type, &error_value, &error_traceback); | |
| 623 file = PySys_GetObject(name); | 624 file = PySys_GetObject(name); |
| 624 if (file == NULL || PyFile_AsFile(file) == fp) | 625 if (file == NULL || PyFile_AsFile(file) == fp) |
| 625 vfprintf(fp, format, va); | 626 vfprintf(fp, format, va); |
| 626 else { | 627 else { |
| 627 char buffer[1001]; | 628 char buffer[1001]; |
| 628 vsprintf(buffer, format, va); | 629 if (vsprintf(buffer, format, va) >= sizeof(buffer)) |
| 630 Py_FatalError("PySys_WriteStdout/err: buffer overrun"); | |
| 629 if (PyFile_WriteString(buffer, file) != 0) { | 631 if (PyFile_WriteString(buffer, file) != 0) { |
| 630 PyErr_Clear(); | 632 PyErr_Clear(); |
| 631 fputs(buffer, fp); | 633 fputs(buffer, fp); |
| 632 } | 634 } |
| 633 } | 635 } |
| 636 PyErr_Restore(error_type, error_value, error_traceback); | |
| 634 } | 637 } |
| 635 | 638 |
| 636 void | 639 void |
| 637 #ifdef HAVE_STDARG_PROTOTYPES | 640 #ifdef HAVE_STDARG_PROTOTYPES |
| 638 PySys_WriteStdout(const char *format, ...) | 641 PySys_WriteStdout(const char *format, ...) |
