Skip to content

Commit 1fe6cfe

Browse files
revert global var
1 parent 990b050 commit 1fe6cfe

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

Include/cpython/pystate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ struct _ts {
196196
int fileutils_ioctl_works;
197197
int fileutils_skiproot_initialized;
198198
int fileutils_combineex_initialized;
199-
int fileutils__Py_open_cloexec_works;
200199
};
201200

202201
#ifdef Py_DEBUG

Python/fileutils.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ extern int winerror_to_errno(int);
3737
# include <fcntl.h> // fcntl(F_GETFD)
3838
#endif
3939

40+
#ifdef O_CLOEXEC
41+
/* Does open() support the O_CLOEXEC flag? Possible values:
42+
-1: unknown
43+
0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23
44+
1: open() supports O_CLOEXEC flag, close-on-exec is set
45+
The flag is used by _Py_open(), _Py_open_noraise(), io.FileIO
46+
and os.open(). */
47+
int _Py_open_cloexec_works = -1;
48+
#endif
49+
4050
// The value must be the same in unicodeobject.c.
4151
#define MAX_UNICODE 0x10ffff
4252

@@ -1614,16 +1624,7 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
16141624
#ifdef MS_WINDOWS
16151625
flags |= O_NOINHERIT;
16161626
#elif defined(O_CLOEXEC)
1617-
PyThreadState *tstate = PyThreadState_Get();
1618-
/* Does open() support the O_CLOEXEC flag? Possible values:
1619-
1620-
-1: unknown
1621-
0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23
1622-
1: open() supports O_CLOEXEC flag, close-on-exec is set
1623-
1624-
The flag is used by _Py_open(), _Py_open_noraise(), io.FileIO
1625-
and os.open(). */
1626-
atomic_flag_works = &tstate->fileutils__Py_open_cloexec_works;
1627+
atomic_flag_works = &_Py_open_cloexec_works;
16271628
flags |= O_CLOEXEC;
16281629
#else
16291630
atomic_flag_works = NULL;

Tools/c-analyzer/TODO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Objects/bytesobject.c:_Py_onel_strings Py_ssize_t _Py_
3636
Objects/dictobject.c:empty_keys_struct static PyDictKeysObject empty_keys_struct
3737

3838

39+
# "initialized"
40+
Python/fileutils.c:_Py_open_cloexec_works int _Py_open_cloexec_works
41+
42+
3943
# other non-object (40)
4044
Modules/_tracemalloc.c:allocators static struct { PyMemAllocatorEx mem; PyMemAllocatorEx raw; PyMemAllocatorEx obj; } allocators
4145
Modules/_tracemalloc.c:tables_lock static PyThread_type_lock tables_lock

0 commit comments

Comments
 (0)