]> Savannah Git Hosting - gnulib.git/commitdiff
string, wchar: Fix compilation error on MSVC (regression 2021-09-07).
authorBruno Haible <bruno@clisp.org>
Tue, 4 Jan 2022 12:20:55 +0000 (13:20 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Jan 2022 12:22:53 +0000 (13:22 +0100)
* 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
lib/string.in.h
lib/wchar.in.h

index 8c86e4f77a10c100c786f9952a3a51d0cdb9ea56..23ebf159af5911fb73db4ab47c1c6a54edec7f72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-01-04  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        getpass-gnu: Allow use as dependency from test modules.
index 0c4aefcceb91b21344d0281391db6eb865d35a23..03e6a17a36dcfd17f39f1f316e8caf685c36dfa3 100644 (file)
 
 /* 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 <stdlib.h> 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
index 4db98741a2ca16fa3ae747687b6e7d04c9d69d18..d7792e5fb7ad21ebbc16969679a721d1a096cf41 100644 (file)
@@ -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 <stdlib.h> 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