Skip to content

gh-117657: Move static variables in fileutils.c to thread state #120559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "revert global var"
This reverts commit 1fe6cfe.
  • Loading branch information
Fidget-Spinner committed Jun 15, 2024
commit 65007019c58ed8bcb69de170b3b913d973657f63
1 change: 1 addition & 0 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct _ts {
int fileutils_ioctl_works;
int fileutils_skiproot_initialized;
int fileutils_combineex_initialized;
int fileutils__Py_open_cloexec_works;
};

#ifdef Py_DEBUG
Expand Down
21 changes: 10 additions & 11 deletions Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ extern int winerror_to_errno(int);
# include <fcntl.h> // fcntl(F_GETFD)
#endif

#ifdef O_CLOEXEC
/* Does open() support the O_CLOEXEC flag? Possible values:
-1: unknown
0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23
1: open() supports O_CLOEXEC flag, close-on-exec is set
The flag is used by _Py_open(), _Py_open_noraise(), io.FileIO
and os.open(). */
int _Py_open_cloexec_works = -1;
#endif

// The value must be the same in unicodeobject.c.
#define MAX_UNICODE 0x10ffff

Expand Down Expand Up @@ -1624,7 +1614,16 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
#ifdef MS_WINDOWS
flags |= O_NOINHERIT;
#elif defined(O_CLOEXEC)
atomic_flag_works = &_Py_open_cloexec_works;
PyThreadState *tstate = PyThreadState_Get();
/* Does open() support the O_CLOEXEC flag? Possible values:

-1: unknown
0: open() ignores O_CLOEXEC flag, ex: Linux kernel older than 2.6.23
1: open() supports O_CLOEXEC flag, close-on-exec is set

The flag is used by _Py_open(), _Py_open_noraise(), io.FileIO
and os.open(). */
atomic_flag_works = &tstate->fileutils__Py_open_cloexec_works;
flags |= O_CLOEXEC;
#else
atomic_flag_works = NULL;
Expand Down
4 changes: 0 additions & 4 deletions Tools/c-analyzer/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ Objects/bytesobject.c:_Py_onel_strings Py_ssize_t _Py_
Objects/dictobject.c:empty_keys_struct static PyDictKeysObject empty_keys_struct


# "initialized"
Python/fileutils.c:_Py_open_cloexec_works int _Py_open_cloexec_works


# other non-object (40)
Modules/_tracemalloc.c:allocators static struct { PyMemAllocatorEx mem; PyMemAllocatorEx raw; PyMemAllocatorEx obj; } allocators
Modules/_tracemalloc.c:tables_lock static PyThread_type_lock tables_lock
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy