+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.
#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@
-# 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,
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])
])
include_next
snippet/c++defs
snippet/warn-on-use
+stddef
+stdlib
configure.ac:
gl_MALLOC_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)' \