[Python-checkins] python/dist/src/Python sysmodule.c, 2.120.6.1, 2.120.6.2

loewis at users.sourceforge.net loewis at users.sourceforge.net
Sun Jan 23 10:50:48 CET 2005


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26642/Python

Modified Files:
      Tag: release23-maint
	sysmodule.c 
Log Message:
Flush std{in,out,err} before closing it. Fixes #1074011.


Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.120.6.1
retrieving revision 2.120.6.2
diff -u -d -r2.120.6.1 -r2.120.6.2
--- sysmodule.c	9 Aug 2003 09:48:29 -0000	2.120.6.1
+++ sysmodule.c	23 Jan 2005 09:50:32 -0000	2.120.6.2
@@ -896,6 +896,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)
 {
@@ -909,9 +916,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



More information about the Python-checkins mailing list