features/pep-446: f8a52518be4c (original) (raw)

Mercurial > features > pep-446

changeset 84891:f8a52518be4c

os.dup2() now behaves differently for fd < 3

Victor Stinner victor.stinner@gmail.com
date Mon, 29 Jul 2013 23:24:50 +0200
parents 00689f56b418
children 75e5d34898aa
files Doc/library/os.rst Lib/http/server.py Lib/pty.py Lib/test/test_os.py Modules/posixmodule.c
diffstat 5 files changed, 25 insertions(+), 9 deletions(-)[+] [-] Doc/library/os.rst 4 Lib/http/server.py 2 Lib/pty.py 3 Lib/test/test_os.py 17 Modules/posixmodule.c 8

line wrap: on

line diff

--- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -701,7 +701,9 @@ as internal buffering of data. .. function:: dup2(fd, fd2) Duplicate file descriptor fd to fd2, closing the latter first if necessary.

--- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -1132,9 +1132,7 @@ class CGIHTTPRequestHandler(SimpleHTTPRe except OSError: pass os.dup2(self.rfile.fileno(), 0)

--- a/Lib/pty.py +++ b/Lib/pty.py @@ -102,11 +102,8 @@ def fork(): # Slave becomes stdin/stdout/stderr of child. os.dup2(slave_fd, STDIN_FILENO)

--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -2326,6 +2326,23 @@ class FDInheritanceTests(unittest.TestCa finally: os.close(fd1)

+

+ @unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()") def test_openpty_inheritable(self): master_fd, slave_fd = os.openpty()

--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7463,6 +7463,7 @@ static PyObject * posix_dup2(PyObject *self, PyObject *args) { int fd, fd2, res;

#ifdef HAVE_DUP3 /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */ int dup3_works = -1; @@ -7472,9 +7473,10 @@ posix_dup2(PyObject *self, PyObject *arg return NULL; if (!_PyVerify_fd_dup2(fd, fd2)) return posix_error();

#ifdef HAVE_DUP3

@@ -7486,7 +7488,7 @@ posix_dup2(PyObject *self, PyObject *arg } }

#endif Py_BEGIN_ALLOW_THREADS @@ -7494,7 +7496,7 @@ posix_dup2(PyObject *self, PyObject *arg Py_END_ALLOW_THREADS if (res < 0) return posix_error();