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=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 B297B1F45A for ; Sat, 29 Oct 2022 18:54:26 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gfHqiPf+"; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooqy5-0005Dp-TJ; Sat, 29 Oct 2022 14:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooqy5-0005DQ-8L; Sat, 29 Oct 2022 14:54:05 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ooqy3-0004yz-DP; Sat, 29 Oct 2022 14:54:05 -0400 Received: by mail-wm1-x32b.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso8446841wma.1; Sat, 29 Oct 2022 11:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=cGZNHSMbluQdk/jUvafdnEcpJE9UDg220QDQAPJtXiw=; b=gfHqiPf+Ud/hScv/A3N63WNeAVmRXqebDMB4ZOOZ84v0DS3k0WtFoBCD2iJcUi7D5e 62ND5etkHspUs/UzYyWtyKcB8+3rV4N9UhqBymzSscu7bOuH93pmtefUQxVb30mr14GK 7IO8t/a1mHbUHYMRRmoPlVop+15TiZ4WIRaWeOC3e2YlKmHYU7XqjYMDxNTY7frrLfX1 loYjRVwRlufGbhk5uEsvqxNXTxUu9ZY3EjFcezx0gwfknZBar3UFSEYIfxyvm+lU1/I5 mYL6fSUAtJtvyMUQXmJC8T5u5kSgJaNm9c+fZ9mPeGB88z3z2v475q31IX3/gFEAaD2f vVrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cGZNHSMbluQdk/jUvafdnEcpJE9UDg220QDQAPJtXiw=; b=gGEVxyvSiK9+Cd6YCaes8g54/k/ZGgATQzbgyft0PxpLKdzahQxMMD/MX/Rd34tf0z xPRavev7Cw7cyiZVQst5E1YGa1I4eO11oMTpZXBhZ/eoZBtmVuJ/Eoxg0jEnZSw7+Bh0 xOa4G2rMvWf16iX7XUaDXcRExG45H9L3EKnfq7eI7NJ5r+xncVq7HWaHWRgaZE4jn9Ph 17FGXlO+vvFht7reV5A3JBEUmVlUl/lCvRZ991Jzz8U4XRjMmv6qwaqZxjZlOnqGQd2M 7/UWOVPpK+Pmnj8HbQ9LyoelgKSgytgWf93IfJXYTj9ZfMVQK4MMdQSvR0rqW5KCCzJ+ rQyw== X-Gm-Message-State: ACrzQf2eackQeISWpefjACzDzq4v137EhwkCDlKFzn+NH3TaJ2qYovUo y5wKl1JDY7Bs+ktoEVOC8D4chQySTg4= X-Google-Smtp-Source: AMsMyM6ArFdH/4UpTRR1HF2h2yAzbDI1P/SEHplWksLtrwBhre4/PcpqdaoxIgjMVaBmvBtZfXlYOQ== X-Received: by 2002:a1c:ed0b:0:b0:3c1:d16e:a827 with SMTP id l11-20020a1ced0b000000b003c1d16ea827mr3076668wmh.127.1667069641152; Sat, 29 Oct 2022 11:54:01 -0700 (PDT) Received: from localhost (241.84.90.146.dyn.plus.net. [146.90.84.241]) by smtp.gmail.com with ESMTPSA id a15-20020a5d53cf000000b0023682011c1dsm2166577wrw.104.2022.10.29.11.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 11:54:00 -0700 (PDT) From: Gavin Smith X-Google-Original-From: Gavin Smith Date: Sat, 29 Oct 2022 19:53:59 +0100 To: Paul Eggert Cc: bug-gnulib@gnu.org, bug-texinfo@gnu.org Subject: Re: Avoid gnulib redefinitions - MDA, free-posix Message-ID: Mail-Followup-To: Gavin Smith , Paul Eggert , bug-gnulib@gnu.org, bug-texinfo@gnu.org References: <916fe3b7-0ace-fa15-2282-2f6571aba26c@cs.ucla.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <916fe3b7-0ace-fa15-2282-2f6571aba26c@cs.ucla.edu> Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=gavinsmith0123@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "bug-gnulib" Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org On Sat, Oct 29, 2022 at 09:58:25AM -0700, Paul Eggert wrote: > If it's just 'free', I might prefer the latter solution, to underline the > special case and to avoid even more complexity in gnulib-tool. Is that > something you could write? Here is a first attempt. I am not very familiar with the Gnulib code. The main idea is to put a define in AM_CPPFLAGS in the Makefile that gnulib-tool generates. Then the gnulib headers can distinguish whether they are being used as part of building gnulib, or building the user's program. This avoided looking through all the gnulib code and deciding where to replace "free" with "gl_internal_free" or whatever the replacement would be called. I tried to minimize the number of lines of code that would change, but if this approach was adopted, then the following changes should also be made: * Rename free-posix to free-posix-internal and free-posix-public to free-posix * REPLACE_FREE to be changed to REPLACE_FREE_INTERNAL throughout gnulib, likewise REPACE_FREE_PUBLIC to REPLACE_FREE. I tested this on a project with a gnulib import. Let me know if this is the right approach and if there are changes to make to the patch. diff --git a/ChangeLog b/ChangeLog index 6f4bea5c1c..994f457e70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2020-10-29 Gavin Smith + + Avoid unrequested 'free' redefinition + + * gnulib-tool (func_emit_lib_Makefile_am): + Add -DGNULIB_INTERNAL to AM_CPPFLAGS. + * m4/free-public.m4, modules/free-posix-public: + New module to set @REPLACE_FREE_PUBLIC@ from @REPLACE_FREE@. + * modules/stdlib, m4/stdlib_h.m4: + Substitute for @REPLACE_FREE_PUBLIC@. + * lib/stdlib.in.h <@GNULIB_FREE_POSIX@>: Only replace 'free' if + both GNULIB_INTERNAL and @REPLACE_FREE@ are set, or if + @REPLACE_FREE_PUBLIC@ is set. + + This allows Gnulib to use the free redefinition internally without + replacing it in user code, unless they explicitly request the + module. + 2022-10-23 Bruno Haible assert-h: Make static_assert work on Solaris 11.4. diff --git a/gnulib-tool b/gnulib-tool index 028bcf36ad..84a77171d7 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -3945,7 +3945,7 @@ func_emit_lib_Makefile_am () fi if test -z "$makefile_name"; then echo - echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2" + echo "AM_CPPFLAGS = -DGNULIB_INTERNAL$cppflags_part1$cppflags_part2" echo "AM_CFLAGS =" else if test -n "$cppflags_part1$cppflags_part2"; then diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 8e0a609f1f..f75b8621f4 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -179,7 +179,7 @@ _GL_WARN_ON_USE (_Exit, "_Exit is unportable - " #if @GNULIB_FREE_POSIX@ -# if @REPLACE_FREE@ +# if @REPLACE_FREE@ && defined(GNULIB_INTERNAL) || @REPLACE_FREE_PUBLIC@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef free # define free rpl_free diff --git a/m4/free-public.m4 b/m4/free-public.m4 new file mode 100644 index 0000000000..497abf81ae --- /dev/null +++ b/m4/free-public.m4 @@ -0,0 +1 @@ +AC_DEFUN([gl_PREREQ_FREE_PUBLIC], [:]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 9e2096976f..b096054284 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -171,6 +171,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], REPLACE_CALLOC_FOR_CALLOC_POSIX=0; AC_SUBST([REPLACE_CALLOC_FOR_CALLOC_POSIX]) REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) REPLACE_FREE=0; AC_SUBST([REPLACE_FREE]) + REPLACE_FREE_PUBLIC=0; AC_SUBST([REPLACE_FREE_PUBLIC]) REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE]) REPLACE_MALLOC_FOR_MALLOC_GNU=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_GNU]) REPLACE_MALLOC_FOR_MALLOC_POSIX=0; AC_SUBST([REPLACE_MALLOC_FOR_MALLOC_POSIX]) diff --git a/modules/free-posix-public b/modules/free-posix-public new file mode 100644 index 0000000000..050a06bf76 --- /dev/null +++ b/modules/free-posix-public @@ -0,0 +1,27 @@ +Description: +Work around systems where free clobbers errno. + +Files: +m4/free-public.m4 + +Depends-on: +free-posix + +configure.ac: +REPLACE_FREE_PUBLIC=$REPLACE_FREE +gl_CONDITIONAL([GL_COND_OBJ_FREE_PUBLIC], [test $REPLACE_FREE_PUBLIC = 1]) +AM_COND_IF([GL_COND_OBJ_FREE_PUBLIC], [ + gl_PREREQ_FREE_PUBLIC +]) +gl_STDLIB_MODULE_INDICATOR([free-posix-public]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +None diff --git a/modules/stdlib b/modules/stdlib index 45d8f59331..2266e68d52 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -131,6 +131,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''REPLACE_CALLOC_FOR_CALLOC_POSIX''@|$(REPLACE_CALLOC_FOR_CALLOC_POSIX)|g' \ -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \ + -e 's|@''REPLACE_FREE_PUBLIC''@|$(REPLACE_FREE_PUBLIC)|g' \ -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \ -e 's|@''REPLACE_MALLOC_FOR_MALLOC_GNU''@|$(REPLACE_MALLOC_FOR_MALLOC_GNU)|g' \ -e 's|@''REPLACE_MALLOC_FOR_MALLOC_POSIX''@|$(REPLACE_MALLOC_FOR_MALLOC_POSIX)|g' \