Skip to content

Commit d951aae

Browse files
authored
[3.11] gh-107298: Document PyMODINIT_FUNC macro (#109236) (#109948)
gh-107298: Document PyMODINIT_FUNC macro (#109236) Document PyMODINIT_FUNC macro. Remove links to PyAPI_FUNC() and PyAPI_DATA() macros since they are not documented. These macros should only be used to define the Python C API. They should not be used outside Python code base. (cherry picked from commit d7a27e5)
1 parent 0a69de7 commit d951aae

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Doc/c-api/intro.rst

+24
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ defined closer to where they are useful (e.g. :c:macro:`Py_RETURN_NONE`).
105105
Others of a more general utility are defined here. This is not necessarily a
106106
complete listing.
107107

108+
.. c:macro:: PyMODINIT_FUNC
109+
110+
Declare an extension module ``PyInit`` initialization function. The function
111+
return type is :c:expr:`PyObject*`. The macro declares any special linkage
112+
declarations required by the platform, and for C++ declares the function as
113+
``extern "C"``.
114+
115+
The initialization function must be named :samp:`PyInit_{name}`, where
116+
*name* is the name of the module, and should be the only non-\ ``static``
117+
item defined in the module file. Example::
118+
119+
static struct PyModuleDef spam_module = {
120+
PyModuleDef_HEAD_INIT,
121+
.m_name = "spam",
122+
...
123+
};
124+
125+
PyMODINIT_FUNC
126+
PyInit_spam(void)
127+
{
128+
return PyModule_Create(&spam_module);
129+
}
130+
131+
108132
.. c:macro:: Py_ABS(x)
109133
110134
Return the absolute value of ``x``.

Doc/using/configure.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Extensions defined after the ``*shared*`` marker are built as dynamic libraries.
679679
The :file:`setup.py` script only builds C extensions as shared libraries using
680680
the :mod:`distutils` module.
681681

682-
The :c:macro:`PyAPI_FUNC()`, :c:macro:`PyAPI_DATA()` and
682+
The :c:macro:`!PyAPI_FUNC()`, :c:macro:`!PyAPI_DATA()` and
683683
:c:macro:`PyMODINIT_FUNC` macros of :file:`Include/pyport.h` are defined
684684
differently depending if the ``Py_BUILD_CORE_MODULE`` macro is defined:
685685

Doc/whatsnew/2.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ Changes to Python's build process and to the C API include:
18891889
* The :c:macro:`!DL_EXPORT` and :c:macro:`!DL_IMPORT` macros are now deprecated.
18901890
Initialization functions for Python extension modules should now be declared
18911891
using the new macro :c:macro:`PyMODINIT_FUNC`, while the Python core will
1892-
generally use the :c:macro:`PyAPI_FUNC` and :c:macro:`PyAPI_DATA` macros.
1892+
generally use the :c:macro:`!PyAPI_FUNC` and :c:macro:`!PyAPI_DATA` macros.
18931893

18941894
* The interpreter can be compiled without any docstrings for the built-in
18951895
functions and modules by supplying :option:`!--without-doc-strings` to the

0 commit comments

Comments
 (0)