Index: Modules/datetimemodule.c =================================================================== --- Modules/datetimemodule.c (revision 52355) +++ Modules/datetimemodule.c (working copy) @@ -100,6 +100,9 @@ static PyTypeObject PyDateTime_TimeType; static PyTypeObject PyDateTime_TZInfoType; +/* time module imported in datetime module initialisation */ +static PyObject *time_module = NULL; + /* --------------------------------------------------------------------------- * Math utilities. */ @@ -1303,12 +1306,8 @@ if (_PyString_Resize(&newfmt, usednew) < 0) goto Done; { - PyObject *time = PyImport_ImportModule("time"); - if (time == NULL) - goto Done; - result = PyObject_CallMethod(time, "strftime", "OO", + result = PyObject_CallMethod(time_module, "strftime", "OO", newfmt, timetuple); - Py_DECREF(time); } Done: Py_XDECREF(zreplacement); @@ -1350,14 +1349,7 @@ static PyObject * time_time(void) { - PyObject *result = NULL; - PyObject *time = PyImport_ImportModule("time"); - - if (time != NULL) { - result = PyObject_CallMethod(time, "time", "()"); - Py_DECREF(time); - } - return result; + return PyObject_CallMethod(time_module, "time", "()"); } /* Build a time.struct_time. The weekday and day number are automatically @@ -1366,21 +1358,13 @@ static PyObject * build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag) { - PyObject *time; - PyObject *result = NULL; - - time = PyImport_ImportModule("time"); - if (time != NULL) { - result = PyObject_CallMethod(time, "struct_time", - "((iiiiiiiii))", - y, m, d, - hh, mm, ss, - weekday(y, m, d), - days_before_month(y, m) + d, - dstflag); - Py_DECREF(time); - } - return result; + return PyObject_CallMethod(time_module, "struct_time", + "((iiiiiiiii))", + y, m, d, + hh, mm, ss, + weekday(y, m, d), + days_before_month(y, m) + d, + dstflag); } /* --------------------------------------------------------------------------- @@ -3821,10 +3805,7 @@ if (!PyArg_ParseTuple(args, "ss:strptime", &string, &format)) return NULL; - if ((module = PyImport_ImportModule("time")) == NULL) - return NULL; - obj = PyObject_CallMethod(module, "strptime", "ss", string, format); - Py_DECREF(module); + obj = PyObject_CallMethod(time_module,"strptime", "ss", string, format); if (obj != NULL) { int i, good_timetuple = 1; @@ -4629,6 +4610,10 @@ PyObject *d; /* its dict */ PyObject *x; + time_module = PyImport_ImportModule("time"); + if (time_module == NULL) + return; + m = Py_InitModule3("datetime", module_methods, "Fast implementation of the datetime type."); if (m == NULL)