bpo-30807: signal.setitimer() now uses _PyTime API (GH-3865) · python/cpython@ef611c9 (original) (raw)

`@@ -131,16 +131,21 @@ static HANDLE sigint_event = NULL;

`

131

131

`#ifdef HAVE_GETITIMER

`

132

132

`static PyObject *ItimerError;

`

133

133

``

134

``

`-

/* auxiliary functions for setitimer/getitimer */

`

135

``

`-

static void

`

136

``

`-

timeval_from_double(double d, struct timeval *tv)

`

``

134

`+

/* auxiliary functions for setitimer */

`

``

135

`+

static int

`

``

136

`+

timeval_from_double(PyObject *obj, struct timeval *tv)

`

137

137

`{

`

138

``

`-

tv->tv_sec = floor(d);

`

139

``

`-

tv->tv_usec = fmod(d, 1.0) * 1000000.0;

`

140

``

`-

/* Don't disable the timer if the computation above rounds down to zero. */

`

141

``

`-

if (d > 0.0 && tv->tv_sec == 0 && tv->tv_usec == 0) {

`

142

``

`-

tv->tv_usec = 1;

`

``

138

`+

if (obj == NULL) {

`

``

139

`+

tv->tv_sec = 0;

`

``

140

`+

tv->tv_usec = 0;

`

``

141

`+

return 0;

`

``

142

`+

}

`

``

143

+

``

144

`+

_PyTime_t t;

`

``

145

`+

if (_PyTime_FromSecondsObject(&t, obj, _PyTime_ROUND_CEILING) < 0) {

`

``

146

`+

return -1;

`

143

147

` }

`

``

148

`+

return _PyTime_AsTimeval(t, tv, _PyTime_ROUND_CEILING);

`

144

149

`}

`

145

150

``

146

151

`Py_LOCAL_INLINE(double)

`

`@@ -677,8 +682,8 @@ PySignal_SetWakeupFd(int fd)

`

677

682

`signal.setitimer

`

678

683

``

679

684

` which: int

`

680

``

`-

seconds: double

`

681

``

`-

interval: double = 0.0

`

``

685

`+

seconds: object

`

``

686

`+

interval: object(c_default="NULL") = 0.0

`

682

687

` /

`

683

688

``

684

689

`Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).

`

`@@ -690,14 +695,19 @@ Returns old values as a tuple: (delay, interval).

`

690

695

`[clinic start generated code]*/

`

691

696

``

692

697

`static PyObject *

`

693

``

`-

signal_setitimer_impl(PyObject *module, int which, double seconds,

`

694

``

`-

double interval)

`

695

``

`-

/[clinic end generated code: output=6f51da0fe0787f2c input=0d27d417cfcbd51a]/

`

``

698

`+

signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,

`

``

699

`+

PyObject *interval)

`

``

700

`+

/[clinic end generated code: output=65f9dcbddc35527b input=de43daf194e6f66f]/

`

696

701

`{

`

697

702

`struct itimerval new, old;

`

698

703

``

699

``

`-

timeval_from_double(seconds, &new.it_value);

`

700

``

`-

timeval_from_double(interval, &new.it_interval);

`

``

704

`+

if (timeval_from_double(seconds, &new.it_value) < 0) {

`

``

705

`+

return NULL;

`

``

706

`+

}

`

``

707

`+

if (timeval_from_double(interval, &new.it_interval) < 0) {

`

``

708

`+

return NULL;

`

``

709

`+

}

`

``

710

+

701

711

`/* Let OS check "which" value */

`

702

712

`if (setitimer(which, &new, &old) != 0) {

`

703

713

`PyErr_SetFromErrno(ItimerError);

`