diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2002-02-12 04:02:33 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2002-02-12 04:02:33 (GMT) |
commit | 7ba5e810fd7d7bbfcf5aeffcf2f397398d562c32 (patch) | |
tree | 436465f5dbb490d9ef63dbc05dd1f89fbf8f8b25 /Modules/timemodule.c | |
parent | a8d73847c47405aa026e19ceaeea63c2d639dea4 (diff) | |
download | cpython-7ba5e810fd7d7bbfcf5aeffcf2f397398d562c32.zip cpython-7ba5e810fd7d7bbfcf5aeffcf2f397398d562c32.tar.gz cpython-7ba5e810fd7d7bbfcf5aeffcf2f397398d562c32.tar.bz2 |
Ensure we also build on VC7. Involves replacing largeint.h helper functions with msvc's native 64 bit integers.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 6841b0f..b009ea1 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -51,7 +51,6 @@ extern int ftime(struct timeb *); #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__) /* Win32 has better clock replacement XXX Win64 does not yet, but might when the platform matures. */ -#include <largeint.h> #undef HAVE_CLOCK /* We have our own version down below */ #endif /* MS_WIN32 && !MS_WIN64 */ @@ -144,36 +143,33 @@ time_clock(PyObject *self, PyObject *args) #endif /* HAVE_CLOCK */ #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__) -/* Due to Mark Hammond */ +/* Due to Mark Hammond and Tim Peters */ static PyObject * time_clock(PyObject *self, PyObject *args) { - static LARGE_INTEGER ctrStart; - static LARGE_INTEGER divisor = {0,0}; - LARGE_INTEGER now, diff, rem; + static LONG_LONG ctrStart; + static double divisor = 0.0; + LONG_LONG now; + double diff; + assert(sizeof(LONG_LONG) == sizeof(LARGE_INTEGER)); if (!PyArg_ParseTuple(args, ":clock")) return NULL; - if (LargeIntegerEqualToZero(divisor)) { - QueryPerformanceCounter(&ctrStart); - if (!QueryPerformanceFrequency(&divisor) || - LargeIntegerEqualToZero(divisor)) { - /* Unlikely to happen - - this works on all intel machines at least! - Revert to clock() */ + if (divisor == 0.0) { + LONG_LONG freq; + QueryPerformanceCounter((LARGE_INTEGER*)&ctrStart); + if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq) || + freq == 0) { + /* Unlikely to happen - this works on all intel + machines at least! Revert to clock() */ return PyFloat_FromDouble(clock()); } + divisor = (double)freq; } - QueryPerformanceCounter(&now); - diff = LargeIntegerSubtract(now, ctrStart); - diff = LargeIntegerDivide(diff, divisor, &rem); - /* 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)); + QueryPerformanceCounter((LARGE_INTEGER*)&now); + diff = (double)(now - ctrStart); + return PyFloat_FromDouble(diff / divisor); } #define HAVE_CLOCK /* So it gets included in the methods */ |