From eae672ebce3fbb777670debd458905cfb2a0adc4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 Jan 2021 12:30:18 +0100 Subject: [PATCH] Make it possible to compile malloc.c separately, unconditionally. * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/malloc.c: Don't define rpl_malloc if not needed. --- ChangeLog | 6 ++++++ lib/malloc.c | 16 +++++++++++----- modules/malloc-posix | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96d81e55ce..bc19d192fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-01-31 Bruno Haible + + Make it possible to compile malloc.c separately, unconditionally. + * modules/malloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. + * lib/malloc.c: Don't define rpl_malloc if not needed. + 2021-01-31 Bruno Haible canonicalize-lgpl: Simplify. diff --git a/lib/malloc.c b/lib/malloc.c index 325064d3b0..887cddea3e 100644 --- a/lib/malloc.c +++ b/lib/malloc.c @@ -30,7 +30,11 @@ #include -#include +/* A function definition is only needed if NEED_MALLOC_GNU is defined above + or if the module 'malloc-posix' requests it. */ +#if NEED_MALLOC_GNU || (GNULIB_MALLOC_POSIX && !HAVE_MALLOC_POSIX) + +# include /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ @@ -40,17 +44,19 @@ rpl_malloc (size_t n) { void *result; -#if NEED_MALLOC_GNU +# if NEED_MALLOC_GNU if (n == 0) n = 1; -#endif +# endif result = malloc (n); -#if !HAVE_MALLOC_POSIX +# if !HAVE_MALLOC_POSIX if (result == NULL) errno = ENOMEM; -#endif +# endif return result; } + +#endif diff --git a/modules/malloc-posix b/modules/malloc-posix index b5ab59427e..1a2d72c5ab 100644 --- a/modules/malloc-posix +++ b/modules/malloc-posix @@ -14,6 +14,7 @@ if test $REPLACE_MALLOC = 1; then AC_LIBOBJ([malloc]) fi gl_STDLIB_MODULE_INDICATOR([malloc-posix]) +gl_MODULE_INDICATOR([malloc-posix]) Makefile.am: -- 2.39.5