All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Jack Winch <sunt.un.morcov@gmail.com>,
	Helmut Grohne <helmut.grohne@intenta.de>,
	Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [libgpiod][PATCH 11/14] treewide: kill find_lines()
Date: Thu, 10 Dec 2020 14:23:12 +0100	[thread overview]
Message-ID: <20201210132315.5785-12-brgl@bgdev.pl> (raw)
In-Reply-To: <20201210132315.5785-1-brgl@bgdev.pl>

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

GPIO line names are not unique. Looking up multiple lines by names would
require us to return a list of matching lines for every name. We're
simplifying the library API so drop this interface treewide.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 bindings/cxx/chip.cpp                  | 18 ------
 bindings/cxx/gpiod.hpp                 |  7 ---
 bindings/cxx/tests/tests-chip.cpp      | 18 ------
 bindings/python/gpiodmodule.c          | 86 --------------------------
 bindings/python/tests/gpiod_py_test.py | 32 ----------
 include/gpiod.h                        | 15 -----
 lib/helpers.c                          | 28 ---------
 tests/tests-chip.c                     | 49 ---------------
 8 files changed, 253 deletions(-)

diff --git a/bindings/cxx/chip.cpp b/bindings/cxx/chip.cpp
index dffa7a2..ff35e53 100644
--- a/bindings/cxx/chip.cpp
+++ b/bindings/cxx/chip.cpp
@@ -154,24 +154,6 @@ line_bulk chip::get_all_lines(void) const
 	return lines;
 }
 
