From 5d85e4361aab66ac2afe70f149b6666a59b5f655 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 3 Nov 2026 12:29:25 +0000 Subject: [PATCH 1/2] Docs: fix code examples in the abi3t migration guide --- Doc/howto/abi3t-migration.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Doc/howto/abi3t-migration.rst b/Doc/howto/abi3t-migration.rst index 3aa11a0dbf653d..fea7aa65f6578f 100644 --- a/Doc/howto/abi3t-migration.rst +++ b/Doc/howto/abi3t-migration.rst @@ -187,11 +187,11 @@ For reference, here are direct links for several popular build tools: You may want to verify that the tool set the right flag by temporarily adding the following just after ``#include ``:: - #if Py_TARGET_ABI3T+0 <= 0x30f0000 + #if Py_TARGET_ABI3T+0 < 0x30f0000 #error "abi3t define is not set!" #endif -This should result in a different error than "``abi3t`` define is not set". +This should not result in an "``abi3t`` define is not set" error. .. seealso:: @@ -357,13 +357,13 @@ It should be a :c:type:`PyModuleDef_Slot` array like the following: static PyModuleDef_Slot my_slots[] = { {Py_mod_gil, Py_MOD_GIL_NOT_USED}, {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, - {Py_mod_create, my_module_create}, + {Py_mod_create, create_module}, {Py_mod_exec, my_first_module_exec}, {Py_mod_exec, my_second_module_exec}, {0, NULL} }; -``py_mod_create`` +``Py_mod_create`` ................. @@ -383,7 +383,7 @@ Commonly, the information is static and you can refer to it directly. defining several functions instead.) -Multiple ``py_mod_exec`` +Multiple ``Py_mod_exec`` ........................ If you have *more than one* :c:macro:`Py_mod_exec` entry, consolidate them: @@ -396,6 +396,7 @@ with it. static int my_module_exec(PyObject *module) { if (my_first_module_exec(module) < 0) return -1; if (my_second_module_exec(module) < 0) return -1; + return 0; } static PyModuleDef_Slot my_slots[] = { @@ -423,8 +424,8 @@ definitions to :c:macro:`PySlot_DATA` and :c:macro:`PySlot_FUNC`: ... PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED), PySlot_DATA(Py_mod_multiple_interpreters, - Py_MOD_PER_INTERPRETER_GIL_SUPPORTED) - PySlot_FUNC(Py_mod_create, my_module_create), + Py_MOD_PER_INTERPRETER_GIL_SUPPORTED), + PySlot_FUNC(Py_mod_create, create_module), PySlot_FUNC(Py_mod_exec, my_module_exec), PySlot_END }; @@ -475,7 +476,7 @@ These functions are typically used for two purposes: ... PySlot_STATIC_DATA(Py_mod_token, &my_token), PySlot_END - } + }; Then, switch from :c:func:`PyModule_GetDef` calls such as: @@ -508,7 +509,7 @@ These functions are typically used for two purposes: .. code-block:: :class: good - PyObject *module = PyType_GetModuleByToken(type, my_token); + PyObject *module = PyType_GetModuleByToken(type, &my_token); /* handle error; use module */ Py_XDECREF(module); @@ -655,11 +656,12 @@ There are two main ways to get the right class: .. code-block:: :class: good - PyTypeObject cls; + PyTypeObject *cls; if (PyType_GetBaseByToken(Py_TYPE(obj), my_tp_token, &cls) < 0) { /* handle error */ } CustomObjectData *data = PyObject_GetTypeData(obj, cls); + Py_DECREF(cls); Type tokens work similarly to module tokens covered :ref:`earlier in this guide `. From dc781283dff7f762ba8fdd50623f9467fd7a4f0b Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 4 Nov 2026 01:14:40 +0900 Subject: [PATCH 2/2] Apply suggestion from @encukou Co-authored-by: Petr Viktorin --- Doc/howto/abi3t-migration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/howto/abi3t-migration.rst b/Doc/howto/abi3t-migration.rst index fea7aa65f6578f..5faf05b89d388f 100644 --- a/Doc/howto/abi3t-migration.rst +++ b/Doc/howto/abi3t-migration.rst @@ -191,7 +191,7 @@ following just after ``#include ``:: #error "abi3t define is not set!" #endif -This should not result in an "``abi3t`` define is not set" error. +This should result in a different error than "``abi3t`` define is not set". (If you get no error at all, either the module is already ported or you're not compiling the code you changed.) .. seealso::