Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include: util: Add memeq and bool_memcmp #84159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

theob-pro
Copy link
Contributor

Those two functions are used to compare memory area. bool_memcmp is basically memcmp but return a bool instead of an int. memeq compare the length of the memory area in addition to the bytes themselves.

`memeq` compare two memory areas and their length. It returns true
if they are equal, else false.

`bool_memcmp` the first n bytes of two memory areas. It returns true if
they are equal, else false.

Signed-off-by: Théo Battrel <[email protected]>
Add two unit tests for the newly added functions `memeq` and `bool_memcmp`.

Signed-off-by: Théo Battrel <[email protected]>
@pdgendt
Copy link
Collaborator

pdgendt commented Jan 17, 2025

I don't see the benefit of adding these, sorry.

@theob-pro
Copy link
Contributor Author

I don't see the benefit of adding these, sorry.

No worries, it may not be useful for everyone 😀
More context on the discussion I had with @Thalley on this PR: #84018

@pdgendt
Copy link
Collaborator

pdgendt commented Jan 17, 2025

No worries, it may not be useful for everyone 😀 More context on the discussion I had with @Thalley on this PR: #84018

What I mean was that I don't see any added value of introducing what basically is an alias...

if (memeq(buf1, size1, buf2, size2)) { /* ... */ }
/* vs */
if (size1 == size2 && memcmp(buf1, buf2, size1) == 0) { /* ... */ }

@andyross
Copy link
Contributor

Tend to agree with @pdgendt, we don't want to be pushing APIs that compete with well-established controlling idioms (like the ISO C standard memcmp() in this case, but we take stuff from Linux too).

@theob-pro
Copy link
Contributor Author

What I mean was that I don't see any added value of introducing what basically is an alias...

Maybe I am missing something but that file is full of aliases... I don't see the problem with adding new ones

Tend to agree with @pdgendt, we don't want to be pushing APIs that compete with well-established controlling idioms (like the ISO C standard memcmp() in this case, but we take stuff from Linux too).

I struggle to understand the reasoning about APIs that compete, sorry, could you develop? And those function are just more convenient to use. Nobody is forced to use them 😅

@pdgendt
Copy link
Collaborator

pdgendt commented Jan 17, 2025

Maybe I am missing something but that file is full of aliases... I don't see the problem with adding new ones

I disagree. The file, in my opinion, provides common functions people tend to get wrong or inefficient implementations of.

I struggle to understand the reasoning about APIs that compete, sorry, could you develop? And those function are just more convenient to use. Nobody is forced to use them 😅

Nobody is forced to use them, but suddenly memeq is almost globally defined as zephyr/sys/util.h will likely be included in some way or another.

@theob-pro
Copy link
Contributor Author

I disagree. The file, in my opinion, provides common functions people tend to get wrong or inefficient implementations of.

Sorry but I must insist, there is an alias for is_power_of_two, macro for IN_RANGE, MIN and MAX, a macro for casting a pointer to an unsigned integer. Those functions and macro are there for quality of life, for making code more readable in the end.

Nobody is forced to use them, but suddenly memeq is almost globally defined as zephyr/sys/util.h will likely be included in some way or another.

Sorry, I don't understand, what is the problem here? It will not be included in people code if they don't use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Base OS Base OS Library (lib/os) area: Testsuite Testsuite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants