@@ -48,7 +48,7 @@ const ::std::map<::std::bitset<32>, int, bitset_cmp> reqflag_mapping = {
} /* namespace */
-const unsigned int line_bulk::MAX_LINES = GPIOD_LINE_BULK_MAX_LINES;
+const unsigned int line_bulk::MAX_LINES = 64;
line_bulk::line_bulk(const ::std::vector<line>& lines)
: _m_bulk()
@@ -8,6 +8,8 @@
#include <Python.h>
#include <gpiod.h>
+#define LINE_REQUEST_MAX_LINES 64
+
typedef struct {
PyObject_HEAD
struct gpiod_chip *chip;
@@ -1138,7 +1140,7 @@ static int gpiod_LineBulk_init(gpiod_LineBulkObject *self,
"Argument must be a non-empty sequence");
return -1;
}
- if (self->num_lines > GPIOD_LINE_BULK_MAX_LINES) {
+ if (self->num_lines > LINE_REQUEST_MAX_LINES) {
PyErr_SetString(PyExc_TypeError,
"Too many objects in the sequence");
return -1;
@@ -1334,7 +1336,7 @@ static PyObject *gpiod_LineBulk_request(gpiod_LineBulkObject *self,
NULL };
int rv, type = gpiod_LINE_REQ_DIR_AS_IS, flags = 0,
- default_vals[GPIOD_LINE_BULK_MAX_LINES], val;
+ default_vals[LINE_REQUEST_MAX_LINES], val;
PyObject *def_vals_obj = NULL, *iter, *next;
struct gpiod_line_request_config conf;
struct gpiod_line_bulk *bulk;
@@ -1413,7 +1415,7 @@ PyDoc_STRVAR(gpiod_LineBulk_get_values_doc,
static PyObject *gpiod_LineBulk_get_values(gpiod_LineBulkObject *self,
PyObject *Py_UNUSED(ignored))
{
- int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+ int rv, vals[LINE_REQUEST_MAX_LINES];
struct gpiod_line_bulk *bulk;
PyObject *val_list, *val;
Py_ssize_t i;
@@ -1506,7 +1508,7 @@ PyDoc_STRVAR(gpiod_LineBulk_set_values_doc,
static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self,
PyObject *args)
{
- int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+ int rv, vals[LINE_REQUEST_MAX_LINES];
struct gpiod_line_bulk *bulk;
PyObject *val_list;
@@ -1556,7 +1558,7 @@ PyDoc_STRVAR(gpiod_LineBulk_set_config_doc,
static PyObject *gpiod_LineBulk_set_config(gpiod_LineBulkObject *self,
PyObject *args)
{
- int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+ int rv, vals[LINE_REQUEST_MAX_LINES];
struct gpiod_line_bulk *bulk;
PyObject *val_list;
const int *valp;
@@ -1672,7 +1674,7 @@ static PyObject *gpiod_LineBulk_set_direction_output(
gpiod_LineBulkObject *self,
PyObject *args)
{
- int rv, vals[GPIOD_LINE_BULK_MAX_LINES];
+ int rv, vals[LINE_REQUEST_MAX_LINES];
struct gpiod_line_bulk *bulk;
PyObject *val_list;
const int *valp;
@@ -225,17 +225,10 @@ gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names) GPIOD_API;
* on multiple lines at once.
*/
-/**
- * @brief Maximum number of GPIO lines that can be requested at once or stored
- * in a line bulk object at the same time.
- */
-#define GPIOD_LINE_BULK_MAX_LINES 64
-
/**
* @brief Allocate and initialize a new line bulk object.
* @param max_lines Maximum number of lines this object can hold.
* @return New line bulk object or NULL on error.
- * @note max_lines must not exceed ::GPIOD_LINE_BULK_MAX_LINES.
*/
struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines) GPIOD_API;
@@ -22,6 +22,8 @@
#include <sys/types.h>
#include <unistd.h>
+#define LINE_REQUEST_MAX_LINES 64
+
enum {
LINE_FREE = 0,
LINE_REQUESTED_VALUES,
@@ -94,7 +96,7 @@ struct gpiod_line_bulk *gpiod_line_bulk_new(unsigned int max_lines)
struct gpiod_line_bulk *bulk;
size_t size;
- if (max_lines < 1 || max_lines > GPIOD_LINE_BULK_MAX_LINES) {
+ if (max_lines == 0) {
errno = EINVAL;
return NULL;
}
@@ -1066,7 +1068,7 @@ int gpiod_line_set_flags(struct gpiod_line *line, int flags)
int gpiod_line_set_flags_bulk(struct gpiod_line_bulk *bulk, int flags)
{
struct gpiod_line *line;
- int values[GPIOD_LINE_BULK_MAX_LINES];
+ int values[LINE_REQUEST_MAX_LINES];
unsigned int i;
int direction;
@@ -1129,7 +1131,7 @@ int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
const struct timespec *timeout,
struct gpiod_line_bulk *event_bulk)
{
- struct pollfd fds[GPIOD_LINE_BULK_MAX_LINES];
+ struct pollfd fds[LINE_REQUEST_MAX_LINES];
unsigned int off, num_lines;
struct gpiod_line *line;
int rv;
@@ -20,15 +20,6 @@ GPIOD_TEST_CASE(alloc_zero_lines, 0, { 1 })
g_assert_cmpint(errno, ==, EINVAL);
}
-GPIOD_TEST_CASE(alloc_too_many_lines, 0, { 1 })
-{
- struct gpiod_line_bulk *bulk;
-
- bulk = gpiod_line_bulk_new(GPIOD_LINE_BULK_MAX_LINES + 1);
- g_assert_null(bulk);
- g_assert_cmpint(errno, ==, EINVAL);
-}
-
GPIOD_TEST_CASE(add_too_many_lines, 0, { 8 })
{
g_autoptr(gpiod_line_bulk_struct) bulk = NULL;
@@ -157,7 +157,7 @@ static void handle_signal(int signum UNUSED)
int main(int argc, char **argv)
{
- unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES], num_lines = 0, offset,
+ unsigned int offsets[64], num_lines = 0, offset,
events_wanted = 0, events_done = 0, x;
bool watch_rising = false, watch_falling = false;
int flags = 0;
@@ -241,6 +241,9 @@ int main(int argc, char **argv)
if (argc < 2)
die("at least one GPIO line offset must be specified");
+ if (argc > 65)
+ die("too many offsets given");
+
for (i = 1; i < argc; i++) {
offset = strtoul(argv[i], &end, 10);
if (*end != '\0' || offset > INT_MAX)