bindings: python: change the return value of gpiod_LineBulk_event_wait()
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 14 May 2018 09:20:23 +0000 (11:20 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 14 May 2018 10:01:13 +0000 (12:01 +0200)
gpiod_Line_event_wait() works differently than its LineBulk
counterpart. While the latter returns either a list of lines or False,
the former returns True if an event occurred on this line or False
otherwise.

False is not a good counterpart for an actual object, so instead return
None if no events occurred on any of the monitored lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
bindings/python/gpiodmodule.c

index 02af81958df49e776bbe22a52c73c4f19e5bfe93..0e1c855640708c5ebe275fd568e6ba6e95b99dad 100644 (file)
@@ -432,8 +432,11 @@ static PyObject *gpiod_Line_event_wait(gpiod_LineObject *self,
        Py_DECREF(bulk_obj);
        if (!events)
                return NULL;
-       if (events == Py_False)
-               return Py_False;
+
+       if (events == Py_None) {
+               Py_DECREF(Py_None);
+               Py_RETURN_FALSE;
+       }
 
        Py_DECREF(events);
        Py_RETURN_TRUE;
@@ -1008,7 +1011,7 @@ static PyObject *gpiod_LineBulk_event_wait(gpiod_LineBulkObject *self,
                PyErr_SetFromErrno(PyExc_OSError);
                return NULL;
        } else if (rv == 0) {
-               Py_RETURN_FALSE;
+               Py_RETURN_NONE;
        }
 
        ret = PyList_New(gpiod_line_bulk_num_lines(&ev_bulk));