[hurd,commited,5/6] malloc: Use assert.h's assert macro

Message ID 20180129220048.28097-6-samuel.thibault@ens-lyon.org
State New
Headers show
Series
  • hurd: fixes against previous hurd commits
Related show

Commit Message

Samuel Thibault Jan. 29, 2018, 10 p.m.
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       |  3 +++
 malloc/malloc.c | 11 ++++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

-- 
2.15.1

Patch

diff --git a/ChangeLog b/ChangeLog
index 2694f6d363..c6bcba65dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,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>
 
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 7889fb1961..f8e7250f70 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -223,6 +223,7 @@ 
 #include <unistd.h>
 #include <stdio.h>    /* needed for malloc_stats */
 #include <errno.h>
+#include <assert.h>
 
 #include <shlib-compat.h>
 
@@ -278,13 +279,9 @@ 
 #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;