mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
Remove all but one use of the module dict.
This commit is contained in:
parent
d63e504d33
commit
9bb7432114
1 changed files with 38 additions and 44 deletions
|
|
@ -560,17 +560,6 @@ static PyMethodDef time_methods[] = {
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
ins(PyObject *d, char *name, PyObject *v)
|
|
||||||
{
|
|
||||||
/* Don't worry too much about errors, they'll be caught by the
|
|
||||||
* caller of inittime().
|
|
||||||
*/
|
|
||||||
if (v)
|
|
||||||
PyDict_SetItemString(d, name, v);
|
|
||||||
Py_XDECREF(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char module_doc[] =
|
static char module_doc[] =
|
||||||
"This module provides various functions to manipulate time values.\n\
|
"This module provides various functions to manipulate time values.\n\
|
||||||
|
|
@ -621,34 +610,35 @@ strptime() -- parse string to time tuple according to format specification\n\
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
inittime(void)
|
inittime(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d;
|
PyObject *m;
|
||||||
char *p;
|
char *p;
|
||||||
m = Py_InitModule3("time", time_methods, module_doc);
|
m = Py_InitModule3("time", time_methods, module_doc);
|
||||||
d = PyModule_GetDict(m);
|
|
||||||
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */
|
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */
|
||||||
p = Py_GETENV("PYTHONY2K");
|
p = Py_GETENV("PYTHONY2K");
|
||||||
ins(d, "accept2dyear", PyInt_FromLong((long) (!p || !*p)));
|
PyModule_AddIntConstant(m, "accept2dyear", (long) (!p || !*p));
|
||||||
/* Squirrel away the module's dictionary for the y2k check */
|
/* Squirrel away the module's dictionary for the y2k check */
|
||||||
Py_INCREF(d);
|
moddict = PyModule_GetDict(m);
|
||||||
moddict = d;
|
Py_INCREF(moddict);
|
||||||
#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__)
|
#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__)
|
||||||
tzset();
|
tzset();
|
||||||
#ifdef PYOS_OS2
|
#ifdef PYOS_OS2
|
||||||
ins(d, "timezone", PyInt_FromLong((long)_timezone));
|
PyModule_AddIntConstant(m, "timezone", _timezone);
|
||||||
#else /* !PYOS_OS2 */
|
#else /* !PYOS_OS2 */
|
||||||
ins(d, "timezone", PyInt_FromLong((long)timezone));
|
PyModule_AddIntConstant(m, "timezone", timezone);
|
||||||
#endif /* PYOS_OS2 */
|
#endif /* PYOS_OS2 */
|
||||||
#ifdef HAVE_ALTZONE
|
#ifdef HAVE_ALTZONE
|
||||||
ins(d, "altzone", PyInt_FromLong((long)altzone));
|
PyModule_AddIntConstant(m, "altzone", altzone);
|
||||||
#else
|
#else
|
||||||
#ifdef PYOS_OS2
|
#ifdef PYOS_OS2
|
||||||
ins(d, "altzone", PyInt_FromLong((long)_timezone-3600));
|
PyModule_AddIntConstant(m, "altzone", _timezone-3600);
|
||||||
#else /* !PYOS_OS2 */
|
#else /* !PYOS_OS2 */
|
||||||
ins(d, "altzone", PyInt_FromLong((long)timezone-3600));
|
PyModule_AddIntConstant(m, "altzone", timezone-3600);
|
||||||
#endif /* PYOS_OS2 */
|
#endif /* PYOS_OS2 */
|
||||||
#endif
|
#endif
|
||||||
ins(d, "daylight", PyInt_FromLong((long)daylight));
|
PyModule_AddIntConstant(m, "daylight", daylight);
|
||||||
ins(d, "tzname", Py_BuildValue("(zz)", tzname[0], tzname[1]));
|
PyModule_AddObject(m, "tzname",
|
||||||
|
Py_BuildValue("(zz)", tzname[0], tzname[1]));
|
||||||
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
|
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
|
||||||
#ifdef HAVE_TM_ZONE
|
#ifdef HAVE_TM_ZONE
|
||||||
{
|
{
|
||||||
|
|
@ -670,19 +660,21 @@ inittime(void)
|
||||||
|
|
||||||
if( janzone < julyzone ) {
|
if( janzone < julyzone ) {
|
||||||
/* DST is reversed in the southern hemisphere */
|
/* DST is reversed in the southern hemisphere */
|
||||||
ins(d, "timezone", PyInt_FromLong(julyzone));
|
PyModule_AddIntConstant(m, "timezone", julyzone);
|
||||||
ins(d, "altzone", PyInt_FromLong(janzone));
|
PyModule_AddIntConstant(m, "altzone", janzone);
|
||||||
ins(d, "daylight",
|
PyModule_AddIntConstant(m, "daylight",
|
||||||
PyInt_FromLong((long)(janzone != julyzone)));
|
janzone != julyzone);
|
||||||
ins(d, "tzname",
|
PyModule_AddObject(m, "tzname",
|
||||||
Py_BuildValue("(zz)", julyname, janname));
|
Py_BuildValue("(zz)",
|
||||||
|
julyname, janname));
|
||||||
} else {
|
} else {
|
||||||
ins(d, "timezone", PyInt_FromLong(janzone));
|
PyModule_AddIntConstant(m, "timezone", janzone);
|
||||||
ins(d, "altzone", PyInt_FromLong(julyzone));
|
PyModule_AddIntConstant(m, "altzone", julyzone);
|
||||||
ins(d, "daylight",
|
PyModule_AddIntConstant(m, "daylight",
|
||||||
PyInt_FromLong((long)(janzone != julyzone)));
|
janzone != julyzone);
|
||||||
ins(d, "tzname",
|
PyModule_AddObject(m, "tzname",
|
||||||
Py_BuildValue("(zz)", janname, julyname));
|
Py_BuildValue("(zz)",
|
||||||
|
janname, julyname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
@ -692,23 +684,25 @@ inittime(void)
|
||||||
** we're looking for:-( )
|
** we're looking for:-( )
|
||||||
*/
|
*/
|
||||||
initmactimezone();
|
initmactimezone();
|
||||||
ins(d, "timezone", PyInt_FromLong(timezone));
|
PyModule_AddIntConstant(m, "timezone", timezone);
|
||||||
ins(d, "altzone", PyInt_FromLong(timezone));
|
PyModule_AddIntConstant(m, "altzone", timezone);
|
||||||
ins(d, "daylight", PyInt_FromLong((long)0));
|
PyModule_AddIntConstant(m, "daylight", 0);
|
||||||
ins(d, "tzname", Py_BuildValue("(zz)", "", ""));
|
PyModule_AddObject(m, "tzname", Py_BuildValue("(zz)", "", ""));
|
||||||
#endif /* macintosh */
|
#endif /* macintosh */
|
||||||
#endif /* HAVE_TM_ZONE */
|
#endif /* HAVE_TM_ZONE */
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
tzset();
|
tzset();
|
||||||
ins(d, "timezone", PyInt_FromLong(_timezone));
|
PyModule_AddIntConstant(m, "timezone", _timezone);
|
||||||
ins(d, "altzone", PyInt_FromLong(_timezone));
|
PyModule_AddIntConstant(m, "altzone", _timezone);
|
||||||
ins(d, "daylight", PyInt_FromLong(_daylight));
|
PyModule_AddIntConstant(m, "daylight", _daylight);
|
||||||
ins(d, "tzname", Py_BuildValue("(zz)", _tzname[0], _tzname[1]));
|
PyModule_AddObject(m, "tzname",
|
||||||
|
Py_BuildValue("(zz)", _tzname[0], _tzname[1]));
|
||||||
#endif /* __CYGWIN__ */
|
#endif /* __CYGWIN__ */
|
||||||
#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
|
#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
|
||||||
|
|
||||||
PyStructSequence_InitType(&StructTimeType, &struct_time_type_desc);
|
PyStructSequence_InitType(&StructTimeType, &struct_time_type_desc);
|
||||||
PyDict_SetItemString(d, "struct_time", (PyObject*) &StructTimeType);
|
Py_INCREF(&StructTimeType);
|
||||||
|
PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue