]> granicus.if.org Git - python/commitdiff
closes bpo-32859: Don't retry dup3() if it is not available at runtime (GH-5708)
authorAlexey Izbyshev <izbyshev@users.noreply.github.com>
Tue, 20 Feb 2018 07:25:46 +0000 (10:25 +0300)
committerBenjamin Peterson <benjamin@python.org>
Tue, 20 Feb 2018 07:25:46 +0000 (23:25 -0800)
os.dup2() tests for dup3() system call availability at runtime,
but doesn't remember the result across calls, repeating
the test on each call with inheritable=False.

Since the caller of os.dup2() is expected to hold the GIL,
fix this by making the variable holding the test result static.

Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst [new file with mode: 0644]
Modules/posixmodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst b/Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst
new file mode 100644 (file)
index 0000000..755bdc1
--- /dev/null
@@ -0,0 +1,2 @@
+In ``os.dup2``, don't check every call whether the ``dup3`` syscall exists
+or not.
index d242df0b6f3106d8fffb417c4572c4988b59de8b..0bbf7c57961f0ec4f30dedaf59de639bf46279de 100644 (file)
@@ -8016,7 +8016,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
 #if defined(HAVE_DUP3) && \
     !(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
     /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
-    int dup3_works = -1;
+    static int dup3_works = -1;
 #endif
 
     if (fd < 0 || fd2 < 0) {