Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions Include/internal/pycore_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
// Export for '_socket' shared extension.
PyAPI_FUNC(PyTime_t) _PyTime_FromSeconds(int seconds);

// Create a timestamp from a number of seconds in double.
extern int _PyTime_FromSecondsDouble(
double seconds,
_PyTime_round_t round,
PyTime_t *result);

// Macro to create a timestamp from a number of seconds, no integer overflow.
// Only use the macro for small values, prefer _PyTime_FromSeconds().
#define _PYTIME_FROMSECONDS(seconds) \
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_os/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -4555,6 +4555,15 @@ def test_timerfd_ns_select(self):
total_time_ns = initial_expiration_ns + interval_ns * (count - 1)
self.assertGreater(t, total_time_ns - self.CLOCK_RES_NS)

def test_timerfd_settime_nan(self):
fd = self.timerfd_create(time.CLOCK_REALTIME)

with self.assertRaises(ValueError):
os.timerfd_settime(fd, initial=float("nan"))
with self.assertRaises(ValueError):
os.timerfd_settime(fd, interval=float("nan"))


class OSErrorTests(unittest.TestCase):
def setUp(self):
class Str(str):
Expand Down
32 changes: 7 additions & 25 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11560,27 +11560,31 @@ os.timerfd_settime
*
flags: int = 0
0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET.
initial as initial_double: double = 0.0
initial as initial_obj: object(c_default="NULL") = 0.0
The initial expiration time, in seconds.
interval as interval_double: double = 0.0
interval as interval_obj: object(c_default="NULL") = 0.0
The timer's interval, in seconds.

Alter a timer file descriptor's internal timer in seconds.
[clinic start generated code]*/

static PyObject *
os_timerfd_settime_impl(PyObject *module, int fd, int flags,
double initial_double, double interval_double)
/*[clinic end generated code: output=df4c1bce6859224e input=81d2c0d7e936e8a7]*/
PyObject *initial_obj, PyObject *interval_obj)
/*[clinic end generated code: output=1b72baf09ba2c79c input=48be44fd2372a8b2]*/
{
PyTime_t initial, interval;
if (_PyTime_FromSecondsDouble(initial_double, _PyTime_ROUND_FLOOR,
&initial) < 0) {
return NULL;
PyTime_t initial = 0, interval = 0;
if (initial_obj != NULL) {
if (_PyTime_FromSecondsObject(&initial, initial_obj,
_PyTime_ROUND_FLOOR) < 0) {
return NULL;
}
}
if (_PyTime_FromSecondsDouble(interval_double, _PyTime_ROUND_FLOOR,
&interval) < 0) {
return NULL;
if (interval_obj != NULL) {
if (_PyTime_FromSecondsObject(&interval, interval_obj,
_PyTime_ROUND_FLOOR) < 0) {
return NULL;
}
}

struct itimerspec new_value, old_value;
Expand Down
7 changes: 0 additions & 7 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,13 +1038,6 @@ PyTime_AsSecondsDouble(PyTime_t ns)
}


int
_PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round, PyTime_t *result)
{
return pytime_from_double(result, seconds, round, SEC_TO_NS);
}


static PyTime_t
pytime_divide_round_up(const PyTime_t t, const PyTime_t k)
{
Expand Down
Loading