bindings: python: import gpiod attributes in external module
authorVincent Fazio <vfazio@xes-inc.com>
Tue, 8 Oct 2024 17:51:39 +0000 (12:51 -0500)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 14 Oct 2024 14:42:38 +0000 (16:42 +0200)
commit035ad74fdd69bc3cc3650d3db113ec2563805104
treec509e5b8ef5231881138710f7fe677f49702160c
parentcfbaa54427ba9b8e9e1bf30f5a28a33e90d99d2f
bindings: python: import gpiod attributes in external module

Previously, the external module relied on gpiod attributes being present
within `globals()` to construct return values back to the caller.

This assumption required callers of the external module to have imported
the attributes to populate `globals()` for the interface to work.

Having this implicit contract is opaque and prone to causing issues if
imports within gpiod modules ever get reworked.

Now, the external module explicitly imports attributes from gpiod in
order to return values back to the caller.

There should be no concern about circular imports as the external module
should be completely imported by the time callers call into it.

Since Py_gpiod_GetGlobalType is no longer used, it has been replaced
with Py_gpiod_GetModuleAttrString which returns a new PyObject*
reference for the named module and attribute that must be decremented
when no longer in use.

Closes: https://github.com/brgl/libgpiod/issues/101
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241008175139.1198980-1-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
bindings/python/gpiod/ext/chip.c
bindings/python/gpiod/ext/common.c
bindings/python/gpiod/ext/internal.h
bindings/python/gpiod/ext/request.c