Building a Gnulib testdir on Android, I see these error messages: clang++ -ferror-limit=0 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/data/data/com.termux/files/home/local/include -Wall -Wno-error -g -O2 -c -o test-stdlib-c++.o ../../gltests/test-stdlib-c++.cc
In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:722:19: error: no member named '_Exit' in the global namespace; did you mean '_exit'? _GL_CXXALIAS_SYS (_Exit, void, (int status)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:723:19: error: use of undeclared identifier '_Exit'; did you mean '_exit'? _GL_CXXALIASWARN (_Exit); ^ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:808:19: error: no member named 'atoll' in the global namespace _GL_CXXALIAS_SYS (atoll, long long, (const char *string)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:809:19: error: use of undeclared identifier 'atoll'; did you mean 'gnulib::atoll'? _GL_CXXALIASWARN (atoll); ^ ../gllib/stdlib.h:1019:19: error: no member named 'grantpt' in the global namespace _GL_CXXALIAS_SYS (grantpt, int, (int fd)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1020:19: error: use of undeclared identifier 'grantpt'; did you mean 'gnulib::grantpt'? _GL_CXXALIASWARN (grantpt); ^ ../gllib/stdlib.h:1088:19: error: no member named 'mbtowc' in the global namespace _GL_CXXALIAS_SYS (mbtowc, int, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1111:19: error: no member named 'mkdtemp' in the global namespace; did you mean 'mktime'? _GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1111:1: error: cannot initialize return object of type 'gnulib::_gl_mkdtemp_wrapper::type' (aka 'char *(*)(char *)') with an lvalue of type 'time_t (struct tm *)' (aka 'long (tm *)'): type mismatch at 1st parameter ('char *' vs 'struct tm *') _GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1112:19: error: use of undeclared identifier 'mkdtemp'; did you mean 'gnulib::mkdtemp'? _GL_CXXALIASWARN (mkdtemp); ^ ../gllib/stdlib.h:1138:19: error: no member named 'mkostemp' in the global namespace; did you mean 'mkdtemp'? _GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../gllib/stdlib.h:1138:1: error: no viable conversion from returned value of type 'typeof (mkdtemp)' (aka 'const gnulib::_gl_mkdtemp_wrapper') to function return type 'gnulib::_gl_mkostemp_wrapper::type' (aka 'int (*)(char *, int)') _GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1139:19: error: use of undeclared identifier 'mkostemp'; did you mean 'gnulib::mkostemp'? _GL_CXXALIASWARN (mkostemp); ^ ../gllib/stdlib.h:1167:19: error: no member named 'mkostemps' in the global namespace; did you mean 'mkostemp'? _GL_CXXALIAS_SYS (mkostemps, int, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ ../gllib/stdlib.h:1167:1: error: no viable conversion from returned value of type 'typeof (mkostemp)' (aka 'const gnulib::_gl_mkostemp_wrapper') to function return type 'gnulib::_gl_mkostemps_wrapper::type' (aka 'int (*)(char *, int, int)') _GL_CXXALIAS_SYS (mkostemps, int, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1169:19: error: use of undeclared identifier 'mkostemps'; did you mean 'mkostemp'? _GL_CXXALIASWARN (mkostemps); ^ ../gllib/stdlib.h:1198:19: error: no member named 'mkstemp' in the global namespace _GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1200:19: error: use of undeclared identifier 'mkstemp' _GL_CXXALIASWARN (mkstemp); ^ ../gllib/stdlib.h:1224:19: error: no member named 'mkstemps' in the global namespace; did you mean 'mkostemps'? _GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../gllib/stdlib.h:1225:19: error: use of undeclared identifier 'mkstemps'; did you mean 'mkostemps'? _GL_CXXALIASWARN (mkstemps); ^ ../gllib/stdlib.h:1245:19: error: no member named 'mktemp' in the global namespace; did you mean 'mkdtemp'? _GL_CXXALIAS_SYS (mktemp, char *, (char * /*template*/)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../gllib/stdlib.h:1247:19: error: use of undeclared identifier 'mktemp'; did you mean 'mkdtemp'? _GL_CXXALIASWARN (mktemp); ^ ../gllib/stdlib.h:1264:19: error: no member named 'posix_memalign' in the global namespace _GL_CXXALIAS_SYS (posix_memalign, int, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1269:19: error: use of undeclared identifier 'posix_memalign'; did you mean 'gnulib::posix_memalign'? _GL_CXXALIASWARN (posix_memalign); ^ ../gllib/stdlib.h:1285:19: error: no member named 'posix_openpt' in the global namespace _GL_CXXALIAS_SYS (posix_openpt, int, (int flags)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1286:19: error: use of undeclared identifier 'posix_openpt'; did you mean 'gnulib::posix_openpt'? _GL_CXXALIASWARN (posix_openpt); ^ ../gllib/stdlib.h:1309:19: error: no member named 'ptsname' in the global namespace _GL_CXXALIAS_SYS (ptsname, char *, (int fd)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1311:19: error: use of undeclared identifier 'ptsname'; did you mean 'gnulib::ptsname'? _GL_CXXALIASWARN (ptsname); ^ ../gllib/stdlib.h:1335:19: error: no member named 'ptsname_r' in the global namespace _GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1340:19: error: use of undeclared identifier 'ptsname_r'; did you mean 'gnulib::ptsname_r'? _GL_CXXALIASWARN (ptsname_r); ^ ../gllib/stdlib.h:1366:19: error: use of undeclared identifier 'putenv'; did you mean 'gnulib::putenv'? _GL_CXXALIASWARN (putenv); ^ ../gllib/stdlib.h:1453:24: error: no member named 'random' in the global namespace _GL_CXXALIAS_SYS_CAST (random, long, (void)); ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1455:19: error: use of undeclared identifier 'random'; did you mean 'gnulib::random'? _GL_CXXALIASWARN (random); ^ ../gllib/stdlib.h:1478:24: error: no member named 'srandom' in the global namespace; did you mean 'getrandom'? _GL_CXXALIAS_SYS_CAST (srandom, void, (unsigned int seed)); ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1480:19: error: use of undeclared identifier 'srandom'; did you mean 'random'? _GL_CXXALIASWARN (srandom); ^ ../gllib/stdlib.h:1508:24: error: no member named 'initstate' in the global namespace _GL_CXXALIAS_SYS_CAST (initstate, char *, ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1511:19: error: use of undeclared identifier 'initstate'; did you mean 'gnulib::initstate'? _GL_CXXALIASWARN (initstate); ^ ../gllib/stdlib.h:1534:24: error: no member named 'setstate' in the global namespace _GL_CXXALIAS_SYS_CAST (setstate, char *, (char *arg_state)); ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1536:19: error: use of undeclared identifier 'setstate'; did you mean 'gnulib::setstate'? _GL_CXXALIASWARN (setstate); ^ ../gllib/stdlib.h:1747:19: error: no member named 'realpath' in the global namespace _GL_CXXALIAS_SYS (realpath, char *, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1750:19: error: use of undeclared identifier 'realpath'; did you mean 'gnulib::realpath'? _GL_CXXALIASWARN (realpath); ^ ../gllib/stdlib.h:1810:19: error: no member named 'setenv' in the global namespace _GL_CXXALIAS_SYS (setenv, int, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1814:19: error: use of undeclared identifier 'setenv'; did you mean 'gnulib::setenv'? _GL_CXXALIASWARN (setenv); ^ ../gllib/stdlib.h:1842:19: error: no member named 'strtod' in the global namespace; did you mean 'strtok'? _GL_CXXALIAS_SYS (strtod, double, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1842:1: error: cannot initialize return object of type 'gnulib::_gl_strtod_wrapper::type' (aka 'double (*)(const char *__restrict, char **__restrict)') with an lvalue of type 'char *(char *, const char *)': type mismatch at 1st parameter ('const char *__restrict' vs 'char *') _GL_CXXALIAS_SYS (strtod, double, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../gllib/stdlib.h:1914:19: error: no member named 'strtol' in the global namespace _GL_CXXALIAS_SYS (strtol, long, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1957:19: error: no member named 'strtoll' in the global namespace _GL_CXXALIAS_SYS (strtoll, long long, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:1961:19: error: use of undeclared identifier 'strtoll' _GL_CXXALIASWARN (strtoll); ^ ../gllib/stdlib.h:1997:19: error: no member named 'strtoul' in the global namespace _GL_CXXALIAS_SYS (strtoul, unsigned long, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:2040:19: error: no member named 'strtoull' in the global namespace _GL_CXXALIAS_SYS (strtoull, unsigned long long, ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:2044:19: error: use of undeclared identifier 'strtoull' _GL_CXXALIASWARN (strtoull); ^ ../gllib/stdlib.h:2059:19: error: no member named 'unlockpt' in the global namespace _GL_CXXALIAS_SYS (unlockpt, int, (int fd)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:2060:19: error: use of undeclared identifier 'unlockpt' _GL_CXXALIASWARN (unlockpt); ^ ../gllib/stdlib.h:2082:19: error: no member named 'unsetenv' in the global namespace _GL_CXXALIAS_SYS (unsetenv, int, (const char *name)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../gltests/test-stdlib-c++.cc:22: In file included from ../gllib/stdlib.h:36: In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97: In file included from /data/data/com.termux/files/usr/include/stdlib.h:34: In file included from ../gllib/malloc.h:52: ../gllib/stdlib.h:2085:19: error: use of undeclared identifier 'unsetenv' _GL_CXXALIASWARN (unsetenv); ^ ../gllib/stdlib.h:2105:19: error: no member named 'wctomb' in the global namespace _GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For all these, the cause is the same: The declaration is actually present in <stdlib.h>, but only part of <stdlib.h> has been seen, due to a nested include of <stdlib.h>. This patch fixes it. Alternatively, it would also have been possible to introduce a new macro _GL_ALREADY_INCLUDING_STDLIB_H in lib/stdlib.in.h. 2023-01-09 Bruno Haible <br...@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. 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 <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@ 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)' \