[Python-checkins] closes bpo-32859: Don't retry dup3() if it is not available at runtime (GH-5708)
Benjamin Peterson
webhook-mailer at python.org
Wed Feb 21 00:21:16 EST 2018
https://github.com/python/cpython/commit/16de2a9b8697cf90840eb217fb079f9c4c73e588
commit: 16de2a9b8697cf90840eb217fb079f9c4c73e588
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2018-02-20T21:21:12-08:00
summary:
closes bpo-32859: Don't retry dup3() if it is not available at runtime (GH-5708)
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.
(cherry picked from commit b3caf388a0418f6c031e4dbdcc0c1ce7e5cc36bd)
Co-authored-by: Alexey Izbyshev <izbyshev at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2018-02-19-17-46-31.bpo-32859.kAT-Xp.rst
M 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
index 000000000000..755bdc118610
--- /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.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 85ec255fcb4f..885c2674e336 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7704,7 +7704,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)
More information about the Python-checkins
mailing list