@@ -8,11 +8,42 @@ 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.
19+
20+ On success, populate the :c:var: `PyDateTimeAPI ` pointer.
21+ On failure, set :c:var: `PyDateTimeAPI ` to ``NULL `` and set an exception.
22+ The caller must check if an error occurred via :c:func: `PyErr_Occurred `:
23+
24+ .. code-block ::
25+
26+ PyDateTime_IMPORT;
27+ if (PyErr_Occurred()) { /* cleanup */ }
28+
29+ .. warning ::
30+
31+ This is not compatible with subinterpreters.
32+
33+ .. c :type :: PyDateTime_CAPI
34+
35+ Structure containing the fields for the datetime C API.
36+
37+ The fields of this structure are private and subject to change.
38+
39+ Do not use this directly; prefer ``PyDateTime_* `` APIs instead.
40+
41+ .. c :var :: PyDateTime_CAPI *PyDateTimeAPI
42+
43+ Dynamically allocated object containing the datetime C API.
44+
45+ This variable is only available once :c:macro: `PyDateTime_IMPORT ` succeeds.
46+
1647.. c :type :: PyDateTime_Date
1748
1849 This subtype of :c:type: `PyObject ` represents a Python date object.
@@ -325,3 +356,16 @@ Macros for the convenience of modules implementing the DB API:
325356
326357 Create and return a new :class: `datetime.date ` object given an argument
327358 tuple suitable for passing to :meth: `datetime.date.fromtimestamp `.
359+
360+
361+ Internal data
362+ -------------
363+
364+ The following symbols 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