// Clamp to [PyTime_MIN; PyTime_MAX] on overflow.
extern PyTime_t _PyTime_FromMicrosecondsClamp(PyTime_t us);
-// Create a timestamp from a Python int object (number of nanoseconds).
-// Export for '_lsprof' shared extension.
-PyAPI_FUNC(int) _PyTime_FromLong(PyTime_t *t,
- PyObject *obj);
-
// Convert a number of seconds (Python float or int) to a timestamp.
// Raise an exception and return -1 on error, return 0 on success.
// Export for '_socket' shared extension.
_PyTime_round_t round);
#endif
-// Convert a timestamp (number of nanoseconds) as a Python int object.
-// Export for '_testinternalcapi' shared extension.
-PyAPI_FUNC(PyObject*) _PyTime_AsLong(PyTime_t t);
-
#ifndef MS_WINDOWS
// Create a timestamp from a timeval structure.
// Raise an exception and return -1 on overflow, return 0 on success.
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_SetProfile()
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "pycore_time.h" // _PyTime_FromLong()
+#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
if (pObj->externalTimerUnit > 0.0) {
/* interpret the result as an integer that will be scaled
in profiler_getstats() */
- err = _PyTime_FromLong(&result, o);
+ err = PyLong_AsInt64(o, &result);
}
else {
/* interpret the result as a double measured in seconds.
return NULL;
}
PyTime_t ts = _PyTime_FromSeconds(seconds);
- return _PyTime_AsLong(ts);
+ return PyLong_FromInt64(ts);
}
static int
if (_PyTime_FromSecondsObject(&ts, obj, round) == -1) {
return NULL;
}
- return _PyTime_AsLong(ts);
+ return PyLong_FromInt64(ts);
}
static PyObject *
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timeval tv;
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timeval tv;
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timespec ts;
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timespec ts;
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
PyTime_t ms = _PyTime_AsMilliseconds(t, round);
- return _PyTime_AsLong(ms);
+ return PyLong_FromInt64(ms);
}
static PyObject *
return NULL;
}
PyTime_t t;
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
if (check_time_rounding(round) < 0) {
return NULL;
}
PyTime_t us = _PyTime_AsMicroseconds(t, round);
- return _PyTime_AsLong(us);
+ return PyLong_FromInt64(us);
}
static PyObject *
if (PyTime_Time(&t) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
PyDoc_STRVAR(time_ns_doc,
if (_PyTime_FromTimespec(&t, &ts) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
#endif /* HAVE_CLOCK_GETTIME */
return NULL;
}
- if (_PyTime_FromLong(&t, obj) < 0) {
+ if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
if (_PyTime_AsTimespec(t, &ts) == -1) {
if (PyTime_Monotonic(&t) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
PyDoc_STRVAR(monotonic_ns_doc,
if (PyTime_PerfCounter(&t) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
PyDoc_STRVAR(perf_counter_ns_doc,
if (py_process_time(state, &t, NULL) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
PyDoc_STRVAR(process_time_ns_doc,
if (_PyTime_GetThreadTimeWithInfo(&t, NULL) < 0) {
return NULL;
}
- return _PyTime_AsLong(t);
+ return PyLong_FromInt64(t);
}
PyDoc_STRVAR(thread_time_ns_doc,
#include "pycore_initconfig.h" // _PyStatus_ERR
#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#include "pycore_runtime.h" // _PyRuntime
-#include "pycore_time.h" // PyTime_t
+#include "pycore_time.h" // export _PyLong_FromTime_t()
#include <time.h> // gmtime_r()
#ifdef HAVE_SYS_TIME_H
}
-int
-_PyTime_FromLong(PyTime_t *tp, PyObject *obj)
-{
- if (!PyLong_Check(obj)) {
- PyErr_Format(PyExc_TypeError, "expect int, got %s",
- Py_TYPE(obj)->tp_name);
- return -1;
- }
-
- static_assert(sizeof(long long) == sizeof(PyTime_t),
- "PyTime_t is not long long");
- long long nsec = PyLong_AsLongLong(obj);
- if (nsec == -1 && PyErr_Occurred()) {
- if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
- pytime_overflow();
- }
- return -1;
- }
-
- PyTime_t t = (PyTime_t)nsec;
- *tp = t;
- return 0;
-}
-
-
#ifdef HAVE_CLOCK_GETTIME
static int
pytime_fromtimespec(PyTime_t *tp, const struct timespec *ts, int raise_exc)
}
-PyObject *
-_PyTime_AsLong(PyTime_t ns)
-{
- static_assert(sizeof(long long) >= sizeof(PyTime_t),
- "PyTime_t is larger than long long");
- return PyLong_FromLongLong((long long)ns);
-}
-
int
_PyTime_FromSecondsDouble(double seconds, _PyTime_round_t round, PyTime_t *result)
{