aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/timemodule.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/timemodule.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/timemodule.c')
-rw-r--r--contrib/tools/python3/src/Modules/timemodule.c826
1 files changed, 413 insertions, 413 deletions
diff --git a/contrib/tools/python3/src/Modules/timemodule.c b/contrib/tools/python3/src/Modules/timemodule.c
index 10c3cd0bb3..df59f2aac5 100644
--- a/contrib/tools/python3/src/Modules/timemodule.c
+++ b/contrib/tools/python3/src/Modules/timemodule.c
@@ -24,17 +24,17 @@
# include <pthread.h>
#endif
-#if defined(_AIX)
-# include <sys/thread.h>
-#endif
-
+#if defined(_AIX)
+# include <sys/thread.h>
+#endif
+
#if defined(__WATCOMC__) && !defined(__QNX__)
-# include <i86.h>
+# include <i86.h>
#else
-# ifdef MS_WINDOWS
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-# endif /* MS_WINDOWS */
+# ifdef MS_WINDOWS
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# endif /* MS_WINDOWS */
#endif /* !__WATCOMC__ || __QNX__ */
#ifdef _Py_MEMORY_SANITIZER
@@ -51,15 +51,15 @@
#define _Py_tzname tzname
#endif
-#if defined(__APPLE__ ) && defined(__has_builtin)
-# if __has_builtin(__builtin_available)
-# define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
-# endif
-#endif
-#ifndef HAVE_CLOCK_GETTIME_RUNTIME
-# define HAVE_CLOCK_GETTIME_RUNTIME 1
-#endif
-
+#if defined(__APPLE__ ) && defined(__has_builtin)
+# if __has_builtin(__builtin_available)
+# define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
+# endif
+#endif
+#ifndef HAVE_CLOCK_GETTIME_RUNTIME
+# define HAVE_CLOCK_GETTIME_RUNTIME 1
+#endif
+
#define SEC_TO_NS (1000 * 1000 * 1000)
/* Forward declarations */
@@ -158,29 +158,29 @@ perf_counter(_Py_clock_info_t *info)
}
#ifdef HAVE_CLOCK_GETTIME
-
-#ifdef __APPLE__
-/*
- * The clock_* functions will be removed from the module
- * dict entirely when the C API is not available.
- */
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunguarded-availability"
-#endif
-
+
+#ifdef __APPLE__
+/*
+ * The clock_* functions will be removed from the module
+ * dict entirely when the C API is not available.
+ */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability"
+#endif
+
static PyObject *
time_clock_gettime(PyObject *self, PyObject *args)
{
int ret;
struct timespec tp;
-#if defined(_AIX) && (SIZEOF_LONG == 8)
- long clk_id;
- if (!PyArg_ParseTuple(args, "l:clock_gettime", &clk_id)) {
-#else
- int clk_id;
+#if defined(_AIX) && (SIZEOF_LONG == 8)
+ long clk_id;
+ if (!PyArg_ParseTuple(args, "l:clock_gettime", &clk_id)) {
+#else
+ int clk_id;
if (!PyArg_ParseTuple(args, "i:clock_gettime", &clk_id)) {
-#endif
+#endif
return NULL;
}
@@ -316,11 +316,11 @@ PyDoc_STRVAR(clock_getres_doc,
"clock_getres(clk_id) -> floating point number\n\
\n\
Return the resolution (precision) of the specified clock clk_id.");
-
-#ifdef __APPLE__
-#pragma clang diagnostic pop
-#endif
-
+
+#ifdef __APPLE__
+#pragma clang diagnostic pop
+#endif
+
#endif /* HAVE_CLOCK_GETRES */
#ifdef HAVE_PTHREAD_GETCPUCLOCKID
@@ -534,10 +534,10 @@ time_localtime(PyObject *self, PyObject *args)
#endif
}
-#if defined(__linux__) && !defined(__GLIBC__)
-static const char *utc_string = NULL;
-#endif
-
+#if defined(__linux__) && !defined(__GLIBC__)
+static const char *utc_string = NULL;
+#endif
+
PyDoc_STRVAR(localtime_doc,
"localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n\
tm_sec,tm_wday,tm_yday,tm_isdst)\n\
@@ -577,35 +577,35 @@ gettmarg(PyObject *args, struct tm *p, const char *format)
p->tm_wday = (p->tm_wday + 1) % 7;
p->tm_yday--;
#ifdef HAVE_STRUCT_TM_TM_ZONE
- if (Py_IS_TYPE(args, &StructTimeType)) {
+ if (Py_IS_TYPE(args, &StructTimeType)) {
PyObject *item;
- item = PyStructSequence_GET_ITEM(args, 9);
- if (item != Py_None) {
- p->tm_zone = (char *)PyUnicode_AsUTF8(item);
- if (p->tm_zone == NULL) {
- return 0;
- }
-#if defined(__linux__) && !defined(__GLIBC__)
- // Make an attempt to return the C library's own timezone strings to
- // it. musl refuses to process a tm_zone field unless it produced
- // it. See issue #34672.
- if (utc_string && strcmp(p->tm_zone, utc_string) == 0) {
- p->tm_zone = utc_string;
- }
- else if (tzname[0] && strcmp(p->tm_zone, tzname[0]) == 0) {
- p->tm_zone = tzname[0];
- }
- else if (tzname[1] && strcmp(p->tm_zone, tzname[1]) == 0) {
- p->tm_zone = tzname[1];
- }
-#endif
- }
- item = PyStructSequence_GET_ITEM(args, 10);
- if (item != Py_None) {
- p->tm_gmtoff = PyLong_AsLong(item);
- if (PyErr_Occurred())
- return 0;
- }
+ item = PyStructSequence_GET_ITEM(args, 9);
+ if (item != Py_None) {
+ p->tm_zone = (char *)PyUnicode_AsUTF8(item);
+ if (p->tm_zone == NULL) {
+ return 0;
+ }
+#if defined(__linux__) && !defined(__GLIBC__)
+ // Make an attempt to return the C library's own timezone strings to
+ // it. musl refuses to process a tm_zone field unless it produced
+ // it. See issue #34672.
+ if (utc_string && strcmp(p->tm_zone, utc_string) == 0) {
+ p->tm_zone = utc_string;
+ }
+ else if (tzname[0] && strcmp(p->tm_zone, tzname[0]) == 0) {
+ p->tm_zone = tzname[0];
+ }
+ else if (tzname[1] && strcmp(p->tm_zone, tzname[1]) == 0) {
+ p->tm_zone = tzname[1];
+ }
+#endif
+ }
+ item = PyStructSequence_GET_ITEM(args, 10);
+ if (item != Py_None) {
+ p->tm_gmtoff = PyLong_AsLong(item);
+ if (PyErr_Occurred())
+ return 0;
+ }
}
#endif /* HAVE_STRUCT_TM_TM_ZONE */
return 1;
@@ -754,7 +754,7 @@ time_strftime(PyObject *self, PyObject *args)
return NULL;
}
-#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) || defined(__VXWORKS__)
+#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) || defined(__VXWORKS__)
if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
PyErr_SetString(PyExc_ValueError,
"strftime() requires year in [1; 9999]");
@@ -979,71 +979,71 @@ not present, current time as returned by localtime() is used.");
#ifdef HAVE_MKTIME
static PyObject *
-time_mktime(PyObject *self, PyObject *tm_tuple)
+time_mktime(PyObject *self, PyObject *tm_tuple)
{
- struct tm tm;
+ struct tm tm;
time_t tt;
-
- if (!gettmarg(tm_tuple, &tm,
+
+ if (!gettmarg(tm_tuple, &tm,
"iiiiiiiii;mktime(): illegal time tuple argument"))
{
return NULL;
}
-
-#if defined(_AIX) || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_LP64))
- /* bpo-19748: AIX mktime() valid range is 00:00:00 UTC, January 1, 1970
- to 03:14:07 UTC, January 19, 2038. Thanks to the workaround below,
- it is possible to support years in range [1902; 2037] */
- if (tm.tm_year < 2 || tm.tm_year > 137) {
- /* bpo-19748: On AIX, mktime() does not report overflow error
- for timestamp < -2^31 or timestamp > 2**31-1. VxWorks has the
- same issue when working in 32 bit mode. */
+
+#if defined(_AIX) || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_LP64))
+ /* bpo-19748: AIX mktime() valid range is 00:00:00 UTC, January 1, 1970
+ to 03:14:07 UTC, January 19, 2038. Thanks to the workaround below,
+ it is possible to support years in range [1902; 2037] */
+ if (tm.tm_year < 2 || tm.tm_year > 137) {
+ /* bpo-19748: On AIX, mktime() does not report overflow error
+ for timestamp < -2^31 or timestamp > 2**31-1. VxWorks has the
+ same issue when working in 32 bit mode. */
PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range");
return NULL;
}
#endif
-
-#ifdef _AIX
- /* bpo-34373: AIX mktime() has an integer overflow for years in range
- [1902; 1969]. Workaround the issue by using a year greater or equal than
- 1970 (tm_year >= 70): mktime() behaves correctly in that case
- (ex: properly report errors). tm_year and tm_wday are adjusted after
- mktime() call. */
- int orig_tm_year = tm.tm_year;
- int delta_days = 0;
- while (tm.tm_year < 70) {
- /* Use 4 years to account properly leap years */
- tm.tm_year += 4;
- delta_days -= (366 + (365 * 3));
- }
-#endif
-
- tm.tm_wday = -1; /* sentinel; original value ignored */
- tt = mktime(&tm);
-
+
+#ifdef _AIX
+ /* bpo-34373: AIX mktime() has an integer overflow for years in range
+ [1902; 1969]. Workaround the issue by using a year greater or equal than
+ 1970 (tm_year >= 70): mktime() behaves correctly in that case
+ (ex: properly report errors). tm_year and tm_wday are adjusted after
+ mktime() call. */
+ int orig_tm_year = tm.tm_year;
+ int delta_days = 0;
+ while (tm.tm_year < 70) {
+ /* Use 4 years to account properly leap years */
+ tm.tm_year += 4;
+ delta_days -= (366 + (365 * 3));
+ }
+#endif
+
+ tm.tm_wday = -1; /* sentinel; original value ignored */
+ tt = mktime(&tm);
+
/* Return value of -1 does not necessarily mean an error, but tm_wday
* cannot remain set to -1 if mktime succeeded. */
if (tt == (time_t)(-1)
/* Return value of -1 does not necessarily mean an error, but
* tm_wday cannot remain set to -1 if mktime succeeded. */
- && tm.tm_wday == -1)
+ && tm.tm_wday == -1)
{
PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range");
return NULL;
}
-
-#ifdef _AIX
- if (delta_days != 0) {
- tm.tm_year = orig_tm_year;
- if (tm.tm_wday != -1) {
- tm.tm_wday = (tm.tm_wday + delta_days) % 7;
- }
- tt += delta_days * (24 * 3600);
- }
-#endif
-
+
+#ifdef _AIX
+ if (delta_days != 0) {
+ tm.tm_year = orig_tm_year;
+ if (tm.tm_wday != -1) {
+ tm.tm_wday = (tm.tm_wday + delta_days) % 7;
+ }
+ tt += delta_days * (24 * 3600);
+ }
+#endif
+
return PyFloat_FromDouble((double)tt);
}
@@ -1186,34 +1186,34 @@ _PyTime_GetProcessTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
#if defined(HAVE_CLOCK_GETTIME) \
&& (defined(CLOCK_PROCESS_CPUTIME_ID) || defined(CLOCK_PROF))
struct timespec ts;
-
- if (HAVE_CLOCK_GETTIME_RUNTIME) {
-
+
+ if (HAVE_CLOCK_GETTIME_RUNTIME) {
+
#ifdef CLOCK_PROF
- const clockid_t clk_id = CLOCK_PROF;
- const char *function = "clock_gettime(CLOCK_PROF)";
+ const clockid_t clk_id = CLOCK_PROF;
+ const char *function = "clock_gettime(CLOCK_PROF)";
#else
- const clockid_t clk_id = CLOCK_PROCESS_CPUTIME_ID;
- const char *function = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)";
-#endif
-
- if (clock_gettime(clk_id, &ts) == 0) {
- if (info) {
- struct timespec res;
- info->implementation = function;
- info->monotonic = 1;
- info->adjustable = 0;
- if (clock_getres(clk_id, &res)) {
- PyErr_SetFromErrno(PyExc_OSError);
- return -1;
- }
- info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
- }
-
- if (_PyTime_FromTimespec(tp, &ts) < 0) {
+ const clockid_t clk_id = CLOCK_PROCESS_CPUTIME_ID;
+ const char *function = "clock_gettime(CLOCK_PROCESS_CPUTIME_ID)";
+#endif
+
+ if (clock_gettime(clk_id, &ts) == 0) {
+ if (info) {
+ struct timespec res;
+ info->implementation = function;
+ info->monotonic = 1;
+ info->adjustable = 0;
+ if (clock_getres(clk_id, &res)) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return -1;
+ }
+ info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
+ }
+
+ if (_PyTime_FromTimespec(tp, &ts) < 0) {
return -1;
}
- return 0;
+ return 0;
}
}
#endif
@@ -1239,7 +1239,7 @@ _PyTime_GetProcessTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
return -1;
}
- _PyTime_t total = utime + stime;
+ _PyTime_t total = utime + stime;
*tp = total;
return 0;
}
@@ -1375,60 +1375,60 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
return 0;
}
-#elif defined(_AIX)
-#define HAVE_THREAD_TIME
-static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
-{
- /* bpo-40192: On AIX, thread_cputime() is preferred: it has nanosecond
- resolution, whereas clock_gettime(CLOCK_THREAD_CPUTIME_ID)
- has a resolution of 10 ms. */
- thread_cputime_t tc;
- if (thread_cputime(-1, &tc) != 0) {
- PyErr_SetFromErrno(PyExc_OSError);
- return -1;
- }
-
- if (info) {
- info->implementation = "thread_cputime()";
- info->monotonic = 1;
- info->adjustable = 0;
- info->resolution = 1e-9;
- }
- *tp = _PyTime_FromNanoseconds(tc.stime + tc.utime);
- return 0;
-}
-
-#elif defined(__sun) && defined(__SVR4)
-#define HAVE_THREAD_TIME
-static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
-{
- /* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always
- available; use gethrvtime() to substitute this functionality. */
- if (info) {
- info->implementation = "gethrvtime()";
- info->resolution = 1e-9;
- info->monotonic = 1;
- info->adjustable = 0;
- }
- *tp = _PyTime_FromNanoseconds(gethrvtime());
- return 0;
-}
-
+#elif defined(_AIX)
+#define HAVE_THREAD_TIME
+static int
+_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+{
+ /* bpo-40192: On AIX, thread_cputime() is preferred: it has nanosecond
+ resolution, whereas clock_gettime(CLOCK_THREAD_CPUTIME_ID)
+ has a resolution of 10 ms. */
+ thread_cputime_t tc;
+ if (thread_cputime(-1, &tc) != 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return -1;
+ }
+
+ if (info) {
+ info->implementation = "thread_cputime()";
+ info->monotonic = 1;
+ info->adjustable = 0;
+ info->resolution = 1e-9;
+ }
+ *tp = _PyTime_FromNanoseconds(tc.stime + tc.utime);
+ return 0;
+}
+
+#elif defined(__sun) && defined(__SVR4)
+#define HAVE_THREAD_TIME
+static int
+_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+{
+ /* bpo-35455: On Solaris, CLOCK_THREAD_CPUTIME_ID clock is not always
+ available; use gethrvtime() to substitute this functionality. */
+ if (info) {
+ info->implementation = "gethrvtime()";
+ info->resolution = 1e-9;
+ info->monotonic = 1;
+ info->adjustable = 0;
+ }
+ *tp = _PyTime_FromNanoseconds(gethrvtime());
+ return 0;
+}
+
#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
#define HAVE_THREAD_TIME
-
-#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
+
+#if defined(__APPLE__) && defined(__has_attribute) && __has_attribute(availability)
+static int
+_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
+ __attribute__((availability(macos, introduced=10.12)))
+ __attribute__((availability(ios, introduced=10.0)))
+ __attribute__((availability(tvos, introduced=10.0)))
+ __attribute__((availability(watchos, introduced=3.0)));
+#endif
+
static int
-_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
- __attribute__((availability(macos, introduced=10.12)))
- __attribute__((availability(ios, introduced=10.0)))
- __attribute__((availability(tvos, introduced=10.0)))
- __attribute__((availability(watchos, introduced=3.0)));
-#endif
-
-static int
_PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
{
struct timespec ts;
@@ -1459,15 +1459,15 @@ _PyTime_GetThreadTimeWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
#endif
#ifdef HAVE_THREAD_TIME
-#ifdef __APPLE__
-/*
- * The clock_* functions will be removed from the module
- * dict entirely when the C API is not available.
- */
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunguarded-availability"
-#endif
-
+#ifdef __APPLE__
+/*
+ * The clock_* functions will be removed from the module
+ * dict entirely when the C API is not available.
+ */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability"
+#endif
+
static PyObject *
time_thread_time(PyObject *self, PyObject *unused)
{
@@ -1498,14 +1498,14 @@ PyDoc_STRVAR(thread_time_ns_doc,
\n\
Thread time for profiling as nanoseconds:\n\
sum of the kernel and user-space CPU time.");
-
-#ifdef __APPLE__
-#pragma clang diagnostic pop
+
+#ifdef __APPLE__
+#pragma clang diagnostic pop
+#endif
+
#endif
-#endif
-
static PyObject *
time_get_clock_info(PyObject *self, PyObject *args)
{
@@ -1552,19 +1552,19 @@ time_get_clock_info(PyObject *self, PyObject *args)
}
#ifdef HAVE_THREAD_TIME
else if (strcmp(name, "thread_time") == 0) {
-
-#ifdef __APPLE__
- if (HAVE_CLOCK_GETTIME_RUNTIME) {
-#endif
- if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) {
- return NULL;
- }
-#ifdef __APPLE__
- } else {
- PyErr_SetString(PyExc_ValueError, "unknown clock");
+
+#ifdef __APPLE__
+ if (HAVE_CLOCK_GETTIME_RUNTIME) {
+#endif
+ if (_PyTime_GetThreadTimeWithInfo(&t, &info) < 0) {
+ return NULL;
+ }
+#ifdef __APPLE__
+ } else {
+ PyErr_SetString(PyExc_ValueError, "unknown clock");
return NULL;
}
-#endif
+#endif
}
#endif
else {
@@ -1633,7 +1633,7 @@ PyDoc_STRVAR(get_clock_info_doc,
\n\
Get information of the specified clock.");
-#ifndef HAVE_DECL_TZNAME
+#ifndef HAVE_DECL_TZNAME
static void
get_zone(char *zone, int n, struct tm *p)
{
@@ -1654,7 +1654,7 @@ get_gmtoff(time_t t, struct tm *p)
return timegm(p) - t;
#endif
}
-#endif // !HAVE_DECL_TZNAME
+#endif // !HAVE_DECL_TZNAME
static int
init_timezone(PyObject *m)
@@ -1677,7 +1677,7 @@ init_timezone(PyObject *m)
And I'm lazy and hate C so nyer.
*/
-#ifdef HAVE_DECL_TZNAME
+#ifdef HAVE_DECL_TZNAME
PyObject *otz0, *otz1;
tzset();
PyModule_AddIntConstant(m, "timezone", _Py_timezone);
@@ -1687,19 +1687,19 @@ init_timezone(PyObject *m)
PyModule_AddIntConstant(m, "altzone", _Py_timezone-3600);
#endif
PyModule_AddIntConstant(m, "daylight", _Py_daylight);
-#ifdef MS_WINDOWS
- TIME_ZONE_INFORMATION tzinfo = {0};
- GetTimeZoneInformation(&tzinfo);
- otz0 = PyUnicode_FromWideChar(tzinfo.StandardName, -1);
- if (otz0 == NULL) {
- return -1;
- }
- otz1 = PyUnicode_FromWideChar(tzinfo.DaylightName, -1);
- if (otz1 == NULL) {
- Py_DECREF(otz0);
- return -1;
- }
-#else
+#ifdef MS_WINDOWS
+ TIME_ZONE_INFORMATION tzinfo = {0};
+ GetTimeZoneInformation(&tzinfo);
+ otz0 = PyUnicode_FromWideChar(tzinfo.StandardName, -1);
+ if (otz0 == NULL) {
+ return -1;
+ }
+ otz1 = PyUnicode_FromWideChar(tzinfo.DaylightName, -1);
+ if (otz1 == NULL) {
+ Py_DECREF(otz0);
+ return -1;
+ }
+#else
otz0 = PyUnicode_DecodeLocale(_Py_tzname[0], "surrogateescape");
if (otz0 == NULL) {
return -1;
@@ -1709,59 +1709,59 @@ init_timezone(PyObject *m)
Py_DECREF(otz0);
return -1;
}
-#endif // MS_WINDOWS
+#endif // MS_WINDOWS
PyObject *tzname_obj = Py_BuildValue("(NN)", otz0, otz1);
if (tzname_obj == NULL) {
return -1;
}
PyModule_AddObject(m, "tzname", tzname_obj);
-#else // !HAVE_DECL_TZNAME
- static const time_t YEAR = (365 * 24 + 6) * 3600;
- time_t t;
- struct tm p;
- time_t janzone_t, julyzone_t;
- char janname[10], julyname[10];
- t = (time((time_t *)0) / YEAR) * YEAR;
- _PyTime_localtime(t, &p);
- get_zone(janname, 9, &p);
- janzone_t = -get_gmtoff(t, &p);
- janname[9] = '\0';
- t += YEAR/2;
- _PyTime_localtime(t, &p);
- get_zone(julyname, 9, &p);
- julyzone_t = -get_gmtoff(t, &p);
- julyname[9] = '\0';
-
- /* Sanity check, don't check for the validity of timezones.
- In practice, it should be more in range -12 hours .. +14 hours. */
+#else // !HAVE_DECL_TZNAME
+ static const time_t YEAR = (365 * 24 + 6) * 3600;
+ time_t t;
+ struct tm p;
+ time_t janzone_t, julyzone_t;
+ char janname[10], julyname[10];
+ t = (time((time_t *)0) / YEAR) * YEAR;
+ _PyTime_localtime(t, &p);
+ get_zone(janname, 9, &p);
+ janzone_t = -get_gmtoff(t, &p);
+ janname[9] = '\0';
+ t += YEAR/2;
+ _PyTime_localtime(t, &p);
+ get_zone(julyname, 9, &p);
+ julyzone_t = -get_gmtoff(t, &p);
+ julyname[9] = '\0';
+
+ /* Sanity check, don't check for the validity of timezones.
+ In practice, it should be more in range -12 hours .. +14 hours. */
#define MAX_TIMEZONE (48 * 3600)
- if (janzone_t < -MAX_TIMEZONE || janzone_t > MAX_TIMEZONE
- || julyzone_t < -MAX_TIMEZONE || julyzone_t > MAX_TIMEZONE)
- {
- PyErr_SetString(PyExc_RuntimeError, "invalid GMT offset");
- return -1;
- }
- int janzone = (int)janzone_t;
- int julyzone = (int)julyzone_t;
-
- PyObject *tzname_obj;
- if (janzone < julyzone) {
- /* DST is reversed in the southern hemisphere */
- PyModule_AddIntConstant(m, "timezone", julyzone);
- PyModule_AddIntConstant(m, "altzone", janzone);
- PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
- tzname_obj = Py_BuildValue("(zz)", julyname, janname);
- } else {
- PyModule_AddIntConstant(m, "timezone", janzone);
- PyModule_AddIntConstant(m, "altzone", julyzone);
- PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
- tzname_obj = Py_BuildValue("(zz)", janname, julyname);
- }
- if (tzname_obj == NULL) {
- return -1;
- }
- PyModule_AddObject(m, "tzname", tzname_obj);
-#endif // !HAVE_DECL_TZNAME
+ if (janzone_t < -MAX_TIMEZONE || janzone_t > MAX_TIMEZONE
+ || julyzone_t < -MAX_TIMEZONE || julyzone_t > MAX_TIMEZONE)
+ {
+ PyErr_SetString(PyExc_RuntimeError, "invalid GMT offset");
+ return -1;
+ }
+ int janzone = (int)janzone_t;
+ int julyzone = (int)julyzone_t;
+
+ PyObject *tzname_obj;
+ if (janzone < julyzone) {
+ /* DST is reversed in the southern hemisphere */
+ PyModule_AddIntConstant(m, "timezone", julyzone);
+ PyModule_AddIntConstant(m, "altzone", janzone);
+ PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
+ tzname_obj = Py_BuildValue("(zz)", julyname, janname);
+ } else {
+ PyModule_AddIntConstant(m, "timezone", janzone);
+ PyModule_AddIntConstant(m, "altzone", julyzone);
+ PyModule_AddIntConstant(m, "daylight", janzone != julyzone);
+ tzname_obj = Py_BuildValue("(zz)", janname, julyname);
+ }
+ if (tzname_obj == NULL) {
+ return -1;
+ }
+ PyModule_AddObject(m, "tzname", tzname_obj);
+#endif // !HAVE_DECL_TZNAME
if (PyErr_Occurred()) {
return -1;
@@ -1842,171 +1842,171 @@ if it is 1, the time is given in the DST time zone;\n\
if it is -1, mktime() should guess based on the date and time.\n");
-static int
-time_exec(PyObject *module)
-{
-#if defined(__APPLE__) && defined(HAVE_CLOCK_GETTIME)
- if (HAVE_CLOCK_GETTIME_RUNTIME) {
- /* pass: ^^^ cannot use '!' here */
- } else {
- PyObject* dct = PyModule_GetDict(module);
- if (dct == NULL) {
- return -1;
- }
-
- if (PyDict_DelItemString(dct, "clock_gettime") == -1) {
- PyErr_Clear();
- }
- if (PyDict_DelItemString(dct, "clock_gettime_ns") == -1) {
- PyErr_Clear();
- }
- if (PyDict_DelItemString(dct, "clock_settime") == -1) {
- PyErr_Clear();
- }
- if (PyDict_DelItemString(dct, "clock_settime_ns") == -1) {
- PyErr_Clear();
- }
- if (PyDict_DelItemString(dct, "clock_getres") == -1) {
- PyErr_Clear();
- }
- }
-#endif
-#if defined(__APPLE__) && defined(HAVE_THREAD_TIME)
- if (HAVE_CLOCK_GETTIME_RUNTIME) {
- /* pass: ^^^ cannot use '!' here */
- } else {
- PyObject* dct = PyModule_GetDict(module);
-
- if (PyDict_DelItemString(dct, "thread_time") == -1) {
- PyErr_Clear();
- }
- if (PyDict_DelItemString(dct, "thread_time_ns") == -1) {
- PyErr_Clear();
- }
- }
-#endif
+static int
+time_exec(PyObject *module)
+{
+#if defined(__APPLE__) && defined(HAVE_CLOCK_GETTIME)
+ if (HAVE_CLOCK_GETTIME_RUNTIME) {
+ /* pass: ^^^ cannot use '!' here */
+ } else {
+ PyObject* dct = PyModule_GetDict(module);
+ if (dct == NULL) {
+ return -1;
+ }
+
+ if (PyDict_DelItemString(dct, "clock_gettime") == -1) {
+ PyErr_Clear();
+ }
+ if (PyDict_DelItemString(dct, "clock_gettime_ns") == -1) {
+ PyErr_Clear();
+ }
+ if (PyDict_DelItemString(dct, "clock_settime") == -1) {
+ PyErr_Clear();
+ }
+ if (PyDict_DelItemString(dct, "clock_settime_ns") == -1) {
+ PyErr_Clear();
+ }
+ if (PyDict_DelItemString(dct, "clock_getres") == -1) {
+ PyErr_Clear();
+ }
+ }
+#endif
+#if defined(__APPLE__) && defined(HAVE_THREAD_TIME)
+ if (HAVE_CLOCK_GETTIME_RUNTIME) {
+ /* pass: ^^^ cannot use '!' here */
+ } else {
+ PyObject* dct = PyModule_GetDict(module);
+
+ if (PyDict_DelItemString(dct, "thread_time") == -1) {
+ PyErr_Clear();
+ }
+ if (PyDict_DelItemString(dct, "thread_time_ns") == -1) {
+ PyErr_Clear();
+ }
+ }
+#endif
/* Set, or reset, module variables like time.timezone */
- if (init_timezone(module) < 0) {
- return -1;
+ if (init_timezone(module) < 0) {
+ return -1;
}
#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_SETTIME) || defined(HAVE_CLOCK_GETRES)
- if (HAVE_CLOCK_GETTIME_RUNTIME) {
+ if (HAVE_CLOCK_GETTIME_RUNTIME) {
#ifdef CLOCK_REALTIME
- if (PyModule_AddIntMacro(module, CLOCK_REALTIME) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_REALTIME) < 0) {
+ return -1;
+ }
#endif
-
+
#ifdef CLOCK_MONOTONIC
-
- if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC) < 0) {
- return -1;
- }
-
+
+ if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC) < 0) {
+ return -1;
+ }
+
#endif
#ifdef CLOCK_MONOTONIC_RAW
- if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC_RAW) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC_RAW) < 0) {
+ return -1;
+ }
#endif
-
+
#ifdef CLOCK_HIGHRES
- if (PyModule_AddIntMacro(module, CLOCK_HIGHRES) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_HIGHRES) < 0) {
+ return -1;
+ }
#endif
#ifdef CLOCK_PROCESS_CPUTIME_ID
- if (PyModule_AddIntMacro(module, CLOCK_PROCESS_CPUTIME_ID) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_PROCESS_CPUTIME_ID) < 0) {
+ return -1;
+ }
#endif
-
+
#ifdef CLOCK_THREAD_CPUTIME_ID
- if (PyModule_AddIntMacro(module, CLOCK_THREAD_CPUTIME_ID) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_THREAD_CPUTIME_ID) < 0) {
+ return -1;
+ }
#endif
#ifdef CLOCK_PROF
- if (PyModule_AddIntMacro(module, CLOCK_PROF) < 0) {
- return -1;
- }
+ if (PyModule_AddIntMacro(module, CLOCK_PROF) < 0) {
+ return -1;
+ }
#endif
#ifdef CLOCK_BOOTTIME
- if (PyModule_AddIntMacro(module, CLOCK_BOOTTIME) < 0) {
- return -1;
- }
-#endif
-#ifdef CLOCK_TAI
- if (PyModule_AddIntMacro(module, CLOCK_TAI) < 0) {
- return -1;
- }
-#endif
+ if (PyModule_AddIntMacro(module, CLOCK_BOOTTIME) < 0) {
+ return -1;
+ }
+#endif
+#ifdef CLOCK_TAI
+ if (PyModule_AddIntMacro(module, CLOCK_TAI) < 0) {
+ return -1;
+ }
+#endif
#ifdef CLOCK_UPTIME
- if (PyModule_AddIntMacro(module, CLOCK_UPTIME) < 0) {
- return -1;
- }
-#endif
-#ifdef CLOCK_UPTIME_RAW
-
- if (PyModule_AddIntMacro(module, CLOCK_UPTIME_RAW) < 0) {
- return -1;
- }
-#endif
- }
+ if (PyModule_AddIntMacro(module, CLOCK_UPTIME) < 0) {
+ return -1;
+ }
+#endif
+#ifdef CLOCK_UPTIME_RAW
+
+ if (PyModule_AddIntMacro(module, CLOCK_UPTIME_RAW) < 0) {
+ return -1;
+ }
+#endif
+ }
#endif /* defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_SETTIME) || defined(HAVE_CLOCK_GETRES) */
if (!initialized) {
if (PyStructSequence_InitType2(&StructTimeType,
- &struct_time_type_desc) < 0) {
- return -1;
- }
+ &struct_time_type_desc) < 0) {
+ return -1;
+ }
+ }
+ if (PyModule_AddIntConstant(module, "_STRUCT_TM_ITEMS", 11)) {
+ return -1;
}
- if (PyModule_AddIntConstant(module, "_STRUCT_TM_ITEMS", 11)) {
- return -1;
- }
Py_INCREF(&StructTimeType);
- if (PyModule_AddObject(module, "struct_time", (PyObject*) &StructTimeType)) {
- Py_DECREF(&StructTimeType);
- return -1;
- }
+ if (PyModule_AddObject(module, "struct_time", (PyObject*) &StructTimeType)) {
+ Py_DECREF(&StructTimeType);
+ return -1;
+ }
initialized = 1;
-#if defined(__linux__) && !defined(__GLIBC__)
- struct tm tm;
- const time_t zero = 0;
- if (gmtime_r(&zero, &tm) != NULL)
- utc_string = tm.tm_zone;
-#endif
-
- return 0;
+#if defined(__linux__) && !defined(__GLIBC__)
+ struct tm tm;
+ const time_t zero = 0;
+ if (gmtime_r(&zero, &tm) != NULL)
+ utc_string = tm.tm_zone;
+#endif
+
+ return 0;
+}
+
+static struct PyModuleDef_Slot time_slots[] = {
+ {Py_mod_exec, time_exec},
+ {0, NULL}
+};
+
+static struct PyModuleDef timemodule = {
+ PyModuleDef_HEAD_INIT,
+ "time",
+ module_doc,
+ 0,
+ time_methods,
+ time_slots,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC
+PyInit_time(void)
+{
+ return PyModuleDef_Init(&timemodule);
}
-static struct PyModuleDef_Slot time_slots[] = {
- {Py_mod_exec, time_exec},
- {0, NULL}
-};
-
-static struct PyModuleDef timemodule = {
- PyModuleDef_HEAD_INIT,
- "time",
- module_doc,
- 0,
- time_methods,
- time_slots,
- NULL,
- NULL,
- NULL
-};
-
-PyMODINIT_FUNC
-PyInit_time(void)
-{
- return PyModuleDef_Init(&timemodule);
-}
-
/* Implement pysleep() for various platforms.
When interrupted (or when another error occurs), return -1 and
set an exception; else return 0. */