diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-06-12 10:23:45 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-06-12 10:27:13 -0400 |
commit | 453bb6c1b79d6d4fe4b1277336dc0f4097a5ee6b (patch) | |
tree | b8d4627503708b047230c7148dbceae63100a462 | |
parent | 399bc22aff7f1042199cbc425d1df5264d1741af (diff) | |
download | dimension-453bb6c1b79d6d4fe4b1277336dc0f4097a5ee6b.tar.xz |
Use DMNSN_DEBUG macro instead of NDEBUG.
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | libdimension/dimension/error.h | 14 | ||||
-rw-r--r-- | libdimension/inline.c | 3 | ||||
-rw-r--r-- | libdimension/malloc.c | 10 |
4 files changed, 17 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac index d31a589..4ef71ea 100644 --- a/configure.ac +++ b/configure.ac @@ -82,7 +82,10 @@ AC_ARG_ENABLE([debug], [Perform potentially expensive sanity checks while running [default=no]])], [], [enable_debug=no]) -if test "$enable_debug" = "no"; then +if test "$enable_debug" = "yes"; then + AC_DEFINE([DMNSN_DEBUG], [1]) +else + AC_DEFINE([DMNSN_DEBUG], [0]) AC_DEFINE([NDEBUG], [1]) fi AM_CONDITIONAL([DEBUG], [test "$enable_debug" = "yes"]) diff --git a/libdimension/dimension/error.h b/libdimension/dimension/error.h index 0ae349f..f07261e 100644 --- a/libdimension/dimension/error.h +++ b/libdimension/dimension/error.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -51,15 +51,15 @@ * @param[in] expr The expression to assert. * @param[in] str A string to print if the assertion fails. */ -#ifdef NDEBUG - #define dmnsn_assert(expr, str) ((void)0) -#else +#if DMNSN_DEBUG #define dmnsn_assert(expr, str) \ do { \ if (!(expr)) { \ dmnsn_error((str)); \ } \ } while (0) +#else + #define dmnsn_assert(expr, str) ((void)0) #endif /** @@ -67,10 +67,10 @@ * Express that a line of code is unreachable. * @param[in] str A string to print if the line is reached. */ -#ifdef NDEBUG - #define dmnsn_unreachable(str) DMNSN_UNREACHABLE() -#else +#if DMNSN_DEBUG #define dmnsn_unreachable(str) dmnsn_error((str)) +#else + #define dmnsn_unreachable(str) DMNSN_UNREACHABLE() #endif /** diff --git a/libdimension/inline.c b/libdimension/inline.c index ae175e0..b0622fe 100644 --- a/libdimension/inline.c +++ b/libdimension/inline.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -40,5 +40,4 @@ #define DMNSN_INLINE static #endif -#undef NDEBUG #include "dimension.h" diff --git a/libdimension/malloc.c b/libdimension/malloc.c index 786a2dc..2e4969d 100644 --- a/libdimension/malloc.c +++ b/libdimension/malloc.c @@ -28,7 +28,7 @@ #include <string.h> #include <stdatomic.h> -#ifndef NDEBUG +#if DMNSN_DEBUG static atomic_size_t dmnsn_allocs = ATOMIC_VAR_INIT(0); #endif @@ -40,7 +40,7 @@ dmnsn_malloc(size_t size) dmnsn_error("Memory allocation failed."); } -#ifndef NDEBUG +#if DMNSN_DEBUG atomic_fetch_add(&dmnsn_allocs, 1); #endif @@ -50,7 +50,7 @@ dmnsn_malloc(size_t size) void * dmnsn_realloc(void *ptr, size_t size) { -#ifndef NDEBUG +#if DMNSN_DEBUG if (!ptr) { atomic_fetch_add(&dmnsn_allocs, 1); } @@ -74,7 +74,7 @@ dmnsn_strdup(const char *s) void dmnsn_free(void *ptr) { -#ifndef NDEBUG +#if DMNSN_DEBUG if (ptr) { atomic_fetch_sub(&dmnsn_allocs, 1); } @@ -83,7 +83,7 @@ dmnsn_free(void *ptr) free(ptr); } -#ifndef NDEBUG +#if DMNSN_DEBUG DMNSN_LATE_DESTRUCTOR static void dmnsn_leak_check(void) { |