summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-01-23 09:41:49 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-01-23 09:41:49 (GMT)
commit8e3ca8af2641a47a83f02135a77193b0b80c545e (patch)
treeefdc5c38d772e0873b0c4315d7ed2647263cf0ab /Python
parentc300175547ced0af17857a29462b0f9294e8c31c (diff)
downloadcpython-8e3ca8af2641a47a83f02135a77193b0b80c545e.zip
cpython-8e3ca8af2641a47a83f02135a77193b0b80c545e.tar.gz
cpython-8e3ca8af2641a47a83f02135a77193b0b80c545e.tar.bz2
Flush std{in,out,err} before closing it. Fixes #1074011.
Will backport to 2.4 and 2.3.
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index d246a59..3045c46 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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