Skip to content

Commit 416e8d8

Browse files
methaneencukou
andauthored
Docs: fix code examples in the abi3t migration guide (#161247)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent be581b5 commit 416e8d8

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎Doc/howto/abi3t-migration.rst‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ For reference, here are direct links for several popular build tools:
187187
You may want to verify that the tool set the right flag by temporarily adding the
188188
following just after ``#include <Python.h>``::
189189

190-
#if Py_TARGET_ABI3T+0 <= 0x30f0000
190+
#if Py_TARGET_ABI3T+0 < 0x30f0000
191191
#error "abi3t define is not set!"
192192
#endif
193193

194-
This should result in a different error than "``abi3t`` define is not set".
194+
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.)
195195

196196
.. seealso::
197197

@@ -357,13 +357,13 @@ It should be a :c:type:`PyModuleDef_Slot` array like the following:
357357
static PyModuleDef_Slot my_slots[] = {
358358
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
359359
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
360-
{Py_mod_create, my_module_create},
360+
{Py_mod_create, create_module},
361361
{Py_mod_exec, my_first_module_exec},
362362
{Py_mod_exec, my_second_module_exec},
363363
{0, NULL}
364364
};
365365
366-
``py_mod_create``
366+
``Py_mod_create``
367367
.................
368368

369369

@@ -383,7 +383,7 @@ Commonly, the information is static and you can refer to it directly.
383383
defining several functions instead.)
384384

385385

386-
Multiple ``py_mod_exec``
386+
Multiple ``Py_mod_exec``
387387
........................
388388

389389
If you have *more than one* :c:macro:`Py_mod_exec` entry, consolidate them:
@@ -396,6 +396,7 @@ with it.
396396
static int my_module_exec(PyObject *module) {
397397
if (my_first_module_exec(module) < 0) return -1;
398398
if (my_second_module_exec(module) < 0) return -1;
399+
return 0;
399400
}
400401
401402
static PyModuleDef_Slot my_slots[] = {
@@ -423,8 +424,8 @@ definitions to :c:macro:`PySlot_DATA` and :c:macro:`PySlot_FUNC`:
423424
...
424425
PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
425426
PySlot_DATA(Py_mod_multiple_interpreters,
426-
Py_MOD_PER_INTERPRETER_GIL_SUPPORTED)
427-
PySlot_FUNC(Py_mod_create, my_module_create),
427+
Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
428+
PySlot_FUNC(Py_mod_create, create_module),
428429
PySlot_FUNC(Py_mod_exec, my_module_exec),
429430
PySlot_END
430431
};
@@ -475,7 +476,7 @@ These functions are typically used for two purposes:
475476
...
476477
PySlot_STATIC_DATA(Py_mod_token, &my_token),
477478
PySlot_END
478-
}
479+
};
479480
480481
Then, switch from :c:func:`PyModule_GetDef` calls such as:
481482

@@ -508,7 +509,7 @@ These functions are typically used for two purposes:
508509
.. code-block::
509510
:class: good
510511
511-
PyObject *module = PyType_GetModuleByToken(type, my_token);
512+
PyObject *module = PyType_GetModuleByToken(type, &my_token);
512513
/* handle error; use module */
513514
Py_XDECREF(module);
514515
@@ -655,11 +656,12 @@ There are two main ways to get the right class:
655656
.. code-block::
656657
:class: good
657658
658-
PyTypeObject cls;
659+
PyTypeObject *cls;
659660
if (PyType_GetBaseByToken(Py_TYPE(obj), my_tp_token, &cls) < 0) {
660661
/* handle error */
661662
}
662663
CustomObjectData *data = PyObject_GetTypeData(obj, cls);
664+
Py_DECREF(cls);
663665
664666
Type tokens work similarly to module tokens covered :ref:`earlier in this
665667
guide <abi3t-migration-module-token>`.

0 commit comments

Comments
 (0)