diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2005-01-27 18:56:16 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2005-01-27 18:56:16 (GMT) |
commit | 13a1fde4da63c92fdb86b6bcf4d2d21928c80bc8 (patch) | |
tree | de4623a84142b573fb538248ca50b7d75d9c0f07 /Python/sysmodule.c | |
parent | bc029af436f90723e5b5bda4b9842d19153fe0a3 (diff) | |
download | cpython-13a1fde4da63c92fdb86b6bcf4d2d21928c80bc8.zip cpython-13a1fde4da63c92fdb86b6bcf4d2d21928c80bc8.tar.gz cpython-13a1fde4da63c92fdb86b6bcf4d2d21928c80bc8.tar.bz2 |
Partially revert #1074011; don't try to fflush stdin.
Backported to 2.3 and 2.4.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 11 |
1 files changed, 10 insertions, 1 deletions
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()) |