]> Savannah Git Hosting - gnulib.git/commitdiff
malloc-h: Fix compilation errors in C++ mode on Android.
authorBruno Haible <bruno@clisp.org>
Mon, 9 Jan 2023 12:47:25 +0000 (13:47 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 9 Jan 2023 12:50:22 +0000 (13:50 +0100)
* lib/malloc.in.h: Don't include <stdlib.h>, except on Solaris and on
HP-UX. Include <stddef.h>. 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
lib/malloc.in.h
m4/malloc_h.m4
modules/malloc-h

index 5b0282dbb71b6bffad3ba63b81f07741b3750719..b00197bbbf412bce66d07b080cecda1b6fc95cba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-01-09  Bruno Haible  <bruno@clisp.org>
+
+       malloc-h: Fix compilation errors in C++ mode on Android.
+       * lib/malloc.in.h: Don't include <stdlib.h>, except on Solaris and on
+       HP-UX. Include <stddef.h>. 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  <bruno@clisp.org>
 
        gettime: Fix compilation error in C++ mode on Android.
index c39d6e218f7eb89a63ede3a509e7e3b601b5b252..52319a1fc49e1bd66db2dbe171d777c9bbabd95b 100644 (file)
 #ifndef _@GUARD_PREFIX@_MALLOC_H
 #define _@GUARD_PREFIX@_MALLOC_H
 
-/* Solaris declares memalign() in <stdlib.h>, not in <malloc.h>.
-   Also get size_t and free().  */
-#include <stdlib.h>
+/* Solaris declares memalign() in <stdlib.h>, not in <malloc.h>.  */
+#if defined __sun || defined __hpux
+# include <stdlib.h>
+#endif
+
+/* Get size_t.  */
+#include <stddef.h>
 
 /* 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 <stdlib.h> 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@
index f2e649158a676e658a812ecd111e877d6bbfc675..e90988f4ed2b756d97030ec7bcda6b461aa0d970 100644 (file)
@@ -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])
 ])
 
index 085471e1efbb749ff2cb21d022ae729dbe2c3509..9717c90b676d171e3420b5ca04ac2457eb419054 100644 (file)
@@ -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)' \