FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-100227: Port dup3_works to the module state variable. by corona10 · Pull Request #100262 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) .tsv  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Port dup3_works of :mod:`posix` module to the module state variable. Patch
by Dong-hee Na.
28 changes: 18 additions & 10 deletions Modules/posixmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ typedef struct {
PyObject *struct_rusage;
#endif
PyObject *st_mode;
int dup3_works;
} _posixstate;


Expand Down Expand Up @@ -9407,11 +9408,6 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
/*[clinic end generated code: output=bc059d34a73404d1 input=c3cddda8922b038d]*/
{
int res = 0;
#if defined(HAVE_DUP3) && \
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
static int dup3_works = -1;
#endif

if (fd < 0 || fd2 < 0) {
posix_error();
Expand Down Expand Up @@ -9455,21 +9451,23 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
#else

#ifdef HAVE_DUP3
if (!inheritable && dup3_works != 0) {
_posixstate *state = get_posix_state(module);
if (!inheritable && state->dup3_works != 0) {
Py_BEGIN_ALLOW_THREADS
res = dup3(fd, fd2, O_CLOEXEC);
Py_END_ALLOW_THREADS
if (res < 0) {
if (dup3_works == -1)
dup3_works = (errno != ENOSYS);
if (dup3_works) {
if (state->dup3_works == -1) {
state->dup3_works = (errno != ENOSYS);
}
if (state->dup3_works) {
posix_error();
return -1;
}
}
}

if (inheritable || dup3_works == 0)
if (inheritable || state->dup3_works == 0)
{
#endif
Py_BEGIN_ALLOW_THREADS
Expand Down Expand Up @@ -15872,6 +15870,16 @@ posixmodule_exec(PyObject *m)
{
_posixstate *state = get_posix_state(m);

#if defined(HAVE_DUP3) && \
!(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
/* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
state->dup3_works = -1;
#elif !defined(HAVE_DUP3)
state->dup3_works = -1;
#else
state->dup3_works = 0;
#endif

#if defined(HAVE_PWRITEV)
if (HAVE_PWRITEV_RUNTIME) {} else {
PyObject* dct = PyModule_GetDict(m);
Expand Down
3 changes: 0 additions & 3 deletions Tools/c-analyzer/cpython/ignored.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ filename funcname name reason
Python/bootstrap_hash.c py_getrandom getrandom_works -
Python/fileutils.c - _Py_open_cloexec_works -
Python/fileutils.c set_inheritable ioctl_works -
# (set lazily, *after* first init)
# XXX Is this thread-safe?
Modules/posixmodule.c os_dup2_impl dup3_works -

## guards around resource init
Python/thread_pthread.h PyThread__init_thread lib_initialized -
Expand Down

Back | FazBrowse Home | New Git URL