From: Martin v. Löwis Date: Thu, 27 Jan 2005 18:56:16 +0000 (+0000) Subject: Partially revert #1074011; don't try to fflush stdin. X-Git-Tag: v2.5a0~2075 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13a1fde4da63c92fdb86b6bcf4d2d21928c80bc8;p=python Partially revert #1074011; don't try to fflush stdin. Backported to 2.3 and 2.4. --- diff --git a/Misc/NEWS b/Misc/NEWS index c72723abc5..1d919aa50b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,7 +10,7 @@ What's New in Python 2.5 alpha 1? Core and builtins ----------------- -- Bug #1074011: closing sys.std{in,out,err} now causes a flush() and +- Bug #1074011: closing sys.std{out,err} now causes a flush() and an ferror() call. - min() and max() now support key= arguments with the same meaning as in diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 3045c46206..dc46697ee3 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -947,7 +947,16 @@ _PySys_Init(void) m = Py_InitModule3("sys", sys_methods, sys_doc); sysdict = PyModule_GetDict(m); - sysin = PyFile_FromFile(stdin, "", "r", _check_and_flush); + /* Closing the standard FILE* if sys.std* goes aways causes problems + * for embedded Python usages. Closing them when somebody explicitly + * invokes .close() might be possible, but the FAQ promises they get + * never closed. However, we still need to get write errors when + * writing fails (e.g. because stdout is redirected), so we flush the + * streams and check for errors before the file objects are deleted. + * On OS X, fflush()ing stdin causes an error, so we exempt stdin + * from that procedure. + */ + sysin = PyFile_FromFile(stdin, "", "r", NULL); sysout = PyFile_FromFile(stdout, "", "w", _check_and_flush); syserr = PyFile_FromFile(stderr, "", "w", _check_and_flush); if (PyErr_Occurred())