From f0c03853f8c1c74ab3c86da66720893654bfeadf Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 6 Aug 2017 18:29:09 +0200 Subject: [PATCH] Do not activate strlen assume for debug mode. This will make debug mode faster. It also fixes a problem with GCC7 which makes **release**mode slower (since it called strlen!) --- m-string.h | 9 ++++++++- tests/test-mstring.c | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/m-string.h b/m-string.h index dca7aff4..efa494f7 100644 --- a/m-string.h +++ b/m-string.h @@ -37,13 +37,20 @@ /********************************** INTERNAL ************************************/ +/* If within the tests, perform additional checks */ +#ifdef STRING_WITHIN_TEST +# define STRINGI_ASSUME(n) M_ASSUME(n) +#else +# define STRINGI_ASSUME(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 STRING_CONTRACT(v) do { \ M_ASSUME (v != NULL); \ M_ASSUME (v->ptr != NULL || (v->size == 0 && v->alloc == 0)); \ - M_ASSUME (v->ptr == NULL || strlen(v->ptr) == v->size); \ + STRINGI_ASSUME (v->ptr == NULL || v->size == strlen(v->ptr)); \ M_ASSUME (v->ptr == NULL || v->ptr[v->size] == 0); \ M_ASSUME (v->ptr == NULL || v->size < v->alloc); \ } while (0) diff --git a/tests/test-mstring.c b/tests/test-mstring.c index a911c313..90345797 100644 --- a/tests/test-mstring.c +++ b/tests/test-mstring.c @@ -21,6 +21,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define STRING_WITHIN_TEST #include "m-string.h" int main(void)