diff --git a/m-core.h b/m-core.h index ecc6c0bf..770957d0 100644 --- a/m-core.h +++ b/m-core.h @@ -279,6 +279,16 @@ M_BEGIN_PROTECTED_CODE #endif +/* If within the M*LIB tests, perform additional (potentialy slow) checks */ +#ifndef M_ASSERT_SLOW +# if defined(M_USE_ADDITIONAL_CHECKS) && M_USE_ADDITIONAL_CHECKS +# define M_ASSERT_SLOW(n) assert(n) +# else +# define M_ASSERT_SLOW(n) (void) 0 +# endif +#endif + + /* Always perform a runtime check of the given condition * NOTE: Can be overiden by user if it needs to keep finer access * on the assertions or display message on another device. diff --git a/m-serial-bin.h b/m-serial-bin.h index a79bd4cc..0bd0e6cf 100644 --- a/m-serial-bin.h +++ b/m-serial-bin.h @@ -181,7 +181,7 @@ m_serial_bin_write_float(m_serial_write_t serial, const long double data, const static inline m_serial_return_code_t m_serial_bin_write_string(m_serial_write_t serial, const char data[], size_t length) { - STRINGI_ASSERT_SLOW(length == strlen(data) ); + M_ASSERT_SLOW(length == strlen(data) ); FILE *f = (FILE *)serial->data[0].p; M_ASSERT(f != NULL && data != NULL); // Write first the number of (non null) characters diff --git a/m-serial-json.h b/m-serial-json.h index 26d212ea..a1045881 100644 --- a/m-serial-json.h +++ b/m-serial-json.h @@ -67,7 +67,7 @@ m_serial_json_write_float(m_serial_write_t serial, const long double data, const static inline m_serial_return_code_t m_serial_json_write_string(m_serial_write_t serial, const char data[], size_t length) { - STRINGI_ASSERT_SLOW(length == strlen(data) ); + M_ASSERT_SLOW(length == strlen(data) ); FILE *f = (FILE *)serial->data[0].p; M_ASSERT(f != NULL && data != NULL); /* HACK: Build dummy string to reuse string_out_str */ diff --git a/m-string.h b/m-string.h index 463c0ade..d76a08b8 100644 --- a/m-string.h +++ b/m-string.h @@ -37,19 +37,12 @@ M_BEGIN_PROTECTED_CODE /********************************** INTERNAL ************************************/ -/* If within the string tests, perform additional (potentialy slow) checks */ -#ifdef STRING_WITHIN_TEST -# define STRINGI_ASSERT_SLOW(n) M_ASSERT(n) -#else -# define STRINGI_ASSERT_SLOW(n) (void) 0 -#endif - // This macro defines the contract of a string. // Note: A ==> B is represented as not(A) or B // Note: use of strlen can slow down a lot the program in some cases. #define STRINGI_CONTRACT(v) do { \ M_ASSERT (v != NULL); \ - STRINGI_ASSERT_SLOW (string_size(v) == strlen(string_get_cstr(v))); \ + M_ASSERT_SLOW (string_size(v) == strlen(string_get_cstr(v))); \ M_ASSERT (string_get_cstr(v)[string_size(v)] == 0); \ M_ASSERT (string_size(v) < string_capacity(v)); \ M_ASSERT (string_capacity(v) < sizeof (string_heap_ct) || !stringi_stack_p(v)); \ diff --git a/tests/test-mstring.c b/tests/test-mstring.c index 1d2dd4f1..502ca4df 100644 --- a/tests/test-mstring.c +++ b/tests/test-mstring.c @@ -21,7 +21,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define STRING_WITHIN_TEST +#define M_USE_ADDITIONAL_CHECKS 1 #include "m-string.h" BOUNDED_STRING_DEF(string16, 16)