Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 0 additions & 9 deletions Include/internal/pycore_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ extern int _PyTime_FromSecondsDouble(
// 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.
Expand Down Expand Up @@ -182,10 +177,6 @@ extern PyTime_t _PyTime_As100Nanoseconds(PyTime_t t,
_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.
Expand Down
4 changes: 2 additions & 2 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#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()

Expand Down Expand Up @@ -111,7 +111,7 @@ static PyTime_t CallExternalTimer(ProfilerObject *pObj)
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.
Expand Down
20 changes: 10 additions & 10 deletions Modules/_testinternalcapi/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_pytime_fromseconds(PyObject *self, PyObject *args)
return NULL;
}
PyTime_t ts = _PyTime_FromSeconds(seconds);
return _PyTime_AsLong(ts);
return PyLong_FromInt64(ts);
}

static int
Expand Down Expand Up @@ -49,7 +49,7 @@ test_pytime_fromsecondsobject(PyObject *self, PyObject *args)
if (_PyTime_FromSecondsObject(&ts, obj, round) == -1) {
return NULL;
}
return _PyTime_AsLong(ts);
return PyLong_FromInt64(ts);
}

static PyObject *
Expand All @@ -64,7 +64,7 @@ test_PyTime_AsTimeval(PyObject *self, PyObject *args)
return NULL;
}
PyTime_t t;
if (_PyTime_FromLong(&t, obj) < 0) {
if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timeval tv;
Expand All @@ -91,7 +91,7 @@ test_PyTime_AsTimeval_clamp(PyObject *self, PyObject *args)
return NULL;
}
PyTime_t t;
if (_PyTime_FromLong(&t, obj) < 0) {
if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timeval tv;
Expand All @@ -113,7 +113,7 @@ test_PyTime_AsTimespec(PyObject *self, PyObject *args)
return NULL;
}
PyTime_t t;
if (_PyTime_FromLong(&t, obj) < 0) {
if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timespec ts;
Expand All @@ -131,7 +131,7 @@ test_PyTime_AsTimespec_clamp(PyObject *self, PyObject *args)
return NULL;
}
PyTime_t t;
if (_PyTime_FromLong(&t, obj) < 0) {
if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
struct timespec ts;
Expand All @@ -149,14 +149,14 @@ test_PyTime_AsMilliseconds(PyObject *self, PyObject *args)
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 *
Expand All @@ -168,14 +168,14 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
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 *
Expand Down
14 changes: 7 additions & 7 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ time_time_ns(PyObject *self, PyObject *unused)
if (PyTime_Time(&t) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}

PyDoc_STRVAR(time_ns_doc,
Expand Down Expand Up @@ -261,7 +261,7 @@ time_clock_gettime_ns_impl(PyObject *module, clockid_t clk_id)
if (_PyTime_FromTimespec(&t, &ts) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}
#endif /* HAVE_CLOCK_GETTIME */

Expand Down Expand Up @@ -310,7 +310,7 @@ time_clock_settime_ns(PyObject *self, PyObject *args)
return NULL;
}

if (_PyTime_FromLong(&t, obj) < 0) {
if (PyLong_AsInt64(obj, &t) < 0) {
return NULL;
}
if (_PyTime_AsTimespec(t, &ts) == -1) {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ time_monotonic_ns(PyObject *self, PyObject *unused)
if (PyTime_Monotonic(&t) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}

PyDoc_STRVAR(monotonic_ns_doc,
Expand Down Expand Up @@ -1248,7 +1248,7 @@ time_perf_counter_ns(PyObject *self, PyObject *unused)
if (PyTime_PerfCounter(&t) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}

PyDoc_STRVAR(perf_counter_ns_doc,
Expand Down Expand Up @@ -1437,7 +1437,7 @@ time_process_time_ns(PyObject *module, PyObject *unused)
if (py_process_time(state, &t, NULL) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}

PyDoc_STRVAR(process_time_ns_doc,
Expand Down Expand Up @@ -1610,7 +1610,7 @@ time_thread_time_ns(PyObject *self, PyObject *unused)
if (_PyTime_GetThreadTimeWithInfo(&t, NULL) < 0) {
return NULL;
}
return _PyTime_AsLong(t);
return PyLong_FromInt64(t);
}

PyDoc_STRVAR(thread_time_ns_doc,
Expand Down
35 changes: 1 addition & 34 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#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
Expand Down Expand Up @@ -472,31 +472,6 @@ _PyTime_FromMicrosecondsClamp(PyTime_t us)
}


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)
Expand Down Expand Up @@ -658,14 +633,6 @@ PyTime_AsSecondsDouble(PyTime_t ns)
}


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)
{
Expand Down
Loading