[libgpiod][PATCH 0/9] bindings: python: modernize C extensions

Vincent Fazio
2026-04-22T01:20:56Z

This series performs some minor cleanup of the C extension modules and
migrates the module defintions to multi-phase intitialization (PEP 489).

Patch 1 makes `chip_get_line_name` consistent with other functions.

Patches 2 & 3 avoid calling back into python to perform C level object
cleanup.

Patch 4 introduces no real functional change but simplifies the code to
get the same result.

Patch 5 applies suggestions from from a utility maintained by a CPython
core developer to help modernize macro/function usage.

Patch 6 conditionally compiles support for using a standard CPython
function over a backported version bundled within the C extension.

Patches 7-9 migrate the C extensions to use multi-phase initialization
as described in PEP 489 [0]. While not strictly necessary for enabling
free-threaded builds, it makes adding support more straighforward and
sets the stage for both PEP 793 [1] which soft-deprecates PyInit_* and
PEP 803 [2] which could simplify wheel builds.

Patches have been tested against the full matrix of supported versions:
https://github.com/vfazio/libgpiod/actions/runs/24752901690

[0]: https://peps.python.org/pep-0489/
[1]: https://peps.python.org/pep-0793/
[2]: https://peps.python.org/pep-0803/

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
Vincent Fazio (9):
bindings: python: use Py_RETURN_NONE in chip_get_line_name
bindings: python: avoid PyObject_CallMethod during chip finalize
bindings: python: avoid PyObject_CallMethod during request finalize
bindings: python: simplify disallowing _ext.Request from being created
bindings: python: use suggestions from upgrade_pythoncapi.py
bindings: python: use PyImport_ImportModuleAttrString when available
bindings: python: migrate the gpiod._ext module to multi-phase init
bindings: python: tests: migrate the system module to multi-phase init
bindings: python: tests: migrate the gpiosim module to multi-phase
init

bindings/python/gpiod/ext/chip.c | 35 +++---
bindings/python/gpiod/ext/common.c | 5 +-
bindings/python/gpiod/ext/internal.h | 10 +-
bindings/python/gpiod/ext/module.c | 68 ++++++------
bindings/python/gpiod/ext/request.c | 26 ++---
bindings/python/tests/gpiosim/ext.c | 153 +++++++++++++++++----------
bindings/python/tests/system/ext.c | 7 +-
7 files changed, 176 insertions(+), 128 deletions(-)

--
2.43.0