From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [libgpiod][PATCH 04/16] treewide: unify gpiod_line_config/request_get_offsets() functions
Date: Mon, 16 Jan 2023 08:14:53 +0800 [thread overview]
Message-ID: <Y8SW/frUy16O67Kb@sol> (raw)
In-Reply-To: <20230113215210.616812-5-brgl@bgdev.pl>
On Fri, Jan 13, 2023 at 10:51:58PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> We have two functions in the C API that allow users to retrieve a list
> of offsets from objects: gpiod_line_request_get_offsets() and
> gpiod_line_config_get_offsets(). Even though they serve pretty much the
> same purpose, they have different signatures and one of them also
> requires the user to free the memory allocated within the libgpiod
> library with a non-libgpiod free() function.
>
They differ because they operate in different circumstances.
Requests are immutable, wrt lines/offsets, while configs are not.
More on this below.
> Unify them: make them take the array in which to store offsets and the
> size of this array. Make them return the number of offsets actually
> stored in the array and make them impossible to fail. Change their names
> to be more descriptive and in the case of line_config: add a new function
> that allows users to get the number of configured offsets.
>
Not sure symmetry => beauty in this case.
> Update the entire tree to use the new interfaces.
>
> For rust bindings: also unify the line config interface to return a map
> of line settings like C++ bindings do instead of having a function to
> get settings by offset. A map returned from a single call is easier to
> iterate over with a for loop than using an integer and calling the
> previous line_settings() method.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
<snip>
> --- a/include/gpiod.h
> +++ b/include/gpiod.h
> @@ -780,19 +780,29 @@ struct gpiod_line_settings *
> gpiod_line_config_get_line_settings(struct gpiod_line_config *config,
> unsigned int offset);
>
> +/**
> + * @brief Get the number of configured line offsets.
> + * @param config Line config object.
> + * @return Number of offsets for which line settings have been added.
> + */
> +size_t
> +gpiod_line_config_get_num_configured_offsets(struct gpiod_line_config *config);
> +
^^^^^^ ^^^^^^^^^^
Not a fan of the stuttering.
What other kinds of lines are there in the config?
Similarly requested lines in the request.
> /**
> * @brief Get configured offsets.
> * @param config Line config object.
> - * @param num_offsets Pointer to a variable in which the number of line offsets
> - * will be stored.
> - * @param offsets Pointer to a pointer which will be set to point to an array
> - * containing the configured offsets. The array will be allocated
> - * using malloc() and must be freed using free().
> - * @return 0 on success, -1 on failure.
> + * @param offsets Array to store offsets.
> + * @param max_offsets Number of offsets that can be stored in the offsets array.
> + * @return Number of offsets stored in the offsets array.
> + *
> + * If max_offsets is lower than the number of lines actually requested (this
> + * value can be retrieved using ::gpiod_line_config_get_num_configured_offsets),
> + * then only up to max_lines offsets will be stored in offsets.
> */
> -int gpiod_line_config_get_offsets(struct gpiod_line_config *config,
> - size_t *num_offsets,
> - unsigned int **offsets);
> +size_t
> +gpiod_line_config_get_configured_offsets(struct gpiod_line_config *config,
> + unsigned int *offsets,
> + size_t max_offsets);
>
So, to be sure that they have all the offsets, the user needs to call
gpiod_line_config_get_num_configured_offsets() before every call to
gpiod_line_config_get_configured_offsets()?
Unless they can be sure no lines have been added subsequently?
Another way of looking at it is that the old API combines those two
functions in one, hence the difference from the request equivalent.
The old way you got them all, no matter what and no questions asked.
That seems simpler to me, so I'm not sure this is a step forward.
Cheers,
Kent.
next prev parent reply other threads:[~2023-01-16 0:15 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 21:51 [libgpiod][PATCH 00/16] treewide: continue beating libgpiod v2 into shape for an upcoming release Bartosz Golaszewski
2023-01-13 21:51 ` [libgpiod][PATCH 01/16] README: update for libgpiod v2 Bartosz Golaszewski
2023-01-14 11:14 ` Andy Shevchenko
2023-01-13 21:51 ` [libgpiod][PATCH 02/16] tests: avoid shadowing local variables with common names in macros Bartosz Golaszewski
2023-01-14 11:16 ` Andy Shevchenko
2023-01-13 21:51 ` [libgpiod][PATCH 03/16] build: unify the coding style of source files lists in Makefiles Bartosz Golaszewski
2023-01-13 21:51 ` [libgpiod][PATCH 04/16] treewide: unify gpiod_line_config/request_get_offsets() functions Bartosz Golaszewski
2023-01-16 0:14 ` Kent Gibson [this message]
2023-01-16 21:37 ` Bartosz Golaszewski
2023-01-16 23:39 ` Kent Gibson
2023-01-16 5:52 ` Viresh Kumar
2023-01-16 21:39 ` Bartosz Golaszewski
2023-01-17 5:44 ` Viresh Kumar
2023-01-18 20:51 ` Bartosz Golaszewski
2023-01-19 5:15 ` Viresh Kumar
2023-01-23 8:24 ` Viresh Kumar
2023-01-23 8:31 ` Bartosz Golaszewski
2023-01-23 13:58 ` Bartosz Golaszewski
2023-01-24 6:44 ` Viresh Kumar
2023-01-13 21:51 ` [libgpiod][PATCH 05/16] doc: update docs for libgpiod v2 Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 06/16] bindings: cxx: prepend all C symbols with the scope resolution operator Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 07/16] bindings: cxx: allow to copy line_settings Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 08/16] tests: fix the line config reset test case Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 09/16] tests: add a helper for reading back line settings from line config Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 10/16] core: provide gpiod_line_config_set_output_values() Bartosz Golaszewski
2023-01-16 0:15 ` Kent Gibson
2023-01-16 22:23 ` Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 11/16] gpioset: use gpiod_line_config_set_output_values() Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 12/16] bindings: cxx: add line_config.set_output_values() Bartosz Golaszewski
2023-01-14 11:20 ` Andy Shevchenko
2023-01-13 21:52 ` [libgpiod][PATCH 13/16] bindings: python: provide line_config.set_output_values() Bartosz Golaszewski
2023-01-13 21:52 ` [libgpiod][PATCH 14/16] bindings: rust: make request_config optional in Chip.request_lines() Bartosz Golaszewski
2023-01-16 5:55 ` Viresh Kumar
2023-01-13 21:52 ` [libgpiod][PATCH 15/16] bindings: rust: make mutators return &mut self Bartosz Golaszewski
2023-01-16 6:02 ` Viresh Kumar
2023-01-16 8:42 ` Bartosz Golaszewski
2023-01-16 9:40 ` Viresh Kumar
2023-01-16 12:57 ` Bartosz Golaszewski
2023-01-17 5:19 ` Viresh Kumar
2023-01-13 21:52 ` [libgpiod][PATCH 16/16] bindings: rust: provide line_config.set_output_values() Bartosz Golaszewski
2023-01-16 6:09 ` Viresh Kumar
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=Y8SW/frUy16O67Kb@sol \
--to=warthog618@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).