diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-06-20 22:41:32 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-06-20 22:41:32 (GMT) |
commit | 9ddf40b4e1f8875a807c026ef04e79f51debbe26 (patch) | |
tree | d26b253bf04e7b478b0f0649ff1e5692bc97c53f /Modules | |
parent | 873a277eb45439696b4862735dce28ffd29fab22 (diff) | |
download | cpython-9ddf40b4e1f8875a807c026ef04e79f51debbe26.zip cpython-9ddf40b4e1f8875a807c026ef04e79f51debbe26.tar.gz cpython-9ddf40b4e1f8875a807c026ef04e79f51debbe26.tar.bz2 |
SF patch 876130: add C API to datetime module, from Anthony Tuininga.
The LaTeX is untested (well, so is the new API, for that matter).
Note that I also changed NULL to get spelled consistently in concrete.tex.
If that was a wrong thing to do, Fred should yell at me.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/datetimemodule.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index d9cf604..ee7387c 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -9,7 +9,13 @@ #include <time.h> #include "timefuncs.h" + +/* Differentiate between building the core module and building extension + * modules. + */ +#define Py_BUILD_CORE #include "datetime.h" +#undef Py_BUILD_CORE /* We require that C int be at least 32 bits, and use int virtually * everywhere. In just a few cases we use a temp long, where a Python @@ -4520,6 +4526,24 @@ static PyMethodDef module_methods[] = { {NULL, NULL} }; +/* C API. Clients get at this via PyDateTime_IMPORT, defined in + * datetime.h. + */ +static PyDateTime_CAPI CAPI = { + &PyDateTime_DateType, + &PyDateTime_DateTimeType, + &PyDateTime_TimeType, + &PyDateTime_DeltaType, + &PyDateTime_TZInfoType, + new_date_ex, + new_datetime_ex, + new_time_ex, + new_delta_ex, + datetime_fromtimestamp, + date_fromtimestamp +}; + + PyMODINIT_FUNC initdatetime(void) { @@ -4633,6 +4657,12 @@ initdatetime(void) Py_INCREF(&PyDateTime_TZInfoType); PyModule_AddObject(m, "tzinfo", (PyObject *) &PyDateTime_TZInfoType); + x = PyCObject_FromVoidPtrAndDesc(&CAPI, (void*) DATETIME_API_MAGIC, + NULL); + if (x == NULL) + return; + PyModule_AddObject(m, "datetime_CAPI", x); + /* A 4-year cycle has an extra leap day over what we'd get from * pasting together 4 single years. */ |