@@ -131,16 +131,21 @@ static HANDLE sigint_event = NULL;
131131#ifdef HAVE_GETITIMER
132132static PyObject * ItimerError ;
133133
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 )
137137{
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 ;
143147 }
148+ return _PyTime_AsTimeval (t , tv , _PyTime_ROUND_CEILING );
144149}
145150
146151Py_LOCAL_INLINE (double )
@@ -677,8 +682,8 @@ PySignal_SetWakeupFd(int fd)
677682signal.setitimer
678683
679684 which: int
680- seconds: double
681- interval: double = 0.0
685+ seconds: object
686+ interval: object(c_default="NULL") = 0.0
682687 /
683688
684689Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).
@@ -690,14 +695,19 @@ Returns old values as a tuple: (delay, interval).
690695[clinic start generated code]*/
691696
692697static 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 ]*/
696701{
697702 struct itimerval new , old ;
698703
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+
701711 /* Let OS check "which" value */
702712 if (setitimer (which , & new , & old ) != 0 ) {
703713 PyErr_SetFromErrno (ItimerError );
0 commit comments