Skip to content

Commit 445a017

Browse files
committed
Adjust docs
1 parent cdb8a59 commit 445a017

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Doc/c-api/module.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ Feature slots
230230
When creating a module, Python checks the value of this slot
231231
using :c:func:`PyABIInfo_Check`.
232232
233+
This slot is required, except for modules created from
234+
:c:struct:`PyModuleDef`.
235+
233236
.. versionadded:: 3.15
234237
235238
.. c:macro:: Py_mod_multiple_interpreters
@@ -620,9 +623,9 @@ rather than from an extension's :ref:`export hook <extension-export-hook>`.
620623
and the :py:class:`~importlib.machinery.ModuleSpec` *spec*.
621624
622625
The *slots* argument must point to an array of :c:type:`PyModuleDef_Slot`
623-
structures, terminated by an entry slot with slot ID of 0
626+
structures, terminated by an entry with slot ID of 0
624627
(typically written as ``{0}`` or ``{0, NULL}`` in C).
625-
The *slots* argument may not be ``NULL``.
628+
The array must include a :c:data:`Py_mod_abi` entry.
626629
627630
The *spec* argument may be any ``ModuleSpec``-like object, as described
628631
in :c:macro:`Py_mod_create` documentation.

Doc/extending/first-extension-module.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,19 @@ Define this array just before your export hook:
265265

266266
.. code-block:: c
267267
268+
PyABIInfo_VAR(abi_info);
269+
268270
static PyModuleDef_Slot spam_slots[] = {
271+
{Py_mod_abi, &abi_info},
269272
{Py_mod_name, "spam"},
270273
{Py_mod_doc, "A wonderful module with an example function"},
271274
{0, NULL}
272275
};
273276
277+
The ``PyABIInfo_VAR(abi_info);`` macro and the :c:data:`Py_mod_abi` slot
278+
are a bit of boilerplate that helps prevent extensions compiled for
279+
a different version of Python from crashing the interpreter.
280+
274281
For both :c:data:`Py_mod_name` and :c:data:`Py_mod_doc`, the values are C
275282
strings -- that is, NUL-terminated, UTF-8 encoded byte arrays.
276283

Doc/includes/capi-extension/spammodule-01.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ static PyMethodDef spam_methods[] = {
3535

3636
/// Module slot table
3737

38+
PyABIInfo_VAR(abi_info);
39+
3840
static PyModuleDef_Slot spam_slots[] = {
41+
{Py_mod_abi, &abi_info},
3942
{Py_mod_name, "spam"},
4043
{Py_mod_doc, "A wonderful module with an example function"},
4144
{Py_mod_methods, spam_methods},
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
The :c:data:`Py_mod_abi` slot is now mandatory for modules created using the
2-
:c:func:`PyModExport_* <PyModExport_modulename>` export hook.
1+
The :c:data:`Py_mod_abi` slot is now mandatory for modules created from a
2+
slots array (using :c:func:`PyModule_FromSlotsAndSpec` or the
3+
:c:func:`PyModExport_* <PyModExport_modulename>` export hook).

0 commit comments

Comments
 (0)