Commit 9122fdd8 authored by Victor Stinner's avatar Victor Stinner

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