@@ -51,7 +51,6 @@ extern int ftime(struct timeb *);
5151#if defined(MS_WIN32 ) && !defined(MS_WIN64 ) && !defined(__BORLANDC__ )
5252/* Win32 has better clock replacement
5353 XXX Win64 does not yet, but might when the platform matures. */
54- #include <largeint.h>
5554#undef HAVE_CLOCK /* We have our own version down below */
5655#endif /* MS_WIN32 && !MS_WIN64 */
5756
@@ -144,36 +143,33 @@ time_clock(PyObject *self, PyObject *args)
144143#endif /* HAVE_CLOCK */
145144
146145#if defined(MS_WIN32 ) && !defined(MS_WIN64 ) && !defined(__BORLANDC__ )
147- /* Due to Mark Hammond */
146+ /* Due to Mark Hammond and Tim Peters */
148147static PyObject *
149148time_clock (PyObject * self , PyObject * args )
150149{
151- static LARGE_INTEGER ctrStart ;
152- static LARGE_INTEGER divisor = {0 ,0 };
153- LARGE_INTEGER now , diff , rem ;
150+ static LONG_LONG ctrStart ;
151+ static double divisor = 0.0 ;
152+ LONG_LONG now ;
153+ double diff ;
154154
155+ assert (sizeof (LONG_LONG ) == sizeof (LARGE_INTEGER ));
155156 if (!PyArg_ParseTuple (args , ":clock" ))
156157 return NULL ;
157158
158- if (LargeIntegerEqualToZero ( divisor ) ) {
159- QueryPerformanceCounter ( & ctrStart ) ;
160- if (! QueryPerformanceFrequency ( & divisor ) ||
161- LargeIntegerEqualToZero ( divisor )) {
162- /* Unlikely to happen -
163- this works on all intel machines at least!
164- Revert to clock() */
159+ if (divisor == 0.0 ) {
160+ LONG_LONG freq ;
161+ QueryPerformanceCounter (( LARGE_INTEGER * ) & ctrStart );
162+ if (! QueryPerformanceFrequency (( LARGE_INTEGER * ) & freq ) ||
163+ freq == 0 ) {
164+ /* Unlikely to happen - this works on all intel
165+ machines at least! Revert to clock() */
165166 return PyFloat_FromDouble (clock ());
166167 }
168+ divisor = (double )freq ;
167169 }
168- QueryPerformanceCounter (& now );
169- diff = LargeIntegerSubtract (now , ctrStart );
170- diff = LargeIntegerDivide (diff , divisor , & rem );
171- /* XXX - we assume both divide results fit in 32 bits. This is
172- true on Intels. First person who can afford a machine that
173- doesnt deserves to fix it :-)
174- */
175- return PyFloat_FromDouble ((double )diff .LowPart +
176- ((double )rem .LowPart / (double )divisor .LowPart ));
170+ QueryPerformanceCounter ((LARGE_INTEGER * )& now );
171+ diff = (double )(now - ctrStart );
172+ return PyFloat_FromDouble (diff / divisor );
177173}
178174
179175#define HAVE_CLOCK /* So it gets included in the methods */
0 commit comments