diff --git a/src/libAtomVM/defaultatoms.c b/src/libAtomVM/defaultatoms.c index ac4e79a3a..11b607174 100644 --- a/src/libAtomVM/defaultatoms.c +++ b/src/libAtomVM/defaultatoms.c @@ -23,10 +23,17 @@ #include #include +// About X macro: https://en.wikipedia.org/wiki/X_macro +#if __has_builtin(__builtin_strlen) +#define X(name, lenstr, str) \ + _Static_assert(lenstr[0] == __builtin_strlen(str), "Macro length mismatch for " # name); +#include "defaultatoms.def" +#undef X +#endif + void defaultatoms_init(GlobalContext *glb) { -// About X macro: https://en.wikipedia.org/wiki/X_macro #define X(name, lenstr, str) \ lenstr str, @@ -39,10 +46,6 @@ void defaultatoms_init(GlobalContext *glb) #undef X for (int i = 0; i < PLATFORM_ATOMS_BASE_INDEX; i++) { - if (UNLIKELY((size_t) atoms[i][0] != strlen(atoms[i] + 1))) { - AVM_ABORT(); - } - if (UNLIKELY(globalcontext_insert_atom(glb, atoms[i]) != i)) { AVM_ABORT(); } diff --git a/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c b/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c index 412d03b64..9bb0d2cff 100644 --- a/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c +++ b/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c @@ -23,9 +23,16 @@ #include #include +// About X macro: https://en.wikipedia.org/wiki/X_macro +#if __has_builtin(__builtin_strlen) +#define X(name, lenstr, str) \ + _Static_assert(lenstr[0] == __builtin_strlen(str), "Macro length mismatch for " # name); +#include "platform_defaultatoms.def" +#undef X +#endif + void platform_defaultatoms_init(GlobalContext *glb) { -// About X macro: https://en.wikipedia.org/wiki/X_macro #define X(name, lenstr, str) \ lenstr str, @@ -38,10 +45,6 @@ void platform_defaultatoms_init(GlobalContext *glb) #undef X for (int i = 0; i < ATOM_FIRST_AVAIL_INDEX - PLATFORM_ATOMS_BASE_INDEX; i++) { - if (UNLIKELY((size_t) atoms[i][0] != strlen(atoms[i] + 1))) { - AVM_ABORT(); - } - if (UNLIKELY(globalcontext_insert_atom(glb, atoms[i]) != i + PLATFORM_ATOMS_BASE_INDEX)) { AVM_ABORT(); } diff --git a/src/platforms/generic_unix/lib/platform_defaultatoms.c b/src/platforms/generic_unix/lib/platform_defaultatoms.c index 412d03b64..9bb0d2cff 100644 --- a/src/platforms/generic_unix/lib/platform_defaultatoms.c +++ b/src/platforms/generic_unix/lib/platform_defaultatoms.c @@ -23,9 +23,16 @@ #include #include +// About X macro: https://en.wikipedia.org/wiki/X_macro +#if __has_builtin(__builtin_strlen) +#define X(name, lenstr, str) \ + _Static_assert(lenstr[0] == __builtin_strlen(str), "Macro length mismatch for " # name); +#include "platform_defaultatoms.def" +#undef X +#endif + void platform_defaultatoms_init(GlobalContext *glb) { -// About X macro: https://en.wikipedia.org/wiki/X_macro #define X(name, lenstr, str) \ lenstr str, @@ -38,10 +45,6 @@ void platform_defaultatoms_init(GlobalContext *glb) #undef X for (int i = 0; i < ATOM_FIRST_AVAIL_INDEX - PLATFORM_ATOMS_BASE_INDEX; i++) { - if (UNLIKELY((size_t) atoms[i][0] != strlen(atoms[i] + 1))) { - AVM_ABORT(); - } - if (UNLIKELY(globalcontext_insert_atom(glb, atoms[i]) != i + PLATFORM_ATOMS_BASE_INDEX)) { AVM_ABORT(); }