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

gnrc/icmpv6: conditional definition of the MIN macro #14358

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Jun 25, 2020

Contribution description

While implementing the inlined version of irq_* functions according to PR #13999 and issue #14356, I ran into a compilation problem with the MIN macro definition in sys/net/gnrc/network_layer/icmpv6/error/gnrc_icmpv6_error.c.

Since min(a,b) is a very frequently used function, several libraries such as the ESP8266 SDK define their own MIN macro in their header files. Therefore the MIN macro in gnrc/icmpv6 should only be defined if it has not been defined anywhere else before.

Testing procedure

Compilation in Murdock should succeed.

Issues/PRs references

@gschorcht gschorcht added Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Jun 25, 2020
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather use #undef?

@@ -27,7 +27,9 @@
#define ICMPV6_ERROR_SET_VALUE(data, value) \
((icmpv6_error_pkt_too_big_t *)(data))->mtu = byteorder_htonl(value)

#ifndef MIN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rather use

Suggested change
#ifndef MIN
#undef MIN /* undefine common name just to be safe */

in case MIN is not actually determining the minimum between two values (could also be just 60 for MINutes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@maribu
Copy link
Member

maribu commented Jun 25, 2020

I wonder why RIOT does not have a definition of MIN() in kernel_defines.h or somewhere. This would be useful enough for other places.

@miri64
Copy link
Member

miri64 commented Jun 25, 2020

I wonder why RIOT does not have a definition of MIN() in kernel_defines.h or somewhere. This would be useful enough for other places.

See discussion #13530 (comment) ff

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK from my side. I agree that Murdock compilation is enough to test this. Please squash.

Since `min(a,b)` is a very frequently used function, several libraries such as ESP8266 SDK define a `MIN` macro in their header files. Therefore the `MIN` macro should be undefined before its definition to avoid compilation errors if it is defined anywhere else before.
@gschorcht gschorcht force-pushed the sys/net/gnrc/icmpv6/conditional_min_definition branch from a6e5e1f to a440ae7 Compare June 25, 2020 15:31
@miri64 miri64 merged commit 2bb9a39 into RIOT-OS:master Jun 25, 2020
@gschorcht
Copy link
Contributor Author

@miri64 Thanks for reviewing and merging.

@gschorcht gschorcht deleted the sys/net/gnrc/icmpv6/conditional_min_definition branch June 26, 2020 08:51
@miri64 miri64 added this to the Release 2020.07 milestone Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants