From a161045494ddade6ce30162b5f45d6ebbe568e10 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 24 Jun 2025 14:35:52 +0200 Subject: [PATCH 1/2] PEP 793: Two small updates - PyType_GetModuleByToken will return a strong reference, unlike PyType_GetModuleByDef - Remove incorrect note that the new API creates modules from a *spec*. (The note could be updated to say *slots*, but, it isn't that important.) --- peps/pep-0793.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/peps/pep-0793.rst b/peps/pep-0793.rst index 562278f0582..ef9ae7528d9 100644 --- a/peps/pep-0793.rst +++ b/peps/pep-0793.rst @@ -318,12 +318,15 @@ will return 0 on success and -1 on failure: A new ``PyType_GetModuleByToken`` function will be added, with a signature like the existing ``PyType_GetModuleByDef`` but a ``void *token`` argument, -and the same behaviour except matching tokens rather than only defs. +and the same behaviour except matching tokens rather than only defs, +and returning a strong reference. For easier backwards compatibility, the existing ``PyType_GetModuleByDef`` -will be changed to work exactly like ``PyType_GetModuleByToken`` -- that is, -it will allow a token (cast to a ``PyModuleDef *`` pointer) as the -*def* argument. +will be changed to also allow a token (cast to a ``PyModuleDef *`` pointer) as +the *def* argument. +That is, ``PyType_GetModuleByToken`` and ``PyType_GetModuleByDef`` will differ +only in the formal signature of the second argument and by returning a +borrowed vs. strong reference. (The ``PyModule_GetDef`` function will not get a similar change, as users may access members of its result.) @@ -346,8 +349,7 @@ They may not have a ``NULL`` value (instead, the slot can be omitted entirely). Note that currently, for modules created from a *spec* (that is, using ``PyModule_FromDefAndSpec``), the ``PyModuleDef.m_name`` member is ignored and the name from the spec is used instead. -All API proposed in this document creates modules from a *spec*, and it will -ignore ``Py_mod_name`` in the same way. +All API proposed in this document will ignore ``Py_mod_name`` in the same way. The slot will be optional, but extension authors are strongly encouraged to include it for the benefit of future APIs, external tooling, debugging, and introspection. From 055cca3c43155f7a21bb1be6e546376e5faa225d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 25 Jun 2025 10:41:16 +0200 Subject: [PATCH 2/2] Revert the *spec* note removal --- peps/pep-0793.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/peps/pep-0793.rst b/peps/pep-0793.rst index ef9ae7528d9..356cbca0066 100644 --- a/peps/pep-0793.rst +++ b/peps/pep-0793.rst @@ -349,7 +349,8 @@ They may not have a ``NULL`` value (instead, the slot can be omitted entirely). Note that currently, for modules created from a *spec* (that is, using ``PyModule_FromDefAndSpec``), the ``PyModuleDef.m_name`` member is ignored and the name from the spec is used instead. -All API proposed in this document will ignore ``Py_mod_name`` in the same way. +All API proposed in this document creates modules from a *spec*, and it will +ignore ``Py_mod_name`` in the same way. The slot will be optional, but extension authors are strongly encouraged to include it for the benefit of future APIs, external tooling, debugging, and introspection.