[libgpiod][PATCH 1/9] bindings: python: use Py_RETURN_NONE in chip_get_line_name

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

When commit 0c0993569c54 introduced `chip_get_line_name`, it failed to
utilize the standard `Py_RETURN_NONE` macro used throughout the rest of
the extension.

While commit fbc0a4471215 fixed the underlying reference counting issue,
utilizing the macro is the standard way of managing reference counts,
works across all CPython versions, and brings the function in line with
others in the extension.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
bindings/python/gpiod/ext/chip.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/bindings/python/gpiod/ext/chip.c b/bindings/python/gpiod/ext/chip.c
index 53c4b80..19b3a4f 100644
--- a/bindings/python/gpiod/ext/chip.c
+++ b/bindings/python/gpiod/ext/chip.c
@@ -152,7 +152,7 @@ static PyObject *chip_get_line_name(chip_object *self, PyObject *args)
int ret;
unsigned int offset;
struct gpiod_line_info *info;
- PyObject *line_name;
+ PyObject *line_name = NULL;
const char *name;

ret = PyArg_ParseTuple(args, "I", &offset);
@@ -166,16 +166,15 @@ static PyObject *chip_get_line_name(chip_object *self, PyObject *args)
return Py_gpiod_SetErrFromErrno();

name = gpiod_line_info_get_name(info);
- if (!name) {
- Py_INCREF(Py_None);
- line_name = Py_None;
- } else {
+ if (name)
line_name = PyUnicode_FromString(name);
- }

gpiod_line_info_free(info);

- return line_name;
+ if (line_name)
+ return line_name;
+
+ Py_RETURN_NONE;
}

static PyObject *
--
2.43.0