From 199566afecdb1edeb9e71ee33e4d984e7b7cd5a0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 9 Jan 2023 13:47:25 +0100 Subject: [PATCH] malloc-h: Fix compilation errors in C++ mode on Android. * lib/malloc.in.h: Don't include , except on Solaris and on HP-UX. Include . Make _GL_ATTRIBUTE_DEALLOC_FREE work (code snippet copied from string.in.h and wchar.in.h). * m4/malloc_h.m4 (gl_MALLOC_H_REQUIRE_DEFAULTS): Invoke gl_STDLIB_H_REQUIRE_DEFAULTS. * modules/malloc-h (Depends-on): Add stddef, stdlib. (Makefile.am): Substitute GNULIB_FREE_POSIX and REPLACE_FREE. --- ChangeLog | 11 +++++++++++ lib/malloc.in.h | 51 +++++++++++++++++++++++++++++++++++++++++++++--- m4/malloc_h.m4 | 4 +++- modules/malloc-h | 4 ++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b0282dbb7..b00197bbbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-01-09 Bruno Haible + + malloc-h: Fix compilation errors in C++ mode on Android. + * lib/malloc.in.h: Don't include , except on Solaris and on + HP-UX. Include . Make _GL_ATTRIBUTE_DEALLOC_FREE work (code + snippet copied from string.in.h and wchar.in.h). + * m4/malloc_h.m4 (gl_MALLOC_H_REQUIRE_DEFAULTS): Invoke + gl_STDLIB_H_REQUIRE_DEFAULTS. + * modules/malloc-h (Depends-on): Add stddef, stdlib. + (Makefile.am): Substitute GNULIB_FREE_POSIX and REPLACE_FREE. + 2023-01-09 Bruno Haible gettime: Fix compilation error in C++ mode on Android. diff --git a/lib/malloc.in.h b/lib/malloc.in.h index c39d6e218f..52319a1fc4 100644 --- a/lib/malloc.in.h +++ b/lib/malloc.in.h @@ -46,15 +46,60 @@ #ifndef _@GUARD_PREFIX@_MALLOC_H #define _@GUARD_PREFIX@_MALLOC_H -/* Solaris declares memalign() in , not in . - Also get size_t and free(). */ -#include +/* Solaris declares memalign() in , not in . */ +#if defined __sun || defined __hpux +# include +#endif + +/* Get size_t. */ +#include /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */ +/* Make _GL_ATTRIBUTE_DEALLOC_FREE work, even though may not have + been included yet. */ +#if @GNULIB_FREE_POSIX@ +# if (@REPLACE_FREE@ && !defined free \ + && !(defined __cplusplus && defined GNULIB_NAMESPACE)) +/* We can't do '#define free rpl_free' here. */ +_GL_EXTERN_C void rpl_free (void *); +# undef _GL_ATTRIBUTE_DEALLOC_FREE +# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1) +# else +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); +# else +# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) +_GL_EXTERN_C void free (void *) throw (); +# else +_GL_EXTERN_C void free (void *); +# endif +# endif +# endif +#else +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); +# else +# if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) +_GL_EXTERN_C void free (void *) throw (); +# else +_GL_EXTERN_C void free (void *); +# endif +# endif +#endif + + /* Declare overridden functions. */ #if @GNULIB_MEMALIGN@ diff --git a/m4/malloc_h.m4 b/m4/malloc_h.m4 index f2e649158a..e90988f4ed 100644 --- a/m4/malloc_h.m4 +++ b/m4/malloc_h.m4 @@ -1,4 +1,4 @@ -# malloc_h.m4 serial 4 +# malloc_h.m4 serial 5 dnl Copyright (C) 2020-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -51,6 +51,8 @@ AC_DEFUN([gl_MALLOC_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMALIGN]) ]) m4_require(GL_MODULE_INDICATOR_PREFIX[_MALLOC_H_MODULE_INDICATOR_DEFAULTS]) + dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized. + gl_STDLIB_H_REQUIRE_DEFAULTS AC_REQUIRE([gl_MALLOC_H_DEFAULTS]) ]) diff --git a/modules/malloc-h b/modules/malloc-h index 085471e1ef..9717c90b67 100644 --- a/modules/malloc-h +++ b/modules/malloc-h @@ -10,6 +10,8 @@ gen-header include_next snippet/c++defs snippet/warn-on-use +stddef +stdlib configure.ac: gl_MALLOC_H @@ -29,8 +31,10 @@ malloc.h: malloc.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_MALLOC_H''@|$(NEXT_MALLOC_H)|g' \ + -e 's/@''GNULIB_FREE_POSIX''@/$(GNULIB_FREE_POSIX)/g' \ -e 's/@''GNULIB_MEMALIGN''@/$(GNULIB_MEMALIGN)/g' \ -e 's|@''HAVE_MEMALIGN''@|$(HAVE_MEMALIGN)|g' \ + -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \ -e 's|@''REPLACE_MEMALIGN''@|$(REPLACE_MEMALIGN)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ -- 2.39.5