]> Savannah Git Hosting - gnulib.git/commitdiff
string, wchar: avoid some namespace pollution
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Sep 2021 00:51:39 +0000 (17:51 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Sep 2021 00:56:01 +0000 (17:56 -0700)
* 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.

ChangeLog
lib/attribute.h
lib/stdlib.in.h
lib/string.in.h
lib/wchar.in.h
m4/gnulib-common.m4
modules/string
modules/wchar

index 39a892e2871c3cacd02045ad6285bd5af0a84086..f73dc5a1300f7af3a81b7f9f9edcd4d644602d56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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
index 26a5556557badf1b500323d22ef126c564f6d093..eb36188d48a840c9758776717e6448819330d111 100644 (file)
@@ -80,7 +80,7 @@
    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
index d0ea07f8bcdaa9dce58e42ae8d44ed733eed786f..0855112d19e4cb79ed2aefebf42c459c90aa38d7 100644 (file)
@@ -111,7 +111,7 @@ struct random_data
 #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)
index fa2e40c257c401c65bd3b4f609a43209ab156331..6214b55784c91264e18f42875524f777ef174225 100644 (file)
@@ -47,9 +47,6 @@
 /* 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.  */
index be5d36c8dedd286e41b3ff5145d56514c2515d6f..027a1454966e509d84953b5e7b5a29968a6b5c0f 100644 (file)
@@ -72,9 +72,6 @@
 # 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.  */
@@ -149,6 +146,12 @@ typedef int rpl_mbstate_t;
 # 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@
index 5d667052d90f59acb227b9a6c42665877b7cd5e1..12b19dbcb4432ad01e48c0bf57187560b2dff7b2 100644 (file)
@@ -174,7 +174,7 @@ AC_DEFUN([gl_COMMON_BODY], [
    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)))
index e1d9980bbd3b0f3b7603fd685b92bf1490a01edb..306834591ecbd6a955b66ec447e501c188cf5407 100644 (file)
@@ -13,6 +13,7 @@ snippet/arg-nonnull
 snippet/c++defs
 snippet/warn-on-use
 stddef
+stdlib
 
 configure.ac:
 gl_STRING_H
@@ -102,6 +103,7 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_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' \
index d4e6d6933b51c1f3ac8c6a5b6923919d885d582c..d34cb6a22ac906ae192b0b3c4b1f092113323236 100644 (file)
@@ -14,6 +14,7 @@ snippet/c++defs
 snippet/warn-on-use
 inttypes-incomplete
 stddef
+stdlib
 
 configure.ac:
 gl_WCHAR_H
@@ -126,6 +127,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_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' \