diff Python/sysmodule.c @ 34483:4a1fefdfc793 2.4

Flush std{in,out,err} before closing it. Fixes #1074011.
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 23 Jan 2005 09:50:14 +0000
parents f455bbe7ea7e
children 91038801eb45
line wrap: on
line diff
--- a/Python/sysmodule.c	Thu Jan 20 19:25:24 2005 +0000
+++ b/Python/sysmodule.c	Sun Jan 23 09:50:14 2005 +0000
@@ -927,6 +927,13 @@
 )
 /* 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 @@
 	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