From: Bruno Haible Date: Tue, 4 Jan 2022 12:20:55 +0000 (+0100) Subject: string, wchar: Fix compilation error on MSVC (regression 2021-09-07). X-Git-Tag: v1.0~2423 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b79766eae6e003159754f6157969f1f2b89caddd;p=gnulib.git 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. --- 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