Commit 7ba5e810 authored by Mark Hammond's avatar Mark Hammond

Ensure we also build on VC7. Involves replacing largeint.h helper functions...

Ensure we also build on VC7.  Involves replacing largeint.h helper functions with msvc's native 64 bit integers.
parent a8d73847
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#ifdef MS_WIN32 #ifdef MS_WIN32
#include <windows.h> #include <windows.h>
#include <largeint.h>
#include <direct.h> /* for getcwd() */ #include <direct.h> /* for getcwd() */
typedef __int64 hs_time; typedef __int64 hs_time;
#define GETTIMEOFDAY(P_HS_TIME) \ #define GETTIMEOFDAY(P_HS_TIME) \
......
...@@ -51,7 +51,6 @@ extern int ftime(struct timeb *); ...@@ -51,7 +51,6 @@ extern int ftime(struct timeb *);
#if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__) #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__)
/* Win32 has better clock replacement /* Win32 has better clock replacement
XXX Win64 does not yet, but might when the platform matures. */ XXX Win64 does not yet, but might when the platform matures. */
#include <largeint.h>
#undef HAVE_CLOCK /* We have our own version down below */ #undef HAVE_CLOCK /* We have our own version down below */
#endif /* MS_WIN32 && !MS_WIN64 */ #endif /* MS_WIN32 && !MS_WIN64 */
...@@ -144,36 +143,33 @@ time_clock(PyObject *self, PyObject *args) ...@@ -144,36 +143,33 @@ time_clock(PyObject *self, PyObject *args)
#endif /* HAVE_CLOCK */ #endif /* HAVE_CLOCK */
#if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__) #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__)
/* Due to Mark Hammond */ /* Due to Mark Hammond and Tim Peters */
static PyObject * static PyObject *
time_clock(PyObject *self, PyObject *args) time_clock(PyObject *self, PyObject *args)
{ {
static LARGE_INTEGER ctrStart; static LONG_LONG ctrStart;
static LARGE_INTEGER divisor = {0,0}; static double divisor = 0.0;
LARGE_INTEGER now, diff, rem; LONG_LONG now;
double diff;
assert(sizeof(LONG_LONG) == sizeof(LARGE_INTEGER));
if (!PyArg_ParseTuple(args, ":clock")) if (!PyArg_ParseTuple(args, ":clock"))
return NULL; return NULL;
if (LargeIntegerEqualToZero(divisor)) { if (divisor == 0.0) {
QueryPerformanceCounter(&ctrStart); LONG_LONG freq;
if (!QueryPerformanceFrequency(&divisor) || QueryPerformanceCounter((LARGE_INTEGER*)&ctrStart);
LargeIntegerEqualToZero(divisor)) { if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq) ||
/* Unlikely to happen - freq == 0) {
this works on all intel machines at least! /* Unlikely to happen - this works on all intel
Revert to clock() */ machines at least! Revert to clock() */
return PyFloat_FromDouble(clock()); return PyFloat_FromDouble(clock());
} }
divisor = (double)freq;
} }
QueryPerformanceCounter(&now); QueryPerformanceCounter((LARGE_INTEGER*)&now);
diff = LargeIntegerSubtract(now, ctrStart); diff = (double)(now - ctrStart);
diff = LargeIntegerDivide(diff, divisor, &rem); return PyFloat_FromDouble(diff / divisor);
/* XXX - we assume both divide results fit in 32 bits. This is
true on Intels. First person who can afford a machine that
doesnt deserves to fix it :-)
*/
return PyFloat_FromDouble((double)diff.LowPart +
((double)rem.LowPart / (double)divisor.LowPart));
} }
#define HAVE_CLOCK /* So it gets included in the methods */ #define HAVE_CLOCK /* So it gets included in the methods */
......
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