Skip to content

Commit b866622

Browse files
committed
Complete PyMODINIT_FUNC doc
1 parent 5847580 commit b866622

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Doc/c-api/intro.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,27 @@ complete listing.
107107

108108
.. c:macro:: PyMODINIT_FUNC
109109
110-
Declare an extension module ``PyInit`` initialization function. The return
111-
type is :c:expr:`PyObject*`. The macro should only be used in the Python C
112-
API.
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 :c:func:`!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+
113131

114132
.. c:macro:: Py_ABS(x)
115133

0 commit comments

Comments
 (0)