From c93727f23f91b83309c331bef094f22c0fe989d4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 8 Apr 2011 11:06:03 -0700 Subject: [PATCH] stdlib: let modules use system malloc, realloc * lib/stdlib.in.h (malloc, realloc): Don't #define or add warnings if !_GL_USE_STDLIB_ALLOC. --- ChangeLog | 4 ++++ lib/stdlib.in.h | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7e4c92804..6c9c17e728 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2011-04-08 Paul Eggert + stdlib: let modules use system malloc, realloc + * lib/stdlib.in.h (malloc, realloc): Don't #define or add warnings + if !_GL_USE_STDLIB_ALLOC. + careadlinkat: rename members to avoid problem * lib/allocator.h (struct allocator): Rename members from malloc/realloc to allocate/reallocate, to avoid problems if malloc diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 2697a4bd1d..c857de497b 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -255,23 +255,29 @@ _GL_WARN_ON_USE (ptsname, "grantpt is not portable - " # endif #endif -#if @GNULIB_MALLOC_POSIX@ -# if @REPLACE_MALLOC@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef malloc -# define malloc rpl_malloc -# endif +/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not + rely on GNU or POSIX semantics for malloc and realloc (for example, + by never specifying a zero size), so it does not need malloc or + realloc to be redefined. */ +#if !_GL_USE_STDLIB_ALLOC +# if @GNULIB_MALLOC_POSIX@ +# if @REPLACE_MALLOC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef malloc +# define malloc rpl_malloc +# endif _GL_FUNCDECL_RPL (malloc, void *, (size_t size)); _GL_CXXALIAS_RPL (malloc, void *, (size_t size)); -# else +# else _GL_CXXALIAS_SYS (malloc, void *, (size_t size)); -# endif +# endif _GL_CXXALIASWARN (malloc); -#elif defined GNULIB_POSIXCHECK -# undef malloc +# elif defined GNULIB_POSIXCHECK +# undef malloc /* Assume malloc is always declared. */ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " "use gnulib module malloc-posix for portability"); +# endif #endif /* Convert a multibyte character to a wide character. */ @@ -529,23 +535,25 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - " #endif -#if @GNULIB_REALLOC_POSIX@ -# if @REPLACE_REALLOC@ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef realloc -# define realloc rpl_realloc -# endif +#if !_GL_USE_STDLIB_ALLOC +# if @GNULIB_REALLOC_POSIX@ +# if @REPLACE_REALLOC@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef realloc +# define realloc rpl_realloc +# endif _GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); -# else +# else _GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); -# endif +# endif _GL_CXXALIASWARN (realloc); -#elif defined GNULIB_POSIXCHECK -# undef realloc +# elif defined GNULIB_POSIXCHECK +# undef realloc /* Assume realloc is always declared. */ _GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " "use gnulib module realloc-posix for portability"); +# endif #endif #if @GNULIB_REALPATH@ -- 2.30.2