-line_bulk chip::find_lines(const ::std::vector<::std::string>& names) const
-{
-	line_bulk lines;
-	line line;
-
-	for (auto& it: names) {
-		line = this->find_line(it);
-		if (!line) {
-			lines.clear();
-			return lines;
-		}
-
-		lines.append(line);
-	}
-
-	return lines;
-}
-
 bool chip::operator==(const chip& rhs) const noexcept
 {
 	return this->_m_chip.get() == rhs._m_chip.get();
diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp
index b258730..a16a27c 100644
--- a/bindings/cxx/gpiod.hpp
+++ b/bindings/cxx/gpiod.hpp
@@ -146,13 +146,6 @@ public:
 	 */
 	GPIOD_API line_bulk get_all_lines(void) const;
 
-	/**
-	 * @brief Get a set of lines exposed by this chip by their names.
-	 * @param names Vector of line names.
-	 * @return Set of lines held by a line_bulk object.
-	 */
-	GPIOD_API line_bulk find_lines(const ::std::vector<::std::string>& names) const;
-
 	/**
 	 * @brief Equality operator.
 	 * @param rhs Right-hand side of the equation.
diff --git a/bindings/cxx/tests/tests-chip.cpp b/bindings/cxx/tests/tests-chip.cpp
index 4c9f113..90ebc1b 100644
--- a/bindings/cxx/tests/tests-chip.cpp
+++ b/bindings/cxx/tests/tests-chip.cpp
@@ -191,17 +191,6 @@ TEST_CASE("Lines can be retrieved from chip objects", "[chip]")
 		REQUIRE(lines.get(2).name() == "gpio-mockup-B-3");
 		REQUIRE(lines.get(3).name() == "gpio-mockup-B-2");
 	}
-
-	SECTION("find multiple lines by names")
-	{
-		auto lines = chip.find_lines({ "gpio-mockup-B-2",
-					       "gpio-mockup-B-5",
-					       "gpio-mockup-B-6"});
-		REQUIRE(lines.size() == 3);
-		REQUIRE(lines.get(0).offset() == 2);
-		REQUIRE(lines.get(1).offset() == 5);
-		REQUIRE(lines.get(2).offset() == 6);
-	}
 }
 
 TEST_CASE("All lines can be retrieved from a chip at once", "[chip]")
@@ -236,11 +225,4 @@ TEST_CASE("Errors occurring when retrieving lines are correctly reported", "[chi
 	{
 		REQUIRE_FALSE(chip.find_line("nonexistent-line"));
 	}
-
-	SECTION("line not found by name (multiple lines)")
-	{
-		REQUIRE_FALSE(chip.find_lines({ "gpio-mockup-B-2",
-						"nonexistent-line",
-						"gpio-mockup-B-6"}));
-	}
 }
diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
index bcaae92..4948d5d 100644
--- a/bindings/python/gpiodmodule.c
+++ b/bindings/python/gpiodmodule.c
@@ -2339,86 +2339,6 @@ gpiod_Chip_get_all_lines(gpiod_ChipObject *self, PyObject *Py_UNUSED(ignored))
 	return bulk_obj;
 }
 
-PyDoc_STRVAR(gpiod_Chip_find_lines_doc,
-"find_lines(names) -> gpiod.LineBulk object\n"
-"\n"
-"Look up a set of lines by their names.\n"
-"\n"
-"  names\n"
-"    Sequence of line names.\n"
-"\n"
-"Unlike find_line(), this method raises an exception if at least one line\n"
-"from the list doesn't exist.");
-
-static gpiod_LineBulkObject *
-gpiod_Chip_find_lines(gpiod_ChipObject *self, PyObject *args)
-{
-	PyObject *names, *lines, *iter, *next, *arg;
-	gpiod_LineBulkObject *bulk;
-	Py_ssize_t num_names, i;
-	gpiod_LineObject *line;
-	int rv;
-
-	rv = PyArg_ParseTuple(args, "O", &names);
-	if (!rv)
-		return NULL;
-
-	num_names = PyObject_Size(names);
-	if (num_names < 1) {
-		PyErr_SetString(PyExc_TypeError,
-				"Argument must be a non-empty sequence of names");
-		return NULL;
-	}
-
-	lines = PyList_New(num_names);
-	if (!lines)
-		return NULL;
-
-	iter = PyObject_GetIter(names);
-	if (!iter) {
-		Py_DECREF(lines);
-		return NULL;
-	}
-
-	for (i = 0;;) {
-		next = PyIter_Next(iter);
-		if (!next) {
-			Py_DECREF(iter);
-			break;
-		}
-
-		arg = PyTuple_Pack(1, next);
-		if (!arg) {
-			Py_DECREF(iter);
-			Py_DECREF(lines);
-			return NULL;
-		}
-
-		line = gpiod_Chip_find_line(self, arg);
-		Py_DECREF(arg);
-		if (!line || (PyObject *)line == Py_None) {
-			Py_DECREF(iter);
-			Py_DECREF(lines);
-			if ((PyObject *)line == Py_None)
-				PyErr_SetString(PyExc_TypeError,
-						"Unable to find all lines from the list");
-			return NULL;
-		}
-
-		rv = PyList_SetItem(lines, i++, (PyObject *)line);
-		if (rv < 0) {
-			Py_DECREF(line);
-			Py_DECREF(iter);
-			Py_DECREF(lines);
-			return NULL;
-		}
-	}
-
-	bulk = gpiod_ListToLineBulk(lines);
-	Py_DECREF(lines);
-	return bulk;
-}
-
 static PyMethodDef gpiod_Chip_methods[] = {
 	{
 		.ml_name = "close",
@@ -2480,12 +2400,6 @@ static PyMethodDef gpiod_Chip_methods[] = {
 		.ml_flags = METH_NOARGS,
 		.ml_doc = gpiod_Chip_get_all_lines_doc,
 	},
-	{
-		.ml_name = "find_lines",
-		.ml_meth = (PyCFunction)gpiod_Chip_find_lines,
-		.ml_flags = METH_VARARGS,
-		.ml_doc = gpiod_Chip_find_lines_doc,
-	},
 	{ }
 };
 
diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py
index 8534ce9..6ee72a9 100755
--- a/bindings/python/tests/gpiod_py_test.py
+++ b/bindings/python/tests/gpiod_py_test.py
@@ -182,30 +182,6 @@ class ChipGetLines(MockupTestCase):
             self.assertEqual(lines[2].name(), 'gpio-mockup-B-6')
             self.assertEqual(lines[3].name(), 'gpio-mockup-B-7')
 
-    def test_find_multiple_lines_by_names_in_tuple(self):
-        with gpiod.Chip(mockup.chip_name(1)) as chip:
-            lines = chip.find_lines(( 'gpio-mockup-B-0',
-                                      'gpio-mockup-B-3',
-                                      'gpio-mockup-B-4',
-                                      'gpio-mockup-B-6' )).to_list()
-            self.assertEqual(len(lines), 4)
-            self.assertEqual(lines[0].offset(), 0)
-            self.assertEqual(lines[1].offset(), 3)
-            self.assertEqual(lines[2].offset(), 4)
-            self.assertEqual(lines[3].offset(), 6)
-
-    def test_find_multiple_lines_by_names_in_list(self):
-        with gpiod.Chip(mockup.chip_name(1)) as chip:
-            lines = chip.find_lines([ 'gpio-mockup-B-0',
-                                      'gpio-mockup-B-3',
-                                      'gpio-mockup-B-4',
-                                      'gpio-mockup-B-6' ]).to_list()
-            self.assertEqual(len(lines), 4)
-            self.assertEqual(lines[0].offset(), 0)
-            self.assertEqual(lines[1].offset(), 3)
-            self.assertEqual(lines[2].offset(), 4)
-            self.assertEqual(lines[3].offset(), 6)
-
     def test_get_multiple_lines_invalid_offset(self):
         with gpiod.Chip(mockup.chip_name(1)) as chip:
             with self.assertRaises(OSError) as err_ctx:
@@ -213,14 +189,6 @@ class ChipGetLines(MockupTestCase):
 
             self.assertEqual(err_ctx.exception.errno, errno.EINVAL)
 
-    def test_find_multiple_lines_nonexistent(self):
-        with gpiod.Chip(mockup.chip_name(1)) as chip:
-            with self.assertRaises(TypeError):
-                lines = chip.find_lines(( 'gpio-mockup-B-0',
-                                          'nonexistent-line',
-                                          'gpio-mockup-B-4',
-                                          'gpio-mockup-B-6' )).to_list()
-
     def test_get_all_lines(self):
         with gpiod.Chip(mockup.chip_name(2)) as chip:
             lines = chip.get_all_lines().to_list()
diff --git a/include/gpiod.h b/include/gpiod.h
index 5aeb7cc..34313ed 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -184,21 +184,6 @@ gpiod_chip_get_all_lines(struct gpiod_chip *chip) GPIOD_API;
 struct gpiod_line *
 gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
 
-/**
- * @brief Find a set of GPIO lines by names among lines exposed by this chip.
- * @param chip The GPIO chip object.
- * @param names Array of pointers to C-strings containing the names of the
- *              lines to lookup. Must end with a NULL-pointer.
- * @return New line bulk object or NULL on error.
- * @note If at least one line from the list could not be found among the lines
- *       exposed by this chip, the function sets errno to ENOENT.
- * @attention GPIO line names are not unique in the linux kernel, neither
- *            globally nor within a single chip. This function finds the first
- *            line with given name.
- */
-struct gpiod_line_bulk *
-gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names) GPIOD_API;
-
 /**
  * @}
  *
diff --git a/lib/helpers.c b/lib/helpers.c
index 5a73736..509a1c8 100644
--- a/lib/helpers.c
+++ b/lib/helpers.c
@@ -142,34 +142,6 @@ gpiod_chip_find_line(struct gpiod_chip *chip, const char *name)
 	return NULL;
 }
 
-struct gpiod_line_bulk *
-gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names)
-{
-	struct gpiod_line_bulk *bulk;
-	struct gpiod_line *line;
-	unsigned int num_names;
-	int i;
-
-	for (i = 0; names[i]; i++);
-	num_names = i;
-
-	bulk = gpiod_line_bulk_new(num_names);
-	if (!bulk)
-		return NULL;
-
-	for (i = 0; names[i]; i++) {
-		line = gpiod_chip_find_line(chip, names[i]);
-		if (!line) {
-			gpiod_line_bulk_free(bulk);
-			return NULL;
-		}
-
-		gpiod_line_bulk_add_line(bulk, line);
-	}
-
-	return bulk;
-}
-
 int gpiod_line_request_input(struct gpiod_line *line, const char *consumer)
 {
 	struct gpiod_line_request_config config = {
diff --git a/tests/tests-chip.c b/tests/tests-chip.c
index 0c2948a..543c103 100644
--- a/tests/tests-chip.c
+++ b/tests/tests-chip.c
@@ -264,52 +264,3 @@ GPIOD_TEST_CASE(find_line_not_found, GPIOD_TEST_FLAG_NAMED_LINES, { 8, 8, 8 })
 	g_assert_null(line);
 	g_assert_cmpint(errno, ==, ENOENT);
 }
-
-GPIOD_TEST_CASE(find_lines_good, GPIOD_TEST_FLAG_NAMED_LINES, { 8, 8, 8 })
-{
-	static const gchar *names[] = { "gpio-mockup-B-3",
-					"gpio-mockup-B-6",
-					"gpio-mockup-B-7",
-					NULL };
-
-	g_autoptr(gpiod_line_bulk_struct) bulk = NULL;
-	g_autoptr(gpiod_chip_struct) chip = NULL;
-	struct gpiod_line *line0, *line1, *line2;
-
-	chip = gpiod_chip_open(gpiod_test_chip_path(1));
-	g_assert_nonnull(chip);
-	gpiod_test_return_if_failed();
-
-	bulk = gpiod_chip_find_lines(chip, names);
-	g_assert_nonnull(bulk);
-	gpiod_test_return_if_failed();
-	g_assert_cmpuint(gpiod_line_bulk_num_lines(bulk), ==, 3);
-	gpiod_test_return_if_failed();
-
-	line0 = gpiod_line_bulk_get_line(bulk, 0);
-	line1 = gpiod_line_bulk_get_line(bulk, 1);
-	line2 = gpiod_line_bulk_get_line(bulk, 2);
-
-	g_assert_cmpuint(gpiod_line_offset(line0), ==, 3);
-	g_assert_cmpuint(gpiod_line_offset(line1), ==, 6);
-	g_assert_cmpuint(gpiod_line_offset(line2), ==, 7);
-}
-
-GPIOD_TEST_CASE(fine_lines_not_found, GPIOD_TEST_FLAG_NAMED_LINES, { 8, 8, 8 })
-{
-	static const gchar *names[] = { "gpio-mockup-B-3",
-					"nonexistent",
-					"gpio-mockup-B-7",
-					NULL };
-
-	g_autoptr(gpiod_chip_struct) chip = NULL;
-	struct gpiod_line_bulk *bulk;
-
-	chip = gpiod_chip_open(gpiod_test_chip_path(1));
-	g_assert_nonnull(chip);
-	gpiod_test_return_if_failed();
-
-	bulk = gpiod_chip_find_lines(chip, names);
-	g_assert_null(bulk);
-	g_assert_cmpint(errno, ==, ENOENT);
-}
-- 
2.29.1


  parent reply	other threads:[~2020-12-10 13:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 13:23 [libgpiod][PATCH 00/14] treewide: start shaving off cruft for v2.0 Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 01/14] bindings: cxx: check for error from gpiod_line_bulk_new() Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 02/14] build: drop the message about tests having been built successfully Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 03/14] core: export gpiod_is_gpiochip_device() Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 04/14] bulk: drop the limit on the max number of lines Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 05/14] core: drop line iterators Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 06/14] treewide: kill opening chips by label Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 07/14] API: move gpiod_line_get_chip() to line attributes section Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 08/14] core: kill gpiod_line_close_chip() Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 09/14] core: kill gpiod_line_get() Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 10/14] treewide: kill global line lookup Bartosz Golaszewski
2020-12-10 13:23 ` Bartosz Golaszewski [this message]
2020-12-10 13:23 ` [libgpiod][PATCH 12/14] core: rework gpiod_chip_find_line() Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 13/14] build: add a configure switch for building examples Bartosz Golaszewski
2020-12-10 13:23 ` [libgpiod][PATCH 14/14] core: kill chip iterators Bartosz Golaszewski
2020-12-10 13:56 ` [libgpiod][PATCH 00/14] treewide: start shaving off cruft for v2.0 Andy Shevchenko
2020-12-11  8:38   ` Bartosz Golaszewski
2020-12-11 14:31     ` Andy Shevchenko
2020-12-11 14:33       ` Bartosz Golaszewski
2020-12-11 14:58         ` Andy Shevchenko
2020-12-11 15:06           ` Bartosz Golaszewski
2020-12-14 15:02   ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201210132315.5785-12-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=geert@linux-m68k.org \
    --cc=helmut.grohne@intenta.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sunt.un.morcov@gmail.com \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.