[Python-checkins] cpython: Issue #9642: Fix the definition of time.clock() on Windows

victor.stinner python-checkins at python.org
Mon Jul 4 14:03:52 CEST 2011


http://hg.python.org/cpython/rev/75b18b10064f
changeset:   71192:75b18b10064f
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Mon Jul 04 13:55:40 2011 +0200
summary:
  Issue #9642: Fix the definition of time.clock() on Windows

Don't unset and set againt the HAVE_CLOCK define, reorder the #if tests
instead. Fix also the definition of the timezone encoding.

files:
  Modules/timemodule.c |  54 ++++++++++++++-----------------
  1 files changed, 25 insertions(+), 29 deletions(-)


diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -3,8 +3,6 @@
 #include "Python.h"
 #include "_time.h"
 
-#define TZNAME_ENCODING "utf-8"
-
 #include <ctype.h>
 
 #ifdef HAVE_SYS_TYPES_H
@@ -45,12 +43,11 @@
 #endif /* MS_WINDOWS */
 #endif /* !__WATCOMC__ || __QNX__ */
 
-#if defined(MS_WINDOWS) && !defined(__BORLANDC__)
-/* Win32 has better clock replacement; we have our own version below. */
-#undef HAVE_CLOCK
-#undef TZNAME_ENCODING
-#define TZNAME_ENCODING "mbcs"
-#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
+#if defined(MS_WINDOWS)
+#  define TZNAME_ENCODING "mbcs"
+#else
+#  define TZNAME_ENCODING "utf-8"
+#endif
 
 #if defined(PYOS_OS2)
 #define INCL_DOS
@@ -84,25 +81,9 @@
 Return the current time in seconds since the Epoch.\n\
 Fractions of a second may be present if the system clock provides them.");
 
-#ifdef HAVE_CLOCK
-
-#ifndef CLOCKS_PER_SEC
-#ifdef CLK_TCK
-#define CLOCKS_PER_SEC CLK_TCK
-#else
-#define CLOCKS_PER_SEC 1000000
-#endif
-#endif
-
-static PyObject *
-time_clock(PyObject *self, PyObject *unused)
-{
-    return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
-}
-#endif /* HAVE_CLOCK */
-
 #if defined(MS_WINDOWS) && !defined(__BORLANDC__)
-/* Due to Mark Hammond and Tim Peters */
+/* Win32 has better clock replacement; we have our own version, due to Mark
+   Hammond and Tim Peters */
 static PyObject *
 time_clock(PyObject *self, PyObject *unused)
 {
@@ -127,8 +108,23 @@
     return PyFloat_FromDouble(diff / divisor);
 }
 
-#define HAVE_CLOCK /* So it gets included in the methods */
-#endif /* MS_WINDOWS && !defined(__BORLANDC__) */
+#elif defined(HAVE_CLOCK)
+
+#ifndef CLOCKS_PER_SEC
+#ifdef CLK_TCK
+#define CLOCKS_PER_SEC CLK_TCK
+#else
+#define CLOCKS_PER_SEC 1000000
+#endif
+#endif
+
+static PyObject *
+time_clock(PyObject *self, PyObject *unused)
+{
+    return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
+}
+#endif /* HAVE_CLOCK */
+
 
 #ifdef HAVE_CLOCK
 PyDoc_STRVAR(clock_doc,
@@ -784,7 +780,7 @@
 
 static PyMethodDef time_methods[] = {
     {"time",            time_time, METH_NOARGS, time_doc},
-#ifdef HAVE_CLOCK
+#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) || defined(HAVE_CLOCK)
     {"clock",           time_clock, METH_NOARGS, clock_doc},
 #endif
     {"sleep",           time_sleep, METH_VARARGS, sleep_doc},

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list