From d331321f010b07ec6646c3effa490655ecab624c Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 12 May 2018 14:48:58 +0200 Subject: [PATCH] bindings: python: return None if line can't be found by name For both find_line() variants (Chip's method and global function) return None if the internal call to the C find_line function fails with ENOENT. This is not an error so don't raise an exception. Signed-off-by: Bartosz Golaszewski --- bindings/python/gpiodmodule.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 8e36ec8..9248616 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -1291,6 +1291,11 @@ gpiod_Chip_find_line(gpiod_ChipObject *self, PyObject *args) line = gpiod_chip_find_line(self->chip, name); Py_END_ALLOW_THREADS; if (!line) { + if (errno == ENOENT) { + Py_INCREF(Py_None); + return (gpiod_LineObject *)Py_None; + } + PyErr_SetFromErrno(PyExc_OSError); return NULL; } @@ -1573,6 +1578,11 @@ static gpiod_LineObject *gpiod_Module_find_line(PyObject *self GPIOD_UNUSED, line = gpiod_line_find(name); Py_END_ALLOW_THREADS; if (!line) { + if (errno == ENOENT) { + Py_INCREF(Py_None); + return (gpiod_LineObject *)Py_None; + } + PyErr_SetFromErrno(PyExc_OSError); return NULL; } -- 2.30.2