Skip to content

Commit bab4fe3

Browse files
miss-islingtonizbyshev
authored andcommitted
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 b3caf38) Co-authored-by: Alexey Izbyshev <[email protected]>
1 parent a3d6c1b commit bab4fe3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In ``os.dup2``, don't check every call whether the ``dup3`` syscall exists
2+
or not.

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8016,7 +8016,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
80168016
#if defined(HAVE_DUP3) && \
80178017
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
80188018
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
8019-
int dup3_works = -1;
8019+
static int dup3_works = -1;
80208020
#endif
80218021

80228022
if (fd < 0 || fd2 < 0) {

0 commit comments

Comments
 (0)