@@ -8,11 +8,43 @@ DateTime Objects
88Various date and time objects are supplied by the :mod: `datetime ` module.
99Before using any of these functions, the header file :file: `datetime.h ` must be
1010included in your source (note that this is not included by :file: `Python.h `),
11- and the macro :c:macro: `! PyDateTime_IMPORT ` must be invoked, usually as part of
11+ and the macro :c:macro: `PyDateTime_IMPORT ` must be invoked, usually as part of
1212the module initialisation function. The macro puts a pointer to a C structure
13- into a static variable, :c:data: `! PyDateTimeAPI `, that is used by the following
13+ into a static variable, :c:data: `PyDateTimeAPI `, that is used by the following
1414macros.
1515
16+ .. c :macro :: PyDateTime_IMPORT()
17+
18+ Import the datetime C API. The macro does not need a semi-colon to be called.
19+
20+ On success, populate the :c:var: `PyDateTimeAPI ` pointer.
21+
22+ On failure, set :c:var: `PyDateTimeAPI ` to ``NULL `` and set an exception.
23+ The caller must check if an error occurred via :c:func: `PyErr_Occurred `:
24+
25+ .. code-block ::
26+
27+ PyDateTime_IMPORT(); // semi-colon is optional but recommended
28+ if (PyErr_Occurred()) { /* cleanup */ }
29+
30+ .. warning ::
31+
32+ This is not compatible with subinterpreters.
33+
34+ .. c :type :: PyDateTime_CAPI
35+
36+ Structure containing the fields for the datetime C API.
37+
38+ The fields of this structure are private and subject to change.
39+
40+ Do not use this directly; prefer ``PyDateTime_* `` APIs instead.
41+
42+ .. c :var :: PyDateTime_CAPI *PyDateTimeAPI
43+
44+ Dynamically allocated object containing the datetime C API.
45+
46+ This variable is only available once :c:macro: `PyDateTime_IMPORT ` succeeds.
47+
1648.. c :type :: PyDateTime_Date
1749
1850 This subtype of :c:type: `PyObject ` represents a Python date object.
@@ -325,3 +357,15 @@ Macros for the convenience of modules implementing the DB API:
325357
326358 Create and return a new :class: `datetime.date ` object given an argument
327359 tuple suitable for passing to :meth: `datetime.date.fromtimestamp `.
360+
361+ Internal data
362+ -------------
363+
364+ The following symbol are exposed by the C API but should be considered
365+ internal-only.
366+
367+ .. c :macro :: PyDateTime_CAPSULE_NAME
368+
369+ Name of the datetime capsule to pass to :c:func: `PyCapsule_Import `.
370+
371+ Internal usage only. Use :c:macro: `PyDateTime_IMPORT ` instead.
0 commit comments