]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Flush std{in,out,err} before closing it. Fixes #1074011.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 23 Jan 2005 09:50:14 +0000 (09:50 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 23 Jan 2005 09:50:14 +0000 (09:50 +0000)
Misc/NEWS
Python/sysmodule.c

index 873076d77f3705d61048bf48b17989b55d7a6994..512007269b9a99405d42e6c03c0cac97f3e3f175 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4.1?
 Core and builtins
 -----------------
 
+- Bug #1074011: closing sys.std{in,out,err} now causes a flush() and 
+  an ferror() call.
+
 - Bug #1085744:  Add missing overflow check to PySequence_Tuple().
   Make resize schedule linear (amortized).
 
index d246a5998ffa9df22887cf445929ecbdcf5430c6..3045c46206d435766cfc7659796969fad2a5b080 100644 (file)
@@ -927,6 +927,13 @@ settrace() -- set the global debug tracing function\n\
 )
 /* end of sys_doc */ ;
 
+static int
+_check_and_flush (FILE *stream)
+{
+  int prev_fail = ferror (stream);
+  return fflush (stream) || prev_fail ? EOF : 0;
+}
+
 PyObject *
 _PySys_Init(void)
 {
@@ -940,9 +947,9 @@ _PySys_Init(void)
        m = Py_InitModule3("sys", sys_methods, sys_doc);
        sysdict = PyModule_GetDict(m);
 
-       sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
-       sysout = PyFile_FromFile(stdout, "<stdout>", "w", NULL);
-       syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL);
+       sysin = PyFile_FromFile(stdin, "<stdin>", "r", _check_and_flush);
+       sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
+       syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
        if (PyErr_Occurred())
                return NULL;
 #ifdef MS_WINDOWS