Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 82921) +++ Python/pythonrun.c (working copy) @@ -268,6 +268,8 @@ /* Initialize _warnings. */ _PyWarnings_Init(); + _PyTime_Init(); + initfsencoding(); if (install_sigs) Index: PCbuild/pythoncore.vcproj =================================================================== --- PCbuild/pythoncore.vcproj (revision 82921) +++ PCbuild/pythoncore.vcproj (working copy) @@ -876,6 +876,10 @@ > + + @@ -1768,6 +1772,10 @@ > + + Index: Include/Python.h =================================================================== --- Include/Python.h (revision 82921) +++ Include/Python.h (working copy) @@ -61,6 +61,7 @@ #error "PYMALLOC_DEBUG requires WITH_PYMALLOC" #endif #include "pymath.h" +#include "pytime.h" #include "pymem.h" #include "object.h" Index: Makefile.pre.in =================================================================== --- Makefile.pre.in (revision 82921) +++ Makefile.pre.in (working copy) @@ -314,6 +314,7 @@ Python/pymath.o \ Python/pystate.o \ Python/pythonrun.o \ + Python/pytime.o \ Python/structmember.o \ Python/symtable.o \ Python/sysmodule.o \ @@ -698,6 +699,7 @@ Include/pystrtod.h \ Include/pythonrun.h \ Include/pythread.h \ + Include/pytime.h \ Include/rangeobject.h \ Include/setobject.h \ Include/sliceobject.h \ Index: Modules/datetimemodule.c =================================================================== --- Modules/datetimemodule.c (revision 82921) +++ Modules/datetimemodule.c (working copy) @@ -8,7 +8,7 @@ #include -#include "timefuncs.h" +#include "_time.h" /* Differentiate between building the core module and building extension * modules. @@ -4166,37 +4166,10 @@ static PyObject * datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo) { -#ifdef HAVE_GETTIMEOFDAY - struct timeval t; - -#ifdef GETTIMEOFDAY_NO_TZ - gettimeofday(&t); -#else - gettimeofday(&t, (struct timezone *)NULL); -#endif + _PyTime_timeval t; + _PyTime_gettimeofday(&t); return datetime_from_timet_and_us(cls, f, t.tv_sec, (int)t.tv_usec, tzinfo); - -#else /* ! HAVE_GETTIMEOFDAY */ - /* No flavor of gettimeofday exists on this platform. Python's - * time.time() does a lot of other platform tricks to get the - * best time it can on the platform, and we're not going to do - * better than that (if we could, the better code would belong - * in time.time()!) We're limited by the precision of a double, - * though. - */ - PyObject *time; - double dtime; - - time = time_time(); - if (time == NULL) - return NULL; - dtime = PyFloat_AsDouble(time); - Py_DECREF(time); - if (dtime == -1.0 && PyErr_Occurred()) - return NULL; - return datetime_from_timestamp(cls, f, dtime, tzinfo); -#endif /* ! HAVE_GETTIMEOFDAY */ } /* Return best possible local time -- this isn't constrained by the Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 82921) +++ Modules/timemodule.c (working copy) @@ -3,22 +3,10 @@ #include "Python.h" #include "structseq.h" -#include "timefuncs.h" +#include "_time.h" #define TZNAME_ENCODING "utf-8" -#ifdef __APPLE__ -#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME) - /* - * floattime falls back to ftime when getttimeofday fails because the latter - * might fail on some platforms. This fallback is unwanted on MacOSX because - * that makes it impossible to use a binary build on OSX 10.4 on earlier - * releases of the OS. Therefore claim we don't support ftime. - */ -# undef HAVE_FTIME -#endif -#endif - #include #ifdef HAVE_SYS_TYPES_H @@ -29,13 +17,6 @@ #include #endif -#ifdef HAVE_FTIME -#include -#if !defined(MS_WINDOWS) && !defined(PYOS_OS2) -extern int ftime(struct timeb *); -#endif /* MS_WINDOWS */ -#endif /* HAVE_FTIME */ - #if defined(__WATCOMC__) && !defined(__QNX__) #include #else @@ -946,44 +927,12 @@ return m; } - -/* Implement floattime() for various platforms */ - static double floattime(void) { - /* There are three ways to get the time: - (1) gettimeofday() -- resolution in microseconds - (2) ftime() -- resolution in milliseconds - (3) time() -- resolution in seconds - In all cases the return value is a float in seconds. - Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may - fail, so we fall back on ftime() or time(). - Note: clock resolution does not imply clock accuracy! */ -#ifdef HAVE_GETTIMEOFDAY - { - struct timeval t; -#ifdef GETTIMEOFDAY_NO_TZ - if (gettimeofday(&t) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#else /* !GETTIMEOFDAY_NO_TZ */ - if (gettimeofday(&t, (struct timezone *)NULL) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#endif /* !GETTIMEOFDAY_NO_TZ */ - } - -#endif /* !HAVE_GETTIMEOFDAY */ - { -#if defined(HAVE_FTIME) - struct timeb t; - ftime(&t); - return (double)t.time + (double)t.millitm * (double)0.001; -#else /* !HAVE_FTIME */ - time_t secs; - time(&secs); - return (double)secs; -#endif /* !HAVE_FTIME */ - } + _PyTime_timeval t; + _PyTime_gettimeofday(&t); + return (double)t.tv_sec + t.tv_usec*0.000001; }