]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-107298: Document PyMODINIT_FUNC macro (#109236) (#109948)
authorVictor Stinner <vstinner@python.org>
Wed, 27 Sep 2023 08:40:24 +0000 (10:40 +0200)
committerGitHub <noreply@github.com>
Wed, 27 Sep 2023 08:40:24 +0000 (10:40 +0200)
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 d7a27e527d7e669d2e45cff80ad725978226477c)

Doc/c-api/intro.rst
Doc/using/configure.rst
Doc/whatsnew/2.3.rst

index ec2d8bc0ef02ef3171fe7c7b4f41418d6240113d..39df9ec390d4a99ba0394135f6eadf0e7039510b 100644 (file)
@@ -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``.
index 6e4a43f4aadcbf9c84dca048809357cf193731f0..ca3b88e079609a76e7e67ffd4d24df7db5a1a456 100644 (file)
@@ -679,7 +679,7 @@ Extensions defined after the ``*shared*`` marker are built as dynamic libraries.
 The :file:`setup.py` script only builds C extensions as shared libraries using
 the :mod:`distutils` module.
 
-The :c:macro:`PyAPI_FUNC()`, :c:macro:`PyAPI_DATA()` and
+The :c:macro:`!PyAPI_FUNC()`, :c:macro:`!PyAPI_DATA()` and
 :c:macro:`PyMODINIT_FUNC` macros of :file:`Include/pyport.h` are defined
 differently depending if the ``Py_BUILD_CORE_MODULE`` macro is defined:
 
index 72aef3d269f8d342da73d76b4ec9e68226ff2a8a..3460421fe45ccef8610ba5a37ce4e15fee676e52 100644 (file)
@@ -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