diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-02-13 05:14:18 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-02-13 05:14:18 (GMT) |
commit | 9ad4b688eca7b80ba00c408089593bba553ed73e (patch) | |
tree | 3491f4b2119a011e4417e06d1321d1eb21de7e21 /Modules | |
parent | 246debbbc276a7025e48bddb2e6fecafbcb9f522 (diff) | |
download | cpython-9ad4b688eca7b80ba00c408089593bba553ed73e.zip cpython-9ad4b688eca7b80ba00c408089593bba553ed73e.tar.gz cpython-9ad4b688eca7b80ba00c408089593bba553ed73e.tar.bz2 |
Windows time_clock(): rewrite to get rid of horrid casting tricks.
Don't blame Mark! The horrid casting tricks were my idea to begin with.
The rewrite works fine under VC6, and I *expect* will work fine under VC7.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/timemodule.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index b009ea1..6647ecc 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -147,28 +147,26 @@ time_clock(PyObject *self, PyObject *args) static PyObject * time_clock(PyObject *self, PyObject *args) { - static LONG_LONG ctrStart; + static LARGE_INTEGER ctrStart; static double divisor = 0.0; - LONG_LONG now; + LARGE_INTEGER now; double diff; - assert(sizeof(LONG_LONG) == sizeof(LARGE_INTEGER)); if (!PyArg_ParseTuple(args, ":clock")) return NULL; if (divisor == 0.0) { - LONG_LONG freq; - QueryPerformanceCounter((LARGE_INTEGER*)&ctrStart); - if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq) || - freq == 0) { + LARGE_INTEGER freq; + QueryPerformanceCounter(&ctrStart); + if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0) { /* Unlikely to happen - this works on all intel machines at least! Revert to clock() */ return PyFloat_FromDouble(clock()); } - divisor = (double)freq; + divisor = (double)freq.QuadPart; } - QueryPerformanceCounter((LARGE_INTEGER*)&now); - diff = (double)(now - ctrStart); + QueryPerformanceCounter(&now); + diff = (double)(now.QuadPart - ctrStart.QuadPart); return PyFloat_FromDouble(diff / divisor); } @@ -220,7 +218,7 @@ static PyStructSequence_Desc struct_time_type_desc = { struct_time_type_fields, 9, }; - + static PyTypeObject StructTimeType; static PyObject * @@ -229,7 +227,7 @@ tmtotuple(struct tm *p) PyObject *v = PyStructSequence_New(&StructTimeType); if (v == NULL) return NULL; - + #define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val)) SET(0, p->tm_year + 1900); |