Commit 49a69e4d authored by Benjamin Peterson's avatar Benjamin Peterson

strip is_ prefixes on clock_info fields

parent d099b56b
...@@ -168,11 +168,11 @@ The module defines the following functions and data items: ...@@ -168,11 +168,11 @@ The module defines the following functions and data items:
The name of the underlying C function used to get the clock value. The name of the underlying C function used to get the clock value.
.. attribute:: is_monotonic .. attribute:: monotonic
``True`` if the clock cannot go backward, ``False`` otherwise. ``True`` if the clock cannot go backward, ``False`` otherwise.
.. attribute:: is_adjusted .. attribute:: adjusted
``True`` if the clock can be adjusted (e.g. by a NTP daemon), ``False`` ``True`` if the clock can be adjusted (e.g. by a NTP daemon), ``False``
otherwise. otherwise.
......
...@@ -25,8 +25,8 @@ typedef struct { ...@@ -25,8 +25,8 @@ typedef struct {
/* Structure used by time.get_clock_info() */ /* Structure used by time.get_clock_info() */
typedef struct { typedef struct {
const char *implementation; const char *implementation;
int is_monotonic; int monotonic;
int is_adjusted; int adjusted;
double resolution; double resolution;
} _Py_clock_info_t; } _Py_clock_info_t;
......
...@@ -30,16 +30,16 @@ class TimeTestCase(unittest.TestCase): ...@@ -30,16 +30,16 @@ class TimeTestCase(unittest.TestCase):
def test_time(self): def test_time(self):
time.time() time.time()
info = time.get_clock_info('time') info = time.get_clock_info('time')
self.assertEqual(info.is_monotonic, False) self.assertEqual(info.monotonic, False)
if sys.platform != 'win32': if sys.platform != 'win32':
self.assertEqual(info.is_adjusted, True) self.assertEqual(info.adjusted, True)
def test_clock(self): def test_clock(self):
time.clock() time.clock()
info = time.get_clock_info('clock') info = time.get_clock_info('clock')
self.assertEqual(info.is_monotonic, True) self.assertEqual(info.monotonic, True)
self.assertEqual(info.is_adjusted, False) self.assertEqual(info.adjusted, False)
@unittest.skipUnless(hasattr(time, 'clock_gettime'), @unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()') 'need time.clock_gettime()')
...@@ -370,11 +370,11 @@ class TimeTestCase(unittest.TestCase): ...@@ -370,11 +370,11 @@ class TimeTestCase(unittest.TestCase):
self.assertAlmostEqual(dt, 0.1, delta=0.2) self.assertAlmostEqual(dt, 0.1, delta=0.2)
info = time.get_clock_info('monotonic') info = time.get_clock_info('monotonic')
self.assertEqual(info.is_monotonic, True) self.assertEqual(info.monotonic, True)
if sys.platform == 'linux': if sys.platform == 'linux':
self.assertEqual(info.is_adjusted, True) self.assertEqual(info.adjusted, True)
else: else:
self.assertEqual(info.is_adjusted, False) self.assertEqual(info.adjusted, False)
def test_perf_counter(self): def test_perf_counter(self):
time.perf_counter() time.perf_counter()
...@@ -386,8 +386,8 @@ class TimeTestCase(unittest.TestCase): ...@@ -386,8 +386,8 @@ class TimeTestCase(unittest.TestCase):
self.assertLess(stop - start, 0.01) self.assertLess(stop - start, 0.01)
info = time.get_clock_info('process_time') info = time.get_clock_info('process_time')
self.assertEqual(info.is_monotonic, True) self.assertEqual(info.monotonic, True)
self.assertEqual(info.is_adjusted, False) self.assertEqual(info.adjusted, False)
@unittest.skipUnless(hasattr(time, 'monotonic'), @unittest.skipUnless(hasattr(time, 'monotonic'),
'need time.monotonic') 'need time.monotonic')
...@@ -433,12 +433,12 @@ class TimeTestCase(unittest.TestCase): ...@@ -433,12 +433,12 @@ class TimeTestCase(unittest.TestCase):
#self.assertIsInstance(info, dict) #self.assertIsInstance(info, dict)
self.assertIsInstance(info.implementation, str) self.assertIsInstance(info.implementation, str)
self.assertNotEqual(info.implementation, '') self.assertNotEqual(info.implementation, '')
self.assertIsInstance(info.is_monotonic, bool) self.assertIsInstance(info.monotonic, bool)
self.assertIsInstance(info.resolution, float) self.assertIsInstance(info.resolution, float)
# 0.0 < resolution <= 1.0 # 0.0 < resolution <= 1.0
self.assertGreater(info.resolution, 0.0) self.assertGreater(info.resolution, 0.0)
self.assertLessEqual(info.resolution, 1.0) self.assertLessEqual(info.resolution, 1.0)
self.assertIsInstance(info.is_adjusted, bool) self.assertIsInstance(info.adjusted, bool)
self.assertRaises(ValueError, time.get_clock_info, 'xxx') self.assertRaises(ValueError, time.get_clock_info, 'xxx')
......
...@@ -95,8 +95,8 @@ floatclock(_Py_clock_info_t *info) ...@@ -95,8 +95,8 @@ floatclock(_Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "clock()"; info->implementation = "clock()";
info->resolution = 1.0 / (double)CLOCKS_PER_SEC; info->resolution = 1.0 / (double)CLOCKS_PER_SEC;
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
} }
return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC); return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC);
} }
...@@ -131,8 +131,8 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result) ...@@ -131,8 +131,8 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result)
if (info) { if (info) {
info->implementation = "QueryPerformanceCounter()"; info->implementation = "QueryPerformanceCounter()";
info->resolution = 1.0 / (double)cpu_frequency; info->resolution = 1.0 / (double)cpu_frequency;
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
} }
*result = PyFloat_FromDouble(diff / (double)cpu_frequency); *result = PyFloat_FromDouble(diff / (double)cpu_frequency);
return 0; return 0;
...@@ -874,7 +874,7 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -874,7 +874,7 @@ pymonotonic(_Py_clock_info_t *info)
info->implementation = "GetTickCount64()"; info->implementation = "GetTickCount64()";
else else
info->implementation = "GetTickCount()"; info->implementation = "GetTickCount()";
info->is_monotonic = 1; info->monotonic = 1;
ok = GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement, ok = GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
&isTimeAdjustmentDisabled); &isTimeAdjustmentDisabled);
if (!ok) { if (!ok) {
...@@ -882,7 +882,7 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -882,7 +882,7 @@ pymonotonic(_Py_clock_info_t *info)
return NULL; return NULL;
} }
info->resolution = timeIncrement * 1e-7; info->resolution = timeIncrement * 1e-7;
info->is_adjusted = 0; info->adjusted = 0;
} }
return PyFloat_FromDouble(result); return PyFloat_FromDouble(result);
...@@ -902,8 +902,8 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -902,8 +902,8 @@ pymonotonic(_Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "mach_absolute_time()"; info->implementation = "mach_absolute_time()";
info->resolution = (double)timebase.numer / timebase.denom * 1e-9; info->resolution = (double)timebase.numer / timebase.denom * 1e-9;
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
} }
return PyFloat_FromDouble(secs); return PyFloat_FromDouble(secs);
...@@ -924,14 +924,14 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -924,14 +924,14 @@ pymonotonic(_Py_clock_info_t *info)
if (info) { if (info) {
struct timespec res; struct timespec res;
info->is_monotonic = 1; info->monotonic = 1;
info->implementation = function; info->implementation = function;
#if (defined(linux) || defined(__linux) || defined(__linux__)) \ #if (defined(linux) || defined(__linux) || defined(__linux__)) \
&& !defined(CLOCK_HIGHRES) && !defined(CLOCK_HIGHRES)
/* CLOCK_MONOTONIC is adjusted on Linux */ /* CLOCK_MONOTONIC is adjusted on Linux */
info->is_adjusted = 1; info->adjusted = 1;
#else #else
info->is_adjusted = 0; info->adjusted = 0;
#endif #endif
if (clock_getres(clk_id, &res) == 0) if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
...@@ -1023,8 +1023,8 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1023,8 +1023,8 @@ py_process_time(_Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "GetProcessTimes()"; info->implementation = "GetProcessTimes()";
info->resolution = 1e-7; info->resolution = 1e-7;
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
} }
return PyFloat_FromDouble(total * 1e-7); return PyFloat_FromDouble(total * 1e-7);
#else #else
...@@ -1052,8 +1052,8 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1052,8 +1052,8 @@ py_process_time(_Py_clock_info_t *info)
if (info) { if (info) {
struct timespec res; struct timespec res;
info->implementation = function; info->implementation = function;
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
if (clock_getres(clk_id, &res) == 0) if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else else
...@@ -1070,8 +1070,8 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1070,8 +1070,8 @@ py_process_time(_Py_clock_info_t *info)
total += ru.ru_stime.tv_sec + ru.ru_stime.tv_usec * 1e-6; total += ru.ru_stime.tv_sec + ru.ru_stime.tv_usec * 1e-6;
if (info) { if (info) {
info->implementation = "getrusage(RUSAGE_SELF)"; info->implementation = "getrusage(RUSAGE_SELF)";
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
info->resolution = 1e-6; info->resolution = 1e-6;
} }
return PyFloat_FromDouble(total); return PyFloat_FromDouble(total);
...@@ -1099,8 +1099,8 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1099,8 +1099,8 @@ py_process_time(_Py_clock_info_t *info)
total += (double)t.tms_stime / ticks_per_second; total += (double)t.tms_stime / ticks_per_second;
if (info) { if (info) {
info->implementation = "times()"; info->implementation = "times()";
info->is_monotonic = 1; info->monotonic = 1;
info->is_adjusted = 0; info->adjusted = 0;
info->resolution = 1.0 / ticks_per_second; info->resolution = 1.0 / ticks_per_second;
} }
return PyFloat_FromDouble(total); return PyFloat_FromDouble(total);
...@@ -1132,8 +1132,8 @@ PyDoc_STRVAR(ClockInfo_docstring, ...@@ -1132,8 +1132,8 @@ PyDoc_STRVAR(ClockInfo_docstring,
static PyStructSequence_Field ClockInfo_fields[] = { static PyStructSequence_Field ClockInfo_fields[] = {
{"implementation", "name of the underlying C function " {"implementation", "name of the underlying C function "
"used to get the clock value"}, "used to get the clock value"},
{"is_monotonic", "True if the clock cannot go backward, False otherwise"}, {"monotonic", "True if the clock cannot go backward, False otherwise"},
{"is_adjusted", "True if the clock can be adjusted " {"adjusted", "True if the clock can be adjusted "
"(e.g. by a NTP daemon), False otherwise"}, "(e.g. by a NTP daemon), False otherwise"},
{"resolution", "resolution of the clock in seconds"}, {"resolution", "resolution of the clock in seconds"},
{NULL, NULL} {NULL, NULL}
...@@ -1159,13 +1159,13 @@ time_get_clock_info(PyObject *self, PyObject *args) ...@@ -1159,13 +1159,13 @@ time_get_clock_info(PyObject *self, PyObject *args)
#ifdef Py_DEBUG #ifdef Py_DEBUG
info.implementation = NULL; info.implementation = NULL;
info.is_monotonic = -1; info.monotonic = -1;
info.is_adjusted = -1; info.adjusted = -1;
info.resolution = -1.0; info.resolution = -1.0;
#else #else
info.implementation = ""; info.implementation = "";
info.is_monotonic = 0; info.monotonic = 0;
info.is_adjusted = 0; info.adjusted = 0;
info.resolution = 1.0; info.resolution = 1.0;
#endif #endif
...@@ -1201,14 +1201,14 @@ time_get_clock_info(PyObject *self, PyObject *args) ...@@ -1201,14 +1201,14 @@ time_get_clock_info(PyObject *self, PyObject *args)
goto error; goto error;
PyStructSequence_SET_ITEM(result, 0, obj); PyStructSequence_SET_ITEM(result, 0, obj);
assert(info.is_monotonic != -1); assert(info.monotonic != -1);
obj = PyBool_FromLong(info.is_monotonic); obj = PyBool_FromLong(info.monotonic);
if (obj == NULL) if (obj == NULL)
goto error; goto error;
PyStructSequence_SET_ITEM(result, 1, obj); PyStructSequence_SET_ITEM(result, 1, obj);
assert(info.is_adjusted != -1); assert(info.adjusted != -1);
obj = PyBool_FromLong(info.is_adjusted); obj = PyBool_FromLong(info.adjusted);
if (obj == NULL) if (obj == NULL)
goto error; goto error;
PyStructSequence_SET_ITEM(result, 2, obj); PyStructSequence_SET_ITEM(result, 2, obj);
...@@ -1487,8 +1487,8 @@ floattime(_Py_clock_info_t *info) ...@@ -1487,8 +1487,8 @@ floattime(_Py_clock_info_t *info)
if (info) { if (info) {
struct timespec res; struct timespec res;
info->implementation = "clock_gettime(CLOCK_REALTIME)"; info->implementation = "clock_gettime(CLOCK_REALTIME)";
info->is_monotonic = 0; info->monotonic = 0;
info->is_adjusted = 1; info->adjusted = 1;
if (clock_getres(CLOCK_REALTIME, &res) == 0) if (clock_getres(CLOCK_REALTIME, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else else
......
...@@ -40,14 +40,14 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -40,14 +40,14 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
BOOL isTimeAdjustmentDisabled; BOOL isTimeAdjustmentDisabled;
info->implementation = "GetSystemTimeAsFileTime()"; info->implementation = "GetSystemTimeAsFileTime()";
info->is_monotonic = 0; info->monotonic = 0;
(void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement, (void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
&isTimeAdjustmentDisabled); &isTimeAdjustmentDisabled);
info->resolution = timeIncrement * 1e-7; info->resolution = timeIncrement * 1e-7;
if (isTimeAdjustmentDisabled) if (isTimeAdjustmentDisabled)
info->is_adjusted = 0; info->adjusted = 0;
else else
info->is_adjusted = 1; info->adjusted = 1;
} }
#else #else
/* There are three ways to get the time: /* There are three ways to get the time:
...@@ -70,8 +70,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -70,8 +70,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "gettimeofday()"; info->implementation = "gettimeofday()";
info->resolution = 1e-6; info->resolution = 1e-6;
info->is_monotonic = 0; info->monotonic = 0;
info->is_adjusted = 1; info->adjusted = 1;
} }
return; return;
} }
...@@ -86,8 +86,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -86,8 +86,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "ftime()"; info->implementation = "ftime()";
info->resolution = 1e-3; info->resolution = 1e-3;
info->is_monotonic = 0; info->monotonic = 0;
info->is_adjusted = 1; info->adjusted = 1;
} }
} }
#else /* !HAVE_FTIME */ #else /* !HAVE_FTIME */
...@@ -96,8 +96,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -96,8 +96,8 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "time()"; info->implementation = "time()";
info->resolution = 1.0; info->resolution = 1.0;
info->is_monotonic = 0; info->monotonic = 0;
info->is_adjusted = 1; info->adjusted = 1;
} }
#endif /* !HAVE_FTIME */ #endif /* !HAVE_FTIME */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment