[Python-checkins] python/dist/src/Include datetime.h,1.4,1.5
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Sun Jun 20 18:41:34 EDT 2004
Update of /cvsroot/python/python/dist/src/Include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18815/Include
Modified Files:
datetime.h
Log Message:
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.
Index: datetime.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/datetime.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** datetime.h 11 Jan 2003 03:39:11 -0000 1.4
--- datetime.h 20 Jun 2004 22:41:24 -0000 1.5
***************
*** 4,7 ****
--- 4,10 ----
#ifndef DATETIME_H
#define DATETIME_H
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
/* Fields are packed into successive bytes, each viewed as unsigned and
***************
*** 133,136 ****
--- 136,169 ----
((PyDateTime_Time*)o)->data[5])
+
+ /* Define structure for C API. */
+ typedef struct {
+ /* type objects */
+ PyTypeObject *DateType;
+ PyTypeObject *DateTimeType;
+ PyTypeObject *TimeType;
+ PyTypeObject *DeltaType;
+ PyTypeObject *TZInfoType;
+
+ /* constructors */
+ PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
+ PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
+ PyObject*, PyTypeObject*);
+ PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
+ PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
+
+ /* constructors for the DB API */
+ PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);
+ PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);
+
+ } PyDateTime_CAPI;
+
+
+ /* "magic" constant used to partially protect against developer mistakes. */
+ #define DATETIME_API_MAGIC 0x414548d5
+
+ #ifdef Py_BUILD_CORE
+
+ /* Macros for type checking when building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
#define PyDate_CheckExact(op) ((op)->ob_type == &PyDateTime_DateType)
***************
*** 148,150 ****
--- 181,245 ----
#define PyTZInfo_CheckExact(op) ((op)->ob_type == &PyDateTime_TZInfoType)
+ #else
+
+ /* Define global variable for the C API and a macro for setting it. */
+ static PyDateTime_CAPI *PyDateTimeAPI;
+
+ #define PyDateTime_IMPORT \
+ PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
+ "datetime_CAPI")
+
+ /* This macro would be used if PyCObject_ImportEx() was created.
+ #define PyDateTime_IMPORT \
+ PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_ImportEx("datetime", \
+ "datetime_CAPI", \
+ DATETIME_API_MAGIC)
+ */
+
+ /* Macros for type checking when not building the Python core. */
+ #define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
+ #define PyDate_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateType)
+
+ #define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
+ #define PyDateTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateTimeType)
+
+ #define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
+ #define PyTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TimeType)
+
+ #define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
+ #define PyDelta_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DeltaType)
+
+ #define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
+ #define PyTZInfo_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TZInfoType)
+
+ /* Macros for accessing constructors in a simplified fashion. */
+ #define PyDate_FromDate(year, month, day) \
+ PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
+
+ #define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
+ PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
+ min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
+
+ #define PyTime_FromTime(hour, minute, second, usecond) \
+ PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
+ Py_None, PyDateTimeAPI->TimeType)
+
+ #define PyDelta_FromDSU(days, seconds, useconds) \
+ PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1,
+ PyDateTimeAPI->DeltaType)
+
+ /* Macros supporting the DB API. */
+ #define PyDateTime_FromTimestamp(args) \
+ PyDateTimeAPI->DateTime_FromTimestamp( \
+ (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
+
+ #define PyDate_FromTimestamp(args) \
+ PyDateTimeAPI->Date_FromTimestamp( \
+ (PyObject*) (PyDateTimeAPI->DateType), args)
+
+ #endif /* Py_BUILD_CORE */
+
+ #ifdef __cplusplus
+ }
+ #endif
#endif
More information about the Python-checkins
mailing list