+2021-09-07 Paul Eggert <eggert@cs.ucla.edu>
+
+ string, wchar: avoid some namespace pollution
+ * lib/string.in.h, lib/wchar.in.h:
+ (free): Declare by hand instead of including stdlib.h.
+ This avoids some namespace pollution. It should also avoid some
+ nested-include problems described by Lucy Phipps in:
+ https://lists.gnu.org/r/bug-gnulib/2021-09/msg00018.html
+ * modules/string, modules/wchar:
+ (Depends-on): Add stdlib, so that REPLACE_FREE has the right value.
+ (Makefile.am): Replace @REPLACE_FREE@ when creating the include file.
+
2021-09-04 Paul Eggert <eggert@cs.ucla.edu>
idx: break copying from glibc
that can be freed by passing them as the Ith argument to the
function F.
ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
- can be freed via 'free'; it can be used only after including <stdlib.h>. */
+ can be freed via 'free'; it can be used only after declaring 'free'. */
/* Applies to: functions. Cannot be used on inline functions. */
#define ATTRIBUTE_DEALLOC(f, i) _GL_ATTRIBUTE_DEALLOC(f, i)
#define ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC_FREE
#endif
/* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
- can be freed via 'free'; it can be used only after including <stdlib.h>. */
+ can be freed via 'free'; it can be used only after declaring 'free'. */
/* Applies to: functions. Cannot be used on inline functions. */
#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
/* NetBSD 5.0 mis-defines NULL. */
#include <stddef.h>
-/* Get free(). */
-#include <stdlib.h>
-
/* MirBSD defines mbslen as a macro. */
#if @GNULIB_MBSLEN@ && defined __MirBSD__
# include <wchar.h>
/* The definition of _GL_WARN_ON_USE is copied here. */
+/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */
+#if (@REPLACE_FREE@ && !defined free \
+ && !(defined __cplusplus && defined GNULIB_NAMESPACE))
+# define free rpl_free
+#endif
+_GL_EXTERN_C void free (void *);
/* Clear a block of memory. The compiler will not delete a call to
this function, even if the block is dead after the call. */
# include <stddef.h>
#endif
-/* Get free(). */
-#include <stdlib.h>
-
/* Include the original <wchar.h> if it exists.
Some builds of uClibc lack it. */
/* The include_next requires a split double-inclusion guard. */
# endif
#endif
+/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */
+#if (@REPLACE_FREE@ && !defined free \
+ && !(defined __cplusplus && defined GNULIB_NAMESPACE))
+# define free rpl_free
+#endif
+_GL_EXTERN_C void free (void *);
/* Convert a single-byte character to a wide character. */
#if @GNULIB_BTOWC@
that can be freed by passing them as the Ith argument to the
function F.
_GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
- can be freed via 'free'; it can be used only after including <stdlib.h>. */
+ can be freed via 'free'; it can be used only after declaring 'free'. */
/* Applies to: functions. Cannot be used on inline functions. */
#if _GL_GNUC_PREREQ (11, 0)
# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
snippet/c++defs
snippet/warn-on-use
stddef
+stdlib
configure.ac:
gl_STRING_H
-e 's|@''REPLACE_FFSLL''@|$(REPLACE_FFSLL)|g' \
-e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
-e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
+ -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
-e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \
-e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \
-e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
snippet/warn-on-use
inttypes-incomplete
stddef
+stdlib
configure.ac:
gl_WCHAR_H
sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
-e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \
-e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
+ -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
-e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \
-e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \
-e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \