summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-01-27 18:58:30 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-01-27 18:58:30 (GMT)
commit486ff4bd92a2978dc6876545f555198149486e15 (patch)
treefd531f160a985169ec99943146e12edaa24ba9cd
parentad5a0f84823ea1a62c483a1cd77d08911db718e6 (diff)
downloadcpython-486ff4bd92a2978dc6876545f555198149486e15.zip
cpython-486ff4bd92a2978dc6876545f555198149486e15.tar.gz
cpython-486ff4bd92a2978dc6876545f555198149486e15.tar.bz2
Partially revert #1074011; don't try to fflush stdin.
-rw-r--r--Misc/NEWS2
-rw-r--r--Python/sysmodule.c11
2 files changed, 11 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 5120072..08d9057 100644
--- 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().
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 3045c46..dc46697 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, "<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())