8000 Use _Static_assert to check macro lengths by pguyot · Pull Request #1471 · atomvm/AtomVM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use _Static_assert to check macro lengths #1471

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pguyot
Copy link
Collaborator
@pguyot pguyot commented Jan 14, 2025

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@pguyot pguyot force-pushed the w03/static-assert-atoms branch 2 times, most recently from 7dbf999 to 2bb0dd7 Compare January 14, 2025 21:35
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
@pguyot pguyot force-pushed the w03/static-assert-atoms branch from 2bb0dd7 to 2ae1afd Compare January 14, 2025 22:11
Comment on lines +27 to +30
#define X(name, lenstr, str) \
_Static_assert(*lenstr == strlen(str), "Macro length mismatch for " # name);
#include "platform_defaultatoms.def"
#undef X
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe using assert.h with static_assert() would be a bit nicer.

@@ -23,10 +23,15 @@
#include <stdlib.h>
#include <string.h>

// About X macro: https://en.wikipedia.org/wiki/X_macro
#define X(name, lenstr, str) \
_Static_assert(*lenstr == strlen(str), "Macro length mismatch for " # name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was waiting this check for quite some time, let's enable it only with clang >= 17. That will be enough at least for blocking any PR that introduces some atom length bug.

Copy link
Collaborator
@bettio bettio left a comment

Choose a reason for hiding this comment

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

Let's make CI green with this.

@pguyot pguyot marked this pull request as draft January 18, 2025 09:54
@bettio
Copy link
Collaborator
bettio commented Feb 12, 2025

I think we should just enable this on the right version of clang, and then merge it.
It is useful and we are close to have it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0