From: Bartosz Golaszewski Date: Sat, 12 May 2018 12:48:58 +0000 (+0200) Subject: bindings: python: return None if line can't be found by name X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=d331321f010b07ec6646c3effa490655ecab624c;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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; }