From: Michel Pollet Date: Wed, 13 Jun 2012 17:11:23 +0000 (+0100) Subject: libc3: c_array tweaks X-Git-Tag: v1.0~84 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=1c4c07586f0591e7a6d8e46e91a4a6ba90a95a5f;p=sx%2Fsimavr.git libc3: c_array tweaks 'free' no longer clears the entire struct, only generic array fields 'realloc' frees the array if passed zero elements Signed-off-by: Michel Pollet --- diff --git a/examples/shared/libc3/src/c_array.h b/examples/shared/libc3/src/c_array.h index bb1aa22..ea974fc 100644 --- a/examples/shared/libc3/src/c_array.h +++ b/examples/shared/libc3/src/c_array.h @@ -55,7 +55,8 @@ static C_ARRAY_INLINE \ {\ if (!a) return;\ if (a->e) free(a->e);\ - *a = __name##_zero;\ + a->count = a->size = 0;\ + a->e = NULL;\ }\ static C_ARRAY_INLINE \ void __name##_clear(\ @@ -69,7 +70,8 @@ static C_ARRAY_INLINE \ __name##_p a, __name##_count_t size) \ {\ if (!a || a->size == size) return; \ - a->e = realloc(a->e, size * sizeof(__name##_element_t));\ + if (size == 0) { if (a->e) free(a->e); a->e = NULL; } \ + else a->e = realloc(a->e, size * sizeof(__name##_element_t));\ a->size = size; \ }\ static C_ARRAY_INLINE \