From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 6079C1F8C6 for ; Wed, 8 Sep 2021 00:56:53 +0000 (UTC) Received: from localhost ([::1]:54490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNltT-00078y-UX for normalperson@yhbt.net; Tue, 07 Sep 2021 20:56:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNltQ-00078I-7k for bug-gnulib@gnu.org; Tue, 07 Sep 2021 20:56:48 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:59328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNltN-0005MR-OW for bug-gnulib@gnu.org; Tue, 07 Sep 2021 20:56:47 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8DFEF160129; Tue, 7 Sep 2021 17:56:43 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id xUBdBDcBTQHe; Tue, 7 Sep 2021 17:56:42 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2FD3B1600FB; Tue, 7 Sep 2021 17:56:42 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id FknmywRCwR2U; Tue, 7 Sep 2021 17:56:42 -0700 (PDT) Received: from day.example.com (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 010BB16007D; Tue, 7 Sep 2021 17:56:41 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org, landfillbaby69@gmail.com Subject: [PATCH] string, wchar: avoid some namespace pollution Date: Tue, 7 Sep 2021 17:56:32 -0700 Message-Id: <20210908005632.100624-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * 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 | 12 ++++++++++++ lib/attribute.h | 2 +- lib/stdlib.in.h | 2 +- lib/string.in.h | 9 ++++++--- lib/wchar.in.h | 9 ++++++--- m4/gnulib-common.m4 | 2 +- modules/string | 2 ++ modules/wchar | 2 ++ 8 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39a892e28..f73dc5a13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2021-09-07 Paul Eggert + + 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 =20 idx: break copying from glibc diff --git a/lib/attribute.h b/lib/attribute.h index 26a555655..eb36188d4 100644 --- a/lib/attribute.h +++ b/lib/attribute.h @@ -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 th= at - can be freed via 'free'; it can be used only after including . */ + 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 diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index d0ea07f8b..0855112d1 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -111,7 +111,7 @@ struct random_data #endif =20 /* _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointer= s that - can be freed via 'free'; it can be used only after including . */ + 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) diff --git a/lib/string.in.h b/lib/string.in.h index fa2e40c25..6214b5578 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -47,9 +47,6 @@ /* NetBSD 5.0 mis-defines NULL. */ #include =20 -/* Get free(). */ -#include - /* MirBSD defines mbslen as a macro. */ #if @GNULIB_MBSLEN@ && defined __MirBSD__ # include @@ -86,6 +83,12 @@ =20 /* The definition of _GL_WARN_ON_USE is copied here. */ =20 +/* 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 *); =20 /* Clear a block of memory. The compiler will not delete a call to this function, even if the block is dead after the call. */ diff --git a/lib/wchar.in.h b/lib/wchar.in.h index be5d36c8d..027a14549 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -72,9 +72,6 @@ # include #endif =20 -/* Get free(). */ -#include - /* Include the original 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 =20 +/* 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 *); =20 /* Convert a single-byte character to a wide character. */ #if @GNULIB_BTOWC@ diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 5d667052d..12b19dbcb 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -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 pointer= s that - can be freed via 'free'; it can be used only after including . */ + 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))) diff --git a/modules/string b/modules/string index e1d9980bb..306834591 100644 --- a/modules/string +++ b/modules/string @@ -13,6 +13,7 @@ snippet/arg-nonnull snippet/c++defs snippet/warn-on-use stddef +stdlib =20 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' \ diff --git a/modules/wchar b/modules/wchar index d4e6d6933..d34cb6a22 100644 --- a/modules/wchar +++ b/modules/wchar @@ -14,6 +14,7 @@ snippet/c++defs snippet/warn-on-use inttypes-incomplete stddef +stdlib =20 configure.ac: gl_WCHAR_H @@ -126,6 +127,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(C= XXDEFS_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' \ --=20 2.30.2