From fc6a2e14d5d89f8aa1c06617a17c94f6a26d2d5d Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Sat, 17 Feb 2018 01:11:41 +0300 Subject: [PATCH 1/2] bpo-32859: Don't retry dup3() if it is not available at runtime 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. --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d242df0b6f3106d..0bbf7c57961f0ec 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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) { From 7c978b782abe4eeb48cb8933e1599877fabc06ad Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 19 Feb 2018 17:46:40 -0800 Subject: [PATCH 2/2] add news --- .../next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst 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 index 000000000000000..755bdc118610108 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst @@ -0,0 +1,2 @@ +In ``os.dup2``, don't check every call whether the ``dup3`` syscall exists +or not.