summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--lib/string.in.h20
-rw-r--r--lib/wchar.in.h20
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 <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.
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 <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
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 <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