diff options
author | Bruno Haible <bruno@clisp.org> | 2021-08-08 18:18:25 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-08-08 18:18:25 +0200 |
commit | 48ece5c3f2185f52ab8cd73ceac9bd9f0e01eac6 (patch) | |
tree | f4ce9f2792efa53a82d9b49eda9e9e8fedebc8e8 /lib/wchar.in.h | |
parent | 6ccfbd6495f2849b1aeea84f73327f6ced0080a7 (diff) | |
download | gnulib-48ece5c3f2185f52ab8cd73ceac9bd9f0e01eac6.tar.gz |
stdlib, string, wchar: Improve GCC 11 allocation-deallocation checking.
* lib/stdlib.in.h (aligned_alloc): For GCC >= 11: Declare also when the
platform already declares the function or when the module
'aligned_alloc' is not in use.
(calloc): For GCC >= 11: Declare nearly always.
(canonicalize_file_name): For GCC >= 11: Declare also when the platform
already declares the function or when the module 'canonicalize-lgpl' is
not in use.
(malloc, realloc): For GCC >= 11: Declare nearly always.
* lib/malloc.in.h: Remove redundant include.
(memalign): For GCC >= 11: Declare also when the platform already
declares the function or when the module 'memalign' is not in use.
* lib/string.in.h: Include <stdlib.h> always.
(strdup): For GCC >= 11: Declare also when the platform already declares
the function or when the module 'strdup' or 'strdup-posix' is not in
use.
* lib/wchar.in.h: Include <stdlib.h> always.
(wcsdup): For GCC >= 11: Declare also when the platform already declares
the function or when the module 'wcsdup' is not in use.
* modules/free-posix (Depends-on): Add string, wchar.
Diffstat (limited to 'lib/wchar.in.h')
-rw-r--r-- | lib/wchar.in.h | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 64e55381ef..be5d36c8de 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -72,9 +72,8 @@ # include <stddef.h> #endif -#if @GNULIB_WCSDUP@ -# include <stdlib.h> /* for free() */ -#endif +/* Get free(). */ +#include <stdlib.h> /* Include the original <wchar.h> if it exists. Some builds of uClibc lack it. */ @@ -945,7 +944,7 @@ _GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - " # endif _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s)); # else -# if !@HAVE_WCSDUP@ +# if !@HAVE_WCSDUP@ || __GNUC__ >= 11 _GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); @@ -953,30 +952,40 @@ _GL_FUNCDECL_SYS (wcsdup, wchar_t *, _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); # endif _GL_CXXALIASWARN (wcsdup); -#elif defined GNULIB_POSIXCHECK -# undef wcsdup -# if HAVE_RAW_DECL_WCSDUP +#else +# if __GNUC__ >= 11 && !defined wcsdup +/* For -Wmismatched-dealloc: Associate wcsdup with free or rpl_free. */ +_GL_FUNCDECL_SYS (wcsdup, wchar_t *, + (const wchar_t *s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# endif +# if defined GNULIB_POSIXCHECK +# undef wcsdup +# if HAVE_RAW_DECL_WCSDUP _GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " "use gnulib module wcsdup for portability"); -# endif -#elif @GNULIB_MDA_WCSDUP@ +# endif +# elif @GNULIB_MDA_WCSDUP@ /* On native Windows, map 'wcsdup' to '_wcsdup', so that -loldnames is not required. In C++ with GNULIB_NAMESPACE, avoid differences between platforms by defining GNULIB_NAMESPACE::wcsdup always. */ -# if defined _WIN32 && !defined __CYGWIN__ -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef wcsdup -# define wcsdup _wcsdup -# endif +# if defined _WIN32 && !defined __CYGWIN__ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsdup +# define wcsdup _wcsdup +# endif _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s)); -# else -_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s)); -# if @HAVE_DECL_WCSDUP@ +# else +_GL_FUNCDECL_SYS (wcsdup, wchar_t *, + (const wchar_t *s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE); +# if @HAVE_DECL_WCSDUP@ _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); +# endif # endif -# endif -# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_WCSDUP@ +# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_WCSDUP@ _GL_CXXALIASWARN (wcsdup); +# endif # endif #endif |