>From 5427cd71962b646bbb084233c5847b02b94b8f06 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 3 Jan 2022 14:49:04 +0100 Subject: [PATCH 1/5] malloc-gnu: Allow use as dependency from test modules. * m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Set REPLACE_MALLOC_FOR_MALLOC_GNU instead of REPLACE_MALLOC. (gl_FUNC_MALLOC_PTRDIFF, gl_FUNC_MALLOC_POSIX): Set REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. * m4/calloc.m4 (gl_FUNC_CALLOC_POSIX): Test REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. * m4/realloc.m4 (gl_FUNC_REALLOC_POSIX): Likewise. * m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize the malloc-gnu module indicator. (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_MALLOC_FOR_MALLOC_GNU, REPLACE_MALLOC_FOR_MALLOC_POSIX, not REPLACE_MALLOC. * modules/stdlib (Makefile.am): Substitute GNULIB_MALLOC_GNU, REPLACE_MALLOC_FOR_MALLOC_GNU, REPLACE_MALLOC_FOR_MALLOC_POSIX, not REPLACE_MALLOC. * modules/malloc-posix (Depends-on, configure.ac): Test REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. * modules/malloc-gnu (Comment): Remove section. (Depends-on): Add xalloc-oversized. (configure.ac): Test REPLACE_MALLOC_FOR_MALLOC_GNU instead of REPLACE_MALLOC. Set a module indicator. * lib/stdlib.in.h (malloc): Test REPLACE_MALLOC_FOR_MALLOC_POSIX, REPLACE_MALLOC_FOR_MALLOC_GNU, and the respective module indicators instead of just REPLACE_MALLOC. --- ChangeLog | 27 +++++++++++++++++++++++++++ lib/stdlib.in.h | 3 ++- m4/calloc.m4 | 4 ++-- m4/malloc.m4 | 11 ++++++----- m4/realloc.m4 | 4 ++-- m4/stdlib_h.m4 | 6 ++++-- modules/malloc-gnu | 9 +++------ modules/malloc-posix | 4 ++-- modules/stdlib | 4 +++- 9 files changed, 51 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2cb4da4cd..90c019dd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2022-01-03 Bruno Haible + + malloc-gnu: Allow use as dependency from test modules. + * m4/malloc.m4 (gl_FUNC_MALLOC_GNU): Set REPLACE_MALLOC_FOR_MALLOC_GNU + instead of REPLACE_MALLOC. + (gl_FUNC_MALLOC_PTRDIFF, gl_FUNC_MALLOC_POSIX): Set + REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. + * m4/calloc.m4 (gl_FUNC_CALLOC_POSIX): Test + REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. + * m4/realloc.m4 (gl_FUNC_REALLOC_POSIX): Likewise. + * m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize the + malloc-gnu module indicator. + (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_MALLOC_FOR_MALLOC_GNU, + REPLACE_MALLOC_FOR_MALLOC_POSIX, not REPLACE_MALLOC. + * modules/stdlib (Makefile.am): Substitute GNULIB_MALLOC_GNU, + REPLACE_MALLOC_FOR_MALLOC_GNU, REPLACE_MALLOC_FOR_MALLOC_POSIX, not + REPLACE_MALLOC. + * modules/malloc-posix (Depends-on, configure.ac): Test + REPLACE_MALLOC_FOR_MALLOC_POSIX instead of REPLACE_MALLOC. + * modules/malloc-gnu (Comment): Remove section. + (Depends-on): Add xalloc-oversized. + (configure.ac): Test REPLACE_MALLOC_FOR_MALLOC_GNU instead of + REPLACE_MALLOC. Set a module indicator. + * lib/stdlib.in.h (malloc): Test REPLACE_MALLOC_FOR_MALLOC_POSIX, + REPLACE_MALLOC_FOR_MALLOC_GNU, and the respective module indicators + instead of just REPLACE_MALLOC. + 2022-01-02 Bruno Haible striconveh: Make the last change also work on Solaris 11. diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index c14f31b7e..5664fd216 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -474,7 +474,8 @@ _GL_WARN_ON_USE (grantpt, "grantpt is not portable - " by never specifying a zero size), so it does not need malloc or realloc to be redefined. */ #if @GNULIB_MALLOC_POSIX@ -# if @REPLACE_MALLOC@ +# if (@GNULIB_MALLOC_POSIX@ && @REPLACE_MALLOC_FOR_MALLOC_POSIX@) \ + || (@GNULIB_MALLOC_GNU@ && @REPLACE_MALLOC_FOR_MALLOC_GNU@) # if !((defined __cplusplus && defined GNULIB_NAMESPACE) \ || _GL_USE_STDLIB_ALLOC) # undef malloc diff --git a/m4/calloc.m4 b/m4/calloc.m4 index 9cba28f2a..3cc21c524 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -1,4 +1,4 @@ -# calloc.m4 serial 27 +# calloc.m4 serial 28 # Copyright (C) 2004-2022 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -72,7 +72,7 @@ AC_DEFUN([gl_FUNC_CALLOC_POSIX], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) - if test $REPLACE_MALLOC = 1; then + if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then REPLACE_CALLOC=1 fi dnl Although in theory we should also test for size_t overflow, diff --git a/m4/malloc.m4 b/m4/malloc.m4 index 2a6d3e1e1..6b76c1e64 100644 --- a/m4/malloc.m4 +++ b/m4/malloc.m4 @@ -1,4 +1,4 @@ -# malloc.m4 serial 27 +# malloc.m4 serial 28 dnl Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -43,8 +43,9 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) - if test $REPLACE_MALLOC = 0; then - _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC=1]) + REPLACE_MALLOC_FOR_MALLOC_GNU="$REPLACE_MALLOC_FOR_MALLOC_POSIX" + if test $REPLACE_MALLOC_FOR_MALLOC_GNU = 0; then + _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC_FOR_MALLOC_GNU=1]) fi ]) @@ -56,7 +57,7 @@ AC_DEFUN([gl_FUNC_MALLOC_PTRDIFF], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF]) - test "$gl_cv_malloc_ptrdiff" = yes || REPLACE_MALLOC=1 + test "$gl_cv_malloc_ptrdiff" = yes || REPLACE_MALLOC_FOR_MALLOC_POSIX=1 ]) # Test whether malloc, realloc, calloc refuse to create objects @@ -109,7 +110,7 @@ AC_DEFUN([gl_FUNC_MALLOC_POSIX], AC_DEFINE([HAVE_MALLOC_POSIX], [1], [Define if malloc, realloc, and calloc set errno on allocation failure.]) else - REPLACE_MALLOC=1 + REPLACE_MALLOC_FOR_MALLOC_POSIX=1 fi ]) diff --git a/m4/realloc.m4 b/m4/realloc.m4 index 62c72f88f..eb981328b 100644 --- a/m4/realloc.m4 +++ b/m4/realloc.m4 @@ -1,4 +1,4 @@ -# realloc.m4 serial 24 +# realloc.m4 serial 25 dnl Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,7 +57,7 @@ AC_DEFUN([gl_FUNC_REALLOC_POSIX], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) - if test $REPLACE_MALLOC = 1; then + if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then REPLACE_REALLOC=1 fi ]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 66fe0975b..69ab51aa3 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 63 +# stdlib_h.m4 serial 64 dnl Copyright (C) 2007-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -74,6 +74,7 @@ AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOADAVG]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSUBOPT]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GRANTPT]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_GNU]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_POSIX]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBTOWC]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDTEMP]) @@ -168,7 +169,8 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) REPLACE_FREE=0; AC_SUBST([REPLACE_FREE]) REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE]) - REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) + REPLACE_MALLOC_FOR_MALLOC_GNU=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_GNU]) + REPLACE_MALLOC_FOR_MALLOC_POSIX=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_POSIX]) REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) REPLACE_POSIX_MEMALIGN=0; AC_SUBST([REPLACE_POSIX_MEMALIGN]) diff --git a/modules/malloc-gnu b/modules/malloc-gnu index f8bcdae55..b0fa1739e 100644 --- a/modules/malloc-gnu +++ b/modules/malloc-gnu @@ -1,22 +1,19 @@ Description: malloc() function that is glibc compatible. -Comment: -This module should not be used as a dependency from a test module, -otherwise when this module occurs as a tests-related module, it will -have side effects on the compilation of the main modules in lib/. - Files: lib/malloc.c Depends-on: malloc-posix +xalloc-oversized [test $REPLACE_MALLOC_FOR_MALLOC_GNU = 1] configure.ac: gl_FUNC_MALLOC_GNU -if test $REPLACE_MALLOC = 1; then +if test $REPLACE_MALLOC_FOR_MALLOC_GNU = 1; then AC_LIBOBJ([malloc]) fi +gl_STDLIB_MODULE_INDICATOR([malloc-gnu]) Makefile.am: diff --git a/modules/malloc-posix b/modules/malloc-posix index bafcf3801..86687aa8a 100644 --- a/modules/malloc-posix +++ b/modules/malloc-posix @@ -7,11 +7,11 @@ m4/malloc.m4 Depends-on: stdlib -xalloc-oversized [test $REPLACE_MALLOC = 1] +xalloc-oversized [test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1] configure.ac: AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) -if test $REPLACE_MALLOC = 1; then +if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then AC_LIBOBJ([malloc]) fi gl_STDLIB_MODULE_INDICATOR([malloc-posix]) diff --git a/modules/stdlib b/modules/stdlib index a5a3c9f75..ed7912b9f 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -43,6 +43,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ + -e 's/@''GNULIB_MALLOC_GNU''@/$(GNULIB_MALLOC_GNU)/g' \ -e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \ -e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \ -e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \ @@ -128,7 +129,8 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \ -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \ - -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ + -e 's|@''REPLACE_MALLOC_FOR_MALLOC_GNU''@|$(REPLACE_MALLOC_FOR_MALLOC_GNU)|g' \ + -e 's|@''REPLACE_MALLOC_FOR_MALLOC_POSIX''@|$(REPLACE_MALLOC_FOR_MALLOC_POSIX)|g' \ -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_POSIX_MEMALIGN''@|$(REPLACE_POSIX_MEMALIGN)|g' \ -- 2.25.1