Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move implementation to pytime
  • Loading branch information
StanFromIreland committed Mar 11, 2025
commit 8ba9ffd0d4e3c01ebd9161c899aa317659753b74
5 changes: 0 additions & 5 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ time_sleep(PyObject *self, PyObject *timeout_obj)

PyTime_t timeout;
if (_PyTime_FromSecondsObject(&timeout, timeout_obj, _PyTime_ROUND_TIMEOUT)) {
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Format(PyExc_TypeError,
"'%T' object cannot be interpreted as an integer or float",
timeout_obj);
}
return NULL;
}
if (timeout < 0) {
Expand Down
34 changes: 19 additions & 15 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,26 +594,30 @@ pytime_from_object(PyTime_t *tp, PyObject *obj, _PyTime_round_t round,
}
return pytime_from_double(tp, d, round, unit_to_ns);
}
else {
Comment thread
StanFromIreland marked this conversation as resolved.
long long sec = PyLong_AsLongLong(obj);
if (sec == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
pytime_overflow();
}
return -1;
}

static_assert(sizeof(long long) <= sizeof(PyTime_t),
"PyTime_t is smaller than long long");
PyTime_t ns = (PyTime_t)sec;
if (pytime_mul(&ns, unit_to_ns) < 0) {
long long sec = PyLong_AsLongLong(obj);
if (sec == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
pytime_overflow();
return -1;
}
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
Comment thread
StanFromIreland marked this conversation as resolved.
Outdated
PyErr_Format(PyExc_TypeError,
"'%T' object cannot be interpreted as an integer or float",
obj);
Comment thread
vstinner marked this conversation as resolved.
Outdated
}
return -1;
}

*tp = ns;
return 0;
static_assert(sizeof(long long) <= sizeof(PyTime_t),
"PyTime_t is smaller than long long");
PyTime_t ns = (PyTime_t)sec;
if (pytime_mul(&ns, unit_to_ns) < 0) {
pytime_overflow();
return -1;
}

*tp = ns;
return 0;
}


Expand Down