summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
commit1a21451b1d73b65af949193208372e86bf308411 (patch)
tree8e98d7be9e249b011ae9380479656e5284ec0234 /Modules/datetimemodule.c
parentcdf94635d7e364f9ce1905bafa5b540f4d16147c (diff)
downloadcpython-1a21451b1d73b65af949193208372e86bf308411.zip
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.gz
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.bz2
Implement PEP 3121: new module initialization and finalization API.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index f37290c..7d44b24 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -4661,45 +4661,57 @@ static PyDateTime_CAPI CAPI = {
};
+
+static struct PyModuleDef datetimemodule = {
+ PyModuleDef_HEAD_INIT,
+ "datetime",
+ "Fast implementation of the datetime type.",
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initdatetime(void)
+PyInit_datetime(void)
{
PyObject *m; /* a module object */
PyObject *d; /* its dict */
PyObject *x;
- m = Py_InitModule3("datetime", module_methods,
- "Fast implementation of the datetime type.");
+ m = PyModule_Create(&datetimemodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DateType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DeltaType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_TimeType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
- return;
+ return NULL;
/* timedelta values */
d = PyDateTime_DeltaType.tp_dict;
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* date values */
@@ -4707,17 +4719,17 @@ initdatetime(void)
x = new_date(1, 1, 1);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_date(MAXYEAR, 12, 31);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(1, 0, 0, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* time values */
@@ -4725,17 +4737,17 @@ initdatetime(void)
x = new_time(0, 0, 0, 0, Py_None);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_time(23, 59, 59, 999999, Py_None);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* datetime values */
@@ -4743,17 +4755,17 @@ initdatetime(void)
x = new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, Py_None);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* module initialization */
@@ -4779,7 +4791,7 @@ initdatetime(void)
x = PyCObject_FromVoidPtrAndDesc(&CAPI, (void*) DATETIME_API_MAGIC,
NULL);
if (x == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "datetime_CAPI", x);
/* A 4-year cycle has an extra leap day over what we'd get from
@@ -4807,7 +4819,7 @@ initdatetime(void)
seconds_per_day = PyLong_FromLong(24 * 3600);
if (us_per_us == NULL || us_per_ms == NULL || us_per_second == NULL ||
us_per_minute == NULL || seconds_per_day == NULL)
- return;
+ return NULL;
/* The rest are too big for 32-bit ints, but even
* us_per_week fits in 40 bits, so doubles should be exact.
@@ -4816,7 +4828,8 @@ initdatetime(void)
us_per_day = PyLong_FromDouble(86400000000.0);
us_per_week = PyLong_FromDouble(604800000000.0);
if (us_per_hour == NULL || us_per_day == NULL || us_per_week == NULL)
- return;
+ return NULL;
+ return m;
}
/* ---------------------------------------------------------------------------