[Mesa-dev] [PATCH mesa 16/16] util: use NDEBUG to guard asserts
Gert Wollny
gw.fossdev at gmail.com
Sat Nov 25 17:45:14 UTC 2017
Am Freitag, den 24.11.2017, 18:07 +0000 schrieb Eric Engestrom:
> Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
> ---
> src/util/ralloc.c | 18 +++++++++---------
> src/util/slab.c | 4 ++--
> 2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/src/util/ralloc.c b/src/util/ralloc.c
> index 42cfa2e391d52df68db2..b52079ac075a0fe11944 100644
> --- a/src/util/ralloc.c
> +++ b/src/util/ralloc.c
> @@ -61,7 +61,7 @@ struct
> #endif
> ralloc_header
> {
> -#ifdef DEBUG
> +#ifndef NDEBUG
> /* A canary value used to determine whether a pointer is
> ralloc'd. */
> unsigned canary;
> #endif
> @@ -88,7 +88,7 @@ get_header(const void *ptr)
> {
> ralloc_header *info = (ralloc_header *) (((char *) ptr) -
> sizeof(ralloc_header));
> -#ifdef DEBUG
> +#ifndef NDEBUG
> assert(info->canary == CANARY);
> #endif
With NDEBUG defined "assert" already translates to a no-op, hence the
extra "#ifndef NDEBUG" block is not needed (same for the other asserts
below and in the other patches).
> return info;
> @@ -140,7 +140,7 @@ ralloc_size(const void *ctx, size_t size)
>
> add_child(parent, info);
>
> -#ifdef DEBUG
> +#ifndef NDEBUG
> info->canary = CANARY;
> #endif
>
> @@ -560,7 +560,7 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t
> *start, const char *fmt,
> #define LMAGIC 0x87b9c7d3
>
> struct linear_header {
> -#ifdef DEBUG
> +#ifndef NDEBUG
> unsigned magic; /* for debugging */
> #endif
> unsigned offset; /* points to the first unused byte in the
> buffer */
> @@ -610,7 +610,7 @@ create_linear_node(void *ralloc_ctx, unsigned
> min_size)
> if (unlikely(!node))
> return NULL;
>
> -#ifdef DEBUG
> +#ifndef NDEBUG
> node->magic = LMAGIC;
> #endif
> node->offset = 0;
> @@ -630,7 +630,7 @@ linear_alloc_child(void *parent, unsigned size)
> linear_size_chunk *ptr;
> unsigned full_size;
>
> -#ifdef DEBUG
> +#ifndef NDEBUG
> assert(first->magic == LMAGIC);
> #endif
> assert(!latest->next);
> @@ -704,7 +704,7 @@ linear_free_parent(void *ptr)
> return;
>
> node = LINEAR_PARENT_TO_HEADER(ptr);
> -#ifdef DEBUG
> +#ifndef NDEBUG
> assert(node->magic == LMAGIC);
> #endif
>
> @@ -725,7 +725,7 @@ ralloc_steal_linear_parent(void *new_ralloc_ctx,
> void *ptr)
> return;
>
> node = LINEAR_PARENT_TO_HEADER(ptr);
> -#ifdef DEBUG
> +#ifndef NDEBUG
> assert(node->magic == LMAGIC);
> #endif
>
> @@ -740,7 +740,7 @@ void *
> ralloc_parent_of_linear_parent(void *ptr)
> {
> linear_header *node = LINEAR_PARENT_TO_HEADER(ptr);
> -#ifdef DEBUG
> +#ifndef NDEBUG
> assert(node->magic == LMAGIC);
> #endif
> return node->ralloc_parent;
> diff --git a/src/util/slab.c b/src/util/slab.c
> index 4ce0e9a34852ca08d473..771c6bc2443b7ed3685f 100644
> --- a/src/util/slab.c
> +++ b/src/util/slab.c
> @@ -33,7 +33,7 @@
> #define SLAB_MAGIC_ALLOCATED 0xcafe4321
> #define SLAB_MAGIC_FREE 0x7ee01234
>
> -#ifdef DEBUG
> +#ifndef NDEBUG
> #define SET_MAGIC(element, value) (element)->magic = (value)
> #define CHECK_MAGIC(element, value) assert((element)->magic ==
> (value))
> #else
> @@ -53,7 +53,7 @@ struct slab_element_header {
> */
> intptr_t owner;
>
> -#ifdef DEBUG
> +#ifndef NDEBUG
> intptr_t magic;
> #endif
> };
best,
Gert
More information about the mesa-dev
mailing list