>From 64bdee095f60ec708937d73132b95377e27a827e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 Jan 2021 12:39:31 +0100 Subject: [PATCH 2/6] Make it possible to compile realloc.c separately, unconditionally. * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/realloc.c: Don't define rpl_realloc if not needed. --- ChangeLog | 4 ++++ lib/realloc.c | 20 +++++++++++++------- modules/realloc-posix | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc19d19..e9e2b36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-31 Bruno Haible + Make it possible to compile realloc.c separately, unconditionally. + * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR. + * lib/realloc.c: Don't define rpl_realloc if not needed. + 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. diff --git a/lib/realloc.c b/lib/realloc.c index 35caeab..51d8d21 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -37,7 +37,11 @@ #include -#include +/* A function definition is only needed if NEED_REALLOC_GNU is defined above + or if the module 'realloc-posix' requests it. */ +#if NEED_REALLOC_GNU || (GNULIB_REALLOC_POSIX && !HAVE_REALLOC_POSIX) + +# include /* Change the size of an allocated block of memory P to N bytes, with error checking. If N is zero, change it to 1. If P is NULL, @@ -48,7 +52,7 @@ rpl_realloc (void *p, size_t n) { void *result; -#if NEED_REALLOC_GNU +# if NEED_REALLOC_GNU if (n == 0) { n = 1; @@ -57,23 +61,25 @@ rpl_realloc (void *p, size_t n) free (p); p = NULL; } -#endif +# endif if (p == NULL) { -#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE +# if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE if (n == 0) n = 1; -#endif +# endif result = malloc (n); } else result = realloc (p, n); -#if !HAVE_REALLOC_POSIX +# if !HAVE_REALLOC_POSIX if (result == NULL) errno = ENOMEM; -#endif +# endif return result; } + +#endif diff --git a/modules/realloc-posix b/modules/realloc-posix index 8e4924d..7f48110 100644 --- a/modules/realloc-posix +++ b/modules/realloc-posix @@ -15,6 +15,7 @@ if test $REPLACE_REALLOC = 1; then AC_LIBOBJ([realloc]) fi gl_STDLIB_MODULE_INDICATOR([realloc-posix]) +gl_MODULE_INDICATOR([realloc-posix]) Makefile.am: -- 2.7.4