diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2005-01-23 09:50:32 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2005-01-23 09:50:32 (GMT) |
commit | 03bdf1719cfec90837588833c88733a6d5df3d10 (patch) | |
tree | 556c899aebfd22b830b7c88921bd16b7d1176055 /Python/sysmodule.c | |
parent | 87b99c7f0e194349e0f30b4d6facb3f3a311ba7e (diff) | |
download | cpython-03bdf1719cfec90837588833c88733a6d5df3d10.zip cpython-03bdf1719cfec90837588833c88733a6d5df3d10.tar.gz cpython-03bdf1719cfec90837588833c88733a6d5df3d10.tar.bz2 |
Flush std{in,out,err} before closing it. Fixes #1074011.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c98e9f1..ed1dd9e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -896,6 +896,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) { @@ -909,9 +916,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 |