gh-110850: Fix _PyTime_FromSecondsDouble() API (#116606)

Return 0 on success. Set an exception and return -1 on error.

Fix os.timerfd_settime(): properly report exceptions on
_PyTime_FromSecondsDouble() failure.

No longer export _PyTime_FromSecondsDouble().
This commit is contained in:
Victor Stinner 2024-03-11 17:35:29 +01:00 committed by GitHub
parent 2731913dd5
commit 113053a070
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 31 deletions

View file

@ -565,6 +565,7 @@ pytime_from_double(PyTime_t *tp, double value, _PyTime_round_t round,
/* See comments in pytime_double_to_denominator */
if (!((double)PyTime_MIN <= d && d < -(double)PyTime_MIN)) {
pytime_time_t_overflow();
*tp = 0;
return -1;
}
PyTime_t ns = (PyTime_t)d;
@ -652,14 +653,10 @@ _PyTime_AsLong(PyTime_t ns)
return PyLong_FromLongLong((long long)ns);
}
PyTime_t
_PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round)
int
_PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round, PyTime_t *result)
{
PyTime_t tp;
if(pytime_from_double(&tp, seconds, round, SEC_TO_NS) < 0) {
return -1;
}
return tp;
return pytime_from_double(result, seconds, round, SEC_TO_NS);
}