summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-14 12:56:43 (GMT)
committerGitHub <noreply@github.com>2023-09-14 12:56:43 (GMT)
commitd7a27e527d7e669d2e45cff80ad725978226477c (patch)
treeff416243277a6d4fb5117bf53f350bf26f1468ab /Doc
parent1f885df2a580360c5de69cc41191f3c6bfaaeb35 (diff)
downloadcpython-d7a27e527d7e669d2e45cff80ad725978226477c.zip
cpython-d7a27e527d7e669d2e45cff80ad725978226477c.tar.gz
cpython-d7a27e527d7e669d2e45cff80ad725978226477c.tar.bz2
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.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/intro.rst24
-rw-r--r--Doc/using/configure.rst4
-rw-r--r--Doc/whatsnew/2.3.rst2
3 files changed, 27 insertions, 3 deletions
diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
index 5cf9914..4dbca92 100644
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -105,6 +105,30 @@ defined closer to where they are useful (e.g. :c:macro:`Py_RETURN_NONE`).
Others of a more general utility are defined here. This is not necessarily a
complete listing.
+.. c:macro:: PyMODINIT_FUNC
+
+ Declare an extension module ``PyInit`` initialization function. The function
+ return type is :c:expr:`PyObject*`. The macro declares any special linkage
+ declarations required by the platform, and for C++ declares the function as
+ ``extern "C"``.
+
+ The initialization function must be named :samp:`PyInit_{name}`, where
+ *name* is the name of the module, and should be the only non-\ ``static``
+ item defined in the module file. Example::
+
+ static struct PyModuleDef spam_module = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "spam",
+ ...
+ };
+
+ PyMODINIT_FUNC
+ PyInit_spam(void)
+ {
+ return PyModule_Create(&spam_module);
+ }
+
+
.. c:macro:: Py_ABS(x)
Return the absolute value of ``x``.
diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index ba1898e..9d2952e 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -855,8 +855,8 @@ Example on Linux x86-64::
At the beginning of the files, C extensions are built as built-in modules.
Extensions defined after the ``*shared*`` marker are built as dynamic libraries.
-The :c:macro:`PyAPI_FUNC()`, :c:macro:`PyAPI_DATA()` and
-:c:macro:`PyMODINIT_FUNC` macros of :file:`Include/pyport.h` are defined
+The :c:macro:`!PyAPI_FUNC()`, :c:macro:`!PyAPI_DATA()` and
+:c:macro:`PyMODINIT_FUNC` macros of :file:`Include/exports.h` are defined
differently depending if the ``Py_BUILD_CORE_MODULE`` macro is defined:
* Use ``Py_EXPORTED_SYMBOL`` if the ``Py_BUILD_CORE_MODULE`` is defined
diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst
index ba18ce3..ec1ca41 100644
--- a/Doc/whatsnew/2.3.rst
+++ b/Doc/whatsnew/2.3.rst
@@ -1889,7 +1889,7 @@ Changes to Python's build process and to the C API include:
* The :c:macro:`!DL_EXPORT` and :c:macro:`!DL_IMPORT` macros are now deprecated.
Initialization functions for Python extension modules should now be declared
using the new macro :c:macro:`PyMODINIT_FUNC`, while the Python core will
- generally use the :c:macro:`PyAPI_FUNC` and :c:macro:`PyAPI_DATA` macros.
+ generally use the :c:macro:`!PyAPI_FUNC` and :c:macro:`!PyAPI_DATA` macros.
* The interpreter can be compiled without any docstrings for the built-in
functions and modules by supplying :option:`!--without-doc-strings` to the