8000 use a fresh `timeval` variable for select(2) portability · python/cpython@2996937 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2996937

Browse files
committed
use a fresh timeval variable for select(2) portability
1 parent 8d270f2 commit 2996937

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Modules/timemodule.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,15 +2407,23 @@ pysleep(PyTime_t timeout)
24072407
static int
24082408
pysleep_zero_posix(void)
24092409
{
2410-
static struct timeval zero = {0, 0};
2411-
24122410
PyTime_t deadline, monotonic;
24132411
if (PyTime_Monotonic(&monotonic) < 0) {
24142412
return -1;
24152413
}
24162414
deadline = monotonic;
24172415
do {
24182416
int ret, err;
2417+
// POSIX-compliant select(2) allows the 'timeout' parameter to
2418+
// be modified but also mandates that the function should return
2419+
// immediately if *both* structure's fields are zero (which is
2420+
// the case here).
2421+
//
2422+
// However, since System V (but not BSD) variant typically sets
2423+
// the timeout before returning (but does not specify whether
2424+
// this is also the case for zero timeouts), we prefer supplying
2425+
// a fresh timeout everytime.
2426+
struct timeval zero = {0, 0};
24192427
Py_BEGIN_ALLOW_THREADS
24202428
ret = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &zero);
24212429
err = errno;

Tools/c-analyzer/cpython/ignored.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ Modules/pyexpat.c - error_info_of -
313313
Modules/pyexpat.c - handler_info -
314314
Modules/termios.c - termios_constants -
315315
Modules/timemodule.c init_timezone YEAR -
316-
Modules/timemodule.c pysleep_zero_posix zero -
317316
Objects/bytearrayobject.c - _PyByteArray_empty_string -
318317
Objects/complexobject.c - c_1 -
319318
Objects/exceptions.c - static_exceptions -

0 commit comments

Comments
 (0)
0