[alsa-lib][PATCH 0/6] add API of equality and comparison for a pair of control element IDs
Takashi Sakamoto
o-takashi at sakamocchi.jp
Thu Mar 18 11:30:07 CET 2021
Hi,
This patchset is a fix for bug issued in the message thread[1].
In this development period, alsa-lib got new API as implementation for
one of comparison algorithms to a pair of control element IDs. However,
it has several issues.
At first, the name, 'snd_ctl_elem_id_compare()', is inappropriate since it
implements one of comparison algorithms. The name itself implies the
algorithm is single and unique for control element ID. However, the
target structure, 'struct snd_ctl_elem_id', is hybrid and compound one.
We can not find such single and unique comparison algorithm for it.
Secondary, it subtracts a pair of values in fields of 'unsigned int' type
in storage size of the type. It brings integer overflow.
Tertiary, it has simple bug to compare subdevice field in the same structure.
Essentially, equality is different from comparison. In a point of programming,
implementation for comparison algorithm can have more overhead than
implementation for equality. In this meaning, it's better to add different API
for them.
This patchset adds new API below:
* for equality
* snd_ctl_elem_id_equal_by_numid()
* snd_ctl_elem_id_equal_by_tuple()
* for each comparison algorithm
* snd_ctl_elem_id_compare_by_numid()
* snd_ctl_elem_id_compare_by_tuple_arithmetic()
I've got bothered to decide the name of API for the case to use tuples.
Here I use the word, 'tuple', which comes from documentation of alsa-lib[2].
Furthermore, this patchset adds test program for them since equality and
comparison are quite basic method to operate data. It's better to have no
bug.
Finally, the issued API, 'snd_ctl_elem_id_compare()' is dropped. After
merging the patchset, I'm going to post additional patch to alsa-utils to
fix issued line[3].
[1] https://mailman.alsa-project.org/pipermail/alsa-devel/2021-March/181738.html
[2] https://github.com/alsa-project/alsa-lib/blob/master/src/control/control.c#L80
[3] https://github.com/alsa-project/alsa-utils/blob/master/alsactl/clean.c#L55
Regards
Takashi Sakamoto (6):
test: ctl-elem-id: add test program for future APIs relevant to
control element ID
ctl: add API to check equality between a pair of control element IDs
by numid
ctl: add API to check equality between a pair of control element IDs
by tuple
ctl: add API to compare a pair of control element IDs by numid
ctl: add API to compare a pair of control element IDs by one of
algorithms according to tuple
ctl: drop deprecated API to compare a pair of control element IDs
include/control.h | 5 +-
src/control/control.c | 135 ++++++++++++++----
test/lsb/Makefile.am | 6 +-
test/lsb/ctl-elem-id.c | 301 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 418 insertions(+), 29 deletions(-)
create mode 100644 test/lsb/ctl-elem-id.c
--
2.27.0
More information about the Alsa-devel
mailing list