summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-03-02 21:54:03 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-03-02 21:54:03 (GMT)
commit643cd68ea4b8d33a6d0163ef693ef6518f76b88f (patch)
tree4dda5f7783635633cc2d092dd975461ba263d2c0 /Modules
parent1c13f84f5554cecbdce8bf42dbfb609c1f72282a (diff)
downloadcpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.zip
cpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.tar.gz
cpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.tar.bz2
Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Add a private API to convert an int or float to a C timespec structure.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c19
-rw-r--r--Modules/signalmodule.c11
2 files changed, 22 insertions, 8 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 23a4d5ac..9294df3 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2323,6 +2323,24 @@ run_in_subinterp(PyObject *self, PyObject *args)
return PyLong_FromLong(r);
}
+static PyObject *
+test_pytime_object_to_timespec(PyObject *self, PyObject *args)
+{
+ PyObject *obj;
+ time_t sec;
+ long nsec;
+ if (!PyArg_ParseTuple(args, "O:pytime_object_to_timespec", &obj))
+ return NULL;
+ if (_PyTime_ObjectToTimespec(obj, &sec, &nsec) == -1)
+ return NULL;
+#if defined(HAVE_LONG_LONG) && SIZEOF_TIME_T == SIZEOF_LONG_LONG
+ return Py_BuildValue("Ll", (PY_LONG_LONG)sec, nsec);
+#else
+ assert(sizeof(time_t) <= sizeof(long));
+ return Py_BuildValue("ll", (long)sec, nsec);
+#endif
+}
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
@@ -2412,6 +2430,7 @@ static PyMethodDef TestMethods[] = {
METH_NOARGS},
{"crash_no_current_thread", (PyCFunction)crash_no_current_thread, METH_NOARGS},
{"run_in_subinterp", run_in_subinterp, METH_VARARGS},
+ {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index e46f8cf..2eb7f29 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -783,16 +783,11 @@ signal_sigtimedwait(PyObject *self, PyObject *args)
siginfo_t si;
int err;
- if (!PyArg_ParseTuple(args, "OO:sigtimedwait", &signals, &timeout))
+ if (!PyArg_ParseTuple(args, "OO:sigtimedwait",
+ &signals, &timeout))
return NULL;
- if (!PyTuple_Check(timeout) || PyTuple_Size(timeout) != 2) {
- PyErr_SetString(PyExc_TypeError,
- "sigtimedwait() arg 2 must be a tuple "
- "(timeout_sec, timeout_nsec)");
- return NULL;
- } else if (!PyArg_ParseTuple(timeout, "ll:sigtimedwait",
- &(buf.tv_sec), &(buf.tv_nsec)))
+ if (_PyTime_ObjectToTimespec(timeout, &buf.tv_sec, &buf.tv_nsec) == -1)
return NULL;
if (buf.tv_sec < 0 || buf.tv_nsec < 0) {