Remove internal _PyTime_AsLong() function (#141053)

* Replace _PyTime_AsLong() with PyLong_FromInt64()
* Replace _PyTime_FromLong() with PyLong_AsInt64().
This commit is contained in:
Victor Stinner
2025-11-05 18:37:06 +01:00
committed by GitHub
parent 30ab627aab
commit 8d55faf2d6
5 changed files with 20 additions and 62 deletions

View File

@@ -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()
@@ -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.

View File

@@ -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
@@ -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 *
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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 *
@@ -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 *

View File

@@ -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,
@@ -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 */
@@ -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) {
@@ -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,
@@ -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,
@@ -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,
@@ -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,