Skip to content

gh-149716: Document PySlot_DATA for Py_mod_gil and Py_mod_multiple_interpreters#150053

Open
Taeknology wants to merge 2 commits into
python:mainfrom
Taeknology:gh-149716-document-mod-gil-multiple-interp-slot-macro
Open

gh-149716: Document PySlot_DATA for Py_mod_gil and Py_mod_multiple_interpreters#150053
Taeknology wants to merge 2 commits into
python:mainfrom
Taeknology:gh-149716-document-mod-gil-multiple-interp-slot-macro

Conversation

@Taeknology

@Taeknology Taeknology commented May 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #149716.

Summary

Adds short code examples to the documentation of two module slot IDs
(Py_mod_gil since 3.13, Py_mod_multiple_interpreters since 3.12).
The examples mirror the existing one under Py_mod_abi and make it
explicit that PySlot_DATA (not PySlot_INT64 / PySlot_UINT64)
is the correct slot-definition macro for these two slots, because
their values (Py_MOD_GIL_*, Py_MOD_MULTIPLE_INTERPRETERS_*,
Py_MOD_PER_INTERPRETER_GIL_SUPPORTED) are defined as (void *)N
in Include/moduleobject.h, and PySlot_DATA casts to void *
(Include/slots.h).

Changes

  • Doc/c-api/module.rst: add a PySlot_DATA(...) code-block to each
    of the two slot sections, in the same 4-part style (intro sentence +
    .. code-block:: c + 6-space code + .. versionadded::) as the
    existing Py_mod_abi example.

The Py_mod_multiple_interpreters example shows
Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (rather than the default
_SUPPORTED) since that is the value extension authors most often need
to set explicitly. Likewise the Py_mod_gil example shows
Py_MOD_GIL_NOT_USED (rather than the default _USED).

Notes

  • Docs-only change; no Misc/NEWS.d entry per the
    devguide.
  • RST format mirrors Py_mod_abi byte-for-byte (3-space body
    indentation, 6-space code indentation, identical directive order).

…ple_interpreters

Add short code examples mirroring the existing Py_mod_abi example,
so it is clear which slot definition macro (PySlot_DATA, PySlot_INT64,
or PySlot_UINT64) to use for these two slots.
@python-cla-bot

python-cla-bot Bot commented May 19, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

read-the-docs-community Bot commented May 19, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33042986 | 📁 Comparing 4726cfd against main (68ebc05)

  🔍 Preview build  

123 files changed · + 1 added · ± 122 modified

+ Added

± Modified

@kumaraditya303 kumaraditya303 requested a review from encukou May 28, 2026 10:46
@encukou encukou self-assigned this May 29, 2026
Comment thread Doc/c-api/module.rst Outdated
machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED``.

A suitable slot value can be defined using the :c:macro:`PySlot_DATA` macro,
as in:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PySlot_DATA is only for the new PySlot arrays; not for the older PyModuleDef_Slot (where every value is a pointer, hence the type).
I'd word it like this:

Suggested change
as in:
For historical reasons, the values are declared as pointers (``void *``).
When using :c:type:`PySlot` arrays, use :c:macro:`PySlot_DATA` for
:c:macro:`!Py_mod_multiple_interpreters`:

Comment thread Doc/c-api/module.rst Outdated
Comment on lines +283 to +284
A suitable slot value can be defined using the :c:macro:`PySlot_DATA` macro,
as in:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A suitable slot value can be defined using the :c:macro:`PySlot_DATA` macro,
as in:
For historical reasons, the values are declared as pointers (``void *``).
When using :c:type:`PySlot` arrays, use :c:macro:`PySlot_DATA` for
:c:macro:`!Py_mod_gil`:

Clarify that PySlot_DATA applies to PySlot arrays and note the
historical void* declaration of the slot values, per review.
@Taeknology

Copy link
Copy Markdown
Contributor Author

Applied both, thanks.

I left Py_mod_abi as is — its value is a real pointer, so the void * note doesn't fit there. Can change it too if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Unclear which slot definition macro to use

2 participants