Skip to content

Commit 8b1d1f8

Browse files
Move dup3_works to _PyRuntimeState.
1 parent f829f34 commit 8b1d1f8

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Include/internal/pycore_os.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@ extern "C" {
99
#endif
1010

1111

12+
#if defined(HAVE_DUP3) && \
13+
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
14+
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
15+
# define dup3_works_STATE \
16+
int dup3_works;
17+
# define dup3_works_INIT \
18+
.dup3_works = -1,
19+
#else
20+
# define dup3_works_STATE
21+
# define dup3_works_INIT
22+
#endif
23+
24+
1225
struct _os_runtime_state {
1326
int _not_used;
27+
dup3_works_STATE
1428
};
15-
16-
#define _OS_RUNTIME_INIT {0}
29+
# define _OS_RUNTIME_INIT \
30+
{ \
31+
._not_used = 0, \
32+
dup3_works_INIT \
33+
}
1734

1835

1936
#ifdef __cplusplus

Modules/posixmodule.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9395,11 +9395,6 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
93959395
/*[clinic end generated code: output=bc059d34a73404d1 input=c3cddda8922b038d]*/
93969396
{
93979397
int res = 0;
9398-
#if defined(HAVE_DUP3) && \
9399-
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
9400-
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
9401-
static int dup3_works = -1;
9402-
#endif
94039398

94049399
if (fd < 0 || fd2 < 0) {
94059400
posix_error();
@@ -9443,6 +9438,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
94439438
#else
94449439

94459440
#ifdef HAVE_DUP3
9441+
#define dup3_works _PyRuntime.os.dup3_works
94469442
if (!inheritable && dup3_works != 0) {
94479443
Py_BEGIN_ALLOW_THREADS
94489444
res = dup3(fd, fd2, O_CLOEXEC);
@@ -9459,6 +9455,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
94599455

94609456
if (inheritable || dup3_works == 0)
94619457
{
9458+
#undef dup3_works
94629459
#endif
94639460
Py_BEGIN_ALLOW_THREADS
94649461
res = dup2(fd, fd2);

Tools/c-analyzer/cpython/globals-to-fix.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ Modules/faulthandler.c - old_stack -
399399
# initialized once
400400

401401
Modules/_io/bufferedio.c _PyIO_trap_eintr eintr_int -
402-
Modules/posixmodule.c os_dup2_impl dup3_works -
403402
Modules/posixmodule.c - structseq_new -
404403
Modules/posixmodule.c - ticks_per_second -
405404
Modules/timemodule.c _PyTime_GetClockWithInfo initialized -

0 commit comments

Comments
 (0)