From b79766eae6e003159754f6157969f1f2b89caddd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 4 Jan 2022 13:20:55 +0100 Subject: [PATCH] string, wchar: Fix compilation error on MSVC (regression 2021-09-07). * lib/string.in.h (free): Don't redeclare as rpl_free. Instead, redefine _GL_ATTRIBUTE_DEALLOC_FREE to reference rpl_free directly. * lib/wchar.in.h (free): Likewise. --- ChangeLog | 7 +++++++ lib/string.in.h | 20 +++++++++++++++++--- lib/wchar.in.h | 20 +++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c86e4f77a..23ebf159af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2022-01-04 Bruno Haible + + string, wchar: Fix compilation error on MSVC (regression 2021-09-07). + * lib/string.in.h (free): Don't redeclare as rpl_free. Instead, redefine + _GL_ATTRIBUTE_DEALLOC_FREE to reference rpl_free directly. + * lib/wchar.in.h (free): Likewise. + 2022-01-03 Bruno Haible getpass-gnu: Allow use as dependency from test modules. diff --git a/lib/string.in.h b/lib/string.in.h index 0c4aefcceb..03e6a17a36 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -112,12 +112,26 @@ /* The definition of _GL_WARN_ON_USE is copied here. */ -/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */ -_GL_EXTERN_C void free (void *); +/* 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)) -# define free rpl_free +/* 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 +_GL_EXTERN_C void __cdecl free (void *); +# else +_GL_EXTERN_C void free (void *); +# endif +# endif +#else +# if defined _MSC_VER +_GL_EXTERN_C void __cdecl free (void *); +# else _GL_EXTERN_C void free (void *); # endif #endif diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 4db98741a2..d7792e5fb7 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -175,12 +175,26 @@ typedef int rpl_mbstate_t; # endif #endif -/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */ -_GL_EXTERN_C void free (void *); +/* 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)) -# define free rpl_free +/* 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 +_GL_EXTERN_C void __cdecl free (void *); +# else +_GL_EXTERN_C void free (void *); +# endif +# endif +#else +# if defined _MSC_VER +_GL_EXTERN_C void __cdecl free (void *); +# else _GL_EXTERN_C void free (void *); # endif #endif -- 2.39.5