]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Partially revert #1074011; don't try to fflush stdin.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 27 Jan 2005 18:58:30 +0000 (18:58 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 27 Jan 2005 18:58:30 +0000 (18:58 +0000)
Misc/NEWS
Python/sysmodule.c

index 512007269b9a99405d42e6c03c0cac97f3e3f175..08d90573243902431bf3c41b1ee80ee362b47331 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,7 +12,7 @@ What's New in Python 2.4.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.
 
 - Bug #1085744:  Add missing overflow check to PySequence_Tuple().
index 3045c46206d435766cfc7659796969fad2a5b080..dc46697ee362ede3034ecf9f7d4f0e967cd922e3 100644 (file)
@@ -947,7 +947,16 @@ _PySys_Init(void)
        m = Py_InitModule3("sys", sys_methods, sys_doc);
        sysdict = PyModule_GetDict(m);
 
-       sysin = PyFile_FromFile(stdin, "<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, "<stdin>", "r", NULL);
        sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
        syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
        if (PyErr_Occurred())