malloc: Use assert.h's assert macro
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 29 Jan 2018 21:49:45 +0000 (22:49 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 29 Jan 2018 22:00:17 +0000 (23:00 +0100)
This avoids assert definition conflicts if some of the headers used by
malloc.c happens to include assert.h.  Malloc still needs a malloc-avoiding
implementation, which we get by redirecting __assert_fail to malloc's
__malloc_assert.

* malloc/malloc.c: Include <assert.h>.
(assert): Do not define.
[!defined NDEBUG] (__assert_fail): Define to __malloc_assert.

ChangeLog
malloc/malloc.c

index 3060b73..579c4f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,9 @@
        || to respect codestyle.
        * libio/tst-memstream3.c (_FWRITE): Rename to FWRITE_FUNC.
        (do_test_bz20181): Rename accordingly.
+       * malloc/malloc.c: Include <assert.h>.
+       (assert): Do not define.
+       [!defined NDEBUG] (__assert_fail): Define to __malloc_assert.
 
 2018-01-29  Darius Rad  <darius@bluespec.com>
 
index 7889fb1..f8e7250 100644 (file)
 #include <unistd.h>
 #include <stdio.h>    /* needed for malloc_stats */
 #include <errno.h>
+#include <assert.h>
 
 #include <shlib-compat.h>
 
 #define MALLOC_DEBUG 0
 #endif
 
-#ifdef NDEBUG
-# define assert(expr) ((void) 0)
-#else
-# define assert(expr) \
-  ((expr)                                                                    \
-   ? ((void) 0)                                                                      \
-   : __malloc_assert (#expr, __FILE__, __LINE__, __func__))
+#ifndef NDEBUG
+# define __assert_fail(assertion, file, line, function)                        \
+        __malloc_assert(assertion, file, line, function)
 
 extern const char *__progname;