Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b4544

Browse files
committed
Issue #22117: Use the _PyTime_t API for time.clock_settime()
Remove also the now unused _PyTime_AddDouble() function.
1 parent c337838 commit b3b4544

3 files changed

Lines changed: 5 additions & 27 deletions

File tree

Include/pytime.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
7474
long *nsec,
7575
_PyTime_round_t);
7676

77-
/* Add interval seconds to tv */
78-
PyAPI_FUNC(void)
79-
_PyTime_AddDouble(_PyTime_timeval *tv, double interval,
80-
_PyTime_round_t round);
81-
8277
/* Initialize time.
8378
Return 0 on success, raise an exception and return -1 on error. */
8479
PyAPI_FUNC(int) _PyTime_Init(void);

Modules/timemodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,18 @@ time_clock_settime(PyObject *self, PyObject *args)
166166
{
167167
int clk_id;
168168
PyObject *obj;
169-
time_t tv_sec;
170-
long tv_nsec;
169+
_PyTime_t t;
171170
struct timespec tp;
172171
int ret;
173172

174173
if (!PyArg_ParseTuple(args, "iO:clock_settime", &clk_id, &obj))
175174
return NULL;
176175

177-
if (_PyTime_ObjectToTimespec(obj, &tv_sec, &tv_nsec, _PyTime_ROUND_DOWN) == -1)
176+
if (_PyTime_FromSecondsObject(&t, obj, _PyTime_ROUND_DOWN) < 0)
177+
return NULL;
178+
179+
if (_PyTime_AsTimespec(t, &tp) == -1)
178180
return NULL;
179-
tp.tv_sec = tv_sec;
180-
tp.tv_nsec = tv_nsec;
181181

182182
ret = clock_settime((clockid_t)clk_id, &tp);
183183
if (ret != 0) {

Python/pytime.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,23 +251,6 @@ _PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec,
251251
return _PyTime_ObjectToDenominator(obj, sec, usec, 1e6, round);
252252
}
253253

254-
void
255-
_PyTime_AddDouble(_PyTime_timeval *tv, double interval, _PyTime_round_t round)
256-
{
257-
_PyTime_timeval tv2;
258-
double frac;
259-
260-
frac = fmod(interval, 1.0);
261-
interval = floor(interval);
262-
tv2.tv_sec = (long)interval;
263-
tv2.tv_usec = (long)(frac*1e6);
264-
265-
tv->tv_sec += tv2.tv_sec;
266-
tv->tv_usec += tv2.tv_usec;
267-
tv->tv_sec += (time_t)(tv->tv_usec / SEC_TO_US);
268-
tv->tv_usec %= SEC_TO_US;
269-
}
270-
271254
/****************** NEW _PyTime_t API **********************/
272255

273256
static void

0 commit comments

Comments
 (0)