Skip to content

Commit 16de2a9

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 76c3f5e commit 16de2a9

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
@@ -7704,7 +7704,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
77047704
#if defined(HAVE_DUP3) && \
77057705
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
77067706
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
7707-
int dup3_works = -1;
7707+
static int dup3_works = -1;
77087708
#endif
77097709

77107710
if (fd < 0 || fd2 < 0)

0 commit comments

Comments
 (0)