[Python-checkins] CVS: python/dist/src/Modules timemodule.c,2.121,2.122
Tim Peters
tim_one@users.sourceforge.net
Tue, 12 Feb 2002 21:14:20 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv21638/python/Modules
Modified Files:
timemodule.c
Log Message:
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.
Index: timemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/timemodule.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -d -r2.121 -r2.122
*** timemodule.c 12 Feb 2002 04:02:33 -0000 2.121
--- timemodule.c 13 Feb 2002 05:14:18 -0000 2.122
***************
*** 148,173 ****
time_clock(PyObject *self, PyObject *args)
{
! 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 (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((LARGE_INTEGER*)&now);
! diff = (double)(now - ctrStart);
return PyFloat_FromDouble(diff / divisor);
}
--- 148,171 ----
time_clock(PyObject *self, PyObject *args)
{
! static LARGE_INTEGER ctrStart;
static double divisor = 0.0;
! LARGE_INTEGER now;
double diff;
if (!PyArg_ParseTuple(args, ":clock"))
return NULL;
if (divisor == 0.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.QuadPart;
}
! QueryPerformanceCounter(&now);
! diff = (double)(now.QuadPart - ctrStart.QuadPart);
return PyFloat_FromDouble(diff / divisor);
}
***************
*** 221,225 ****
9,
};
!
static PyTypeObject StructTimeType;
--- 219,223 ----
9,
};
!
static PyTypeObject StructTimeType;
***************
*** 230,234 ****
if (v == NULL)
return NULL;
!
#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
--- 228,232 ----
if (v == NULL)
return NULL;
!
#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))