Skip to content

Commit

Permalink
closes bpo-32859: Don't retry dup3() if it is not available at runtime (
Browse files Browse the repository at this point in the history
pythonGH-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.
  • Loading branch information
izbyshev authored and benjaminp committed Feb 20, 2018
1 parent 6240917 commit b3caf38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In ``os.dup2``, don't check every call whether the ``dup3`` syscall exists
or not.
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b3caf38

Please sign in to comment.