Skip to content

Commit f1464f4

Browse files
pxinwrvstinner
authored andcommitted
bpo-31904: Port the time module on VxWorks (GH-12305)
time.clock() is not available on VxWorks.
1 parent 236d0b7 commit f1464f4

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Doc/library/time.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Functions
153153
:c:func:`QueryPerformanceCounter`. The resolution is typically better than one
154154
microsecond.
155155

156+
.. availability:: Windows, Unix. Not available on VxWorks.
157+
156158
.. deprecated:: 3.3
157159
The behaviour of this function depends on the platform: use
158160
:func:`perf_counter` or :func:`process_time` instead, depending on your

Lib/test/test_time.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def check_ns(sec, ns):
8888
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
8989
time.clock_gettime_ns(time.CLOCK_REALTIME))
9090

91+
@unittest.skipUnless(hasattr(time, 'clock'),
92+
'need time.clock()')
9193
def test_clock(self):
9294
with self.assertWarns(DeprecationWarning):
9395
time.clock()
@@ -549,7 +551,9 @@ def test_localtime_failure(self):
549551
self.assertRaises(ValueError, time.ctime, float("nan"))
550552

551553
def test_get_clock_info(self):
552-
clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time']
554+
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
555+
if hasattr(time, 'clock'):
556+
clocks.append('clock')
553557

554558
for name in clocks:
555559
if name == 'clock':
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add time module support and fix test_time faiures for VxWorks.

Modules/timemodule.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ perf_counter(_Py_clock_info_t *info)
145145
return _PyFloat_FromPyTime(t);
146146
}
147147

148-
#if defined(MS_WINDOWS) || defined(HAVE_CLOCK)
148+
#if (defined(MS_WINDOWS) || defined(HAVE_CLOCK)) && !defined(__VXWORKS__)
149149
#define PYCLOCK
150150
static PyObject*
151151
pyclock(_Py_clock_info_t *info)
@@ -765,7 +765,7 @@ time_strftime(PyObject *self, PyObject *args)
765765
return NULL;
766766
}
767767

768-
#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX)
768+
#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) || defined(__VXWORKS__)
769769
if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
770770
PyErr_SetString(PyExc_ValueError,
771771
"strftime() requires year in [1; 9999]");
@@ -1001,18 +1001,21 @@ time_mktime(PyObject *self, PyObject *tm_tuple)
10011001
return NULL;
10021002
}
10031003

1004-
#ifdef _AIX
1004+
#if defined(_AIX) || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_LP64))
10051005
/* bpo-19748: AIX mktime() valid range is 00:00:00 UTC, January 1, 1970
10061006
to 03:14:07 UTC, January 19, 2038. Thanks to the workaround below,
10071007
it is possible to support years in range [1902; 2037] */
10081008
if (tm.tm_year < 2 || tm.tm_year > 137) {
10091009
/* bpo-19748: On AIX, mktime() does not report overflow error
1010-
for timestamp < -2^31 or timestamp > 2**31-1. */
1010+
for timestamp < -2^31 or timestamp > 2**31-1. VxWorks has the
1011+
same issue when working in 32 bit mode. */
10111012
PyErr_SetString(PyExc_OverflowError,
10121013
"mktime argument out of range");
10131014
return NULL;
10141015
}
1016+
#endif
10151017

1018+
#ifdef _AIX
10161019
/* bpo-34373: AIX mktime() has an integer overflow for years in range
10171020
[1902; 1969]. Workaround the issue by using a year greater or equal than
10181021
1970 (tm_year >= 70): mktime() behaves correctly in that case

0 commit comments

Comments
 (0)