diff --git a/src/libAtomVM/defaultatoms.c b/src/libAtomVM/defaultatoms.c index ac4e79a3a..d74bee380 100644 --- a/src/libAtomVM/defaultatoms.c +++ b/src/libAtomVM/defaultatoms.c @@ -23,10 +23,15 @@ #include #include +// 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); +#include "defaultatoms.def" +#undef X + void defaultatoms_init(GlobalContext *glb) { -// About X macro: https://en.wikipedia.org/wiki/X_macro #define X(name, lenstr, str) \ lenstr str, @@ -39,10 +44,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..3adcbf3d7 100644 --- a/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c +++ b/src/platforms/esp32/components/avm_sys/platform_defaultatoms.c @@ -23,9 +23,14 @@ #include #include +// 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); +#include "platform_defaultatoms.def" +#undef X + 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 +43,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..3adcbf3d7 100644 --- a/src/platforms/generic_unix/lib/platform_defaultatoms.c +++ b/src/platforms/generic_unix/lib/platform_defaultatoms.c @@ -23,9 +23,14 @@ #include #include +// 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); +#include "platform_defaultatoms.def" +#undef X + 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 +43,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(); }