Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.7
Changeset: r98561:121428ee2494
Date: 2020-01-18 22:17 +0100
http://bitbucket.org/pypy/pypy/changeset/121428ee2494/
Log: port over enough of the pytime changes to make _testcapi compile
diff --git a/pypy/module/cpyext/include/pytime.h
b/pypy/module/cpyext/include/pytime.h
--- a/pypy/module/cpyext/include/pytime.h
+++ b/pypy/module/cpyext/include/pytime.h
@@ -85,7 +85,11 @@
((_PyTime_t)(seconds) * (1000 * 1000 * 1000))
/* Create a timestamp from a number of nanoseconds. */
-PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(long long ns);
+PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns);
+
+/* Create a timestamp from nanoseconds (Python int). */
+PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t,
+ PyObject *obj);
/* Convert a number of seconds (Python float or int) to a timetamp.
Raise an exception and return -1 on error, return 0 on success. */
diff --git a/pypy/module/cpyext/src/pytime.c b/pypy/module/cpyext/src/pytime.c
--- a/pypy/module/cpyext/src/pytime.c
+++ b/pypy/module/cpyext/src/pytime.c
@@ -239,12 +239,37 @@
}
_PyTime_t
-_PyTime_FromNanoseconds(long long ns)
+_PyTime_FromNanoseconds(_PyTime_t ns)
{
+ /* _PyTime_t already uses nanosecond resolution, no conversion needed */
+ return ns;
+}
+
+int
+_PyTime_FromNanosecondsObject(_PyTime_t *tp, PyObject *obj)
+{
+ long long nsec;
_PyTime_t t;
- Py_BUILD_ASSERT(sizeof(long long) <= sizeof(_PyTime_t));
- t = Py_SAFE_DOWNCAST(ns, long long, _PyTime_t);
- return t;
+
+ if (!PyLong_Check(obj)) {
+ PyErr_Format(PyExc_TypeError, "expect int, got %s",
+ Py_TYPE(obj)->tp_name);
+ return -1;
+ }
+
+ Py_BUILD_ASSERT(sizeof(long long) == sizeof(_PyTime_t));
+ nsec = PyLong_AsLongLong(obj);
+ if (nsec == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
+ _PyTime_overflow();
+ }
+ return -1;
+ }
+
+ /* _PyTime_t already uses nanosecond resolution, no conversion needed */
+ t = (_PyTime_t)nsec;
+ *tp = t;
+ return 0;
}
#ifdef HAVE_CLOCK_GETTIME
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit