[committed] Remove two internal uses of AC_EGREP_CPP

2023-04-02 Thread Zack Weinberg
I have pushed the attached two patches, which replace internal uses of
AC_EGREP_CPP with simpler and/or robust checks.  See the discussion at
the bottom of
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/Running-the-Preprocessor.html
for why AC_EGREP_CPP is fragile and should generally be avoided.

zw



From dcf9bb7e3b12f3bd74edff60e80b53e668159579 Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Sun, 2 Apr 2023 10:27:08 -0400
Subject: [PATCH 1/2] AC_XENIX_DIR: Rewrite using AC_CANONICAL_HOST.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AC_XENIX_DIR is an obsolete macro, defined as AC_HEADER_DIRENT plus
code to make absolutely sure configure scripts that depended on a
shell variable internal to the original (2.13 era) definition of
AC_XENIX_DIR are not broken by autoupdate.  (That variable had the
temptingly public-sounding name “XENIX.”)  This compatibility code
uses AC_EGREP_CPP, which is itself discouraged for use in new
configure scripts.

(N.B. codesearch.debian.net does not find any uses whatsoever of
this macro, nor any code in an .ac or .m4 file that depends on the
XENIX variable.)

Change the compatibility code to use AC_CANONICAL_HOST instead,
and clarify which pieces of the code inserted by autoupdate are
probably still necessary.

* lib/autoconf/specific.m4 (AC_XENIX_DIR): Set XENIX variable
  based on value of host_os. Clarify what manual cleanup is
  recommended after autoupdate replaces this obsolete macro.
---
 lib/autoconf/specific.m4 | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/lib/autoconf/specific.m4 b/lib/autoconf/specific.m4
index 1b3ee661..a2dc5d48 100644
--- a/lib/autoconf/specific.m4
+++ b/lib/autoconf/specific.m4
@@ -754,9 +754,9 @@ dnl it should only be defined when necessary.
 ## Checks for UNIX variants.  ##
 ## -- ##
 
-
-# These are kludges which should be replaced by a single POSIX check.
-# They aren't cached, to discourage their use.
+# These macros are all obsolete, from the early days of Autoconf,
+# before the invention of AC_CANONICAL_SYSTEM.  Autoupdate will
+# replace each with inline code for a more modern feature check.
 
 # AC_AIX
 # --
@@ -776,19 +776,15 @@ AU_DEFUN([AC_ISC_POSIX], [AC_SEARCH_LIBS([strerror], [cposix])])
 # AC_XENIX_DIR
 # 
 AU_DEFUN([AC_XENIX_DIR],
-[AC_MSG_CHECKING([for Xenix])
-AC_EGREP_CPP([yes],
-[#if defined M_XENIX && ! defined M_UNIX
-  yes
-@%:@endif],
-	 [AC_MSG_RESULT([yes]); XENIX=yes],
-	 [AC_MSG_RESULT([no]); XENIX=])
-
-AC_HEADER_DIRENT[]dnl
+[AC_HEADER_DIRENT
+# Autoupdate added the next two lines to ensure that your configure
+# script's behavior did not change.  They are safe to remove unless
+# you have code that depends on the XENIX shell variable.
+AC_CANONICAL_HOST
+AS_CASE([$host_os], [xenix*], [XENIX=yes], [XENIX=no])
+# End of code added by autoupdate
 ],
-[You shouldn't need to depend upon XENIX.  Remove the
-'AC_MSG_CHECKING', 'AC_EGREP_CPP', and this warning if this part
-of the test is useless.])
+[Check for code depending on the XENIX shell variable.])
 
 
 # AC_DYNIX_SEQ
-- 
2.39.2

From 51d98495d1aac00970d791f064e83ca762bf81c7 Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Sun, 2 Apr 2023 10:43:51 -0400
Subject: [PATCH 2/2] AC_TYPE_UID_T: Rewrite using AC_CHECK_TYPE.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AC_TYPE_UID_T uses AC_EGREP_HEADER to search sys/types.h for
occurrences of the string ‘uid_t’ and, if found, assumes both
uid_t and gid_t are available.  This would be better done using
a pair of AC_CHECK_TYPE operations.

I also converted two uses of old-style AC_CHECK_TYPE, immediately
below, to new-style.  (There are probably other old-style uses in
this file, I only did the ones I happened to see.)

* lib/autoconf/types.m4 (AC_TYPE_UID_T): Check for uid_t and gid_t,
  separately, using AC_CHECK_TYPE, instead of grepping sys/types.h.
  (AC_TYPE_SIZE_T, AC_TYPE_SSIZE_T): Use new-style AC_CHECK_TYPE.
---
 lib/autoconf/types.m4 | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/lib/autoconf/types.m4 b/lib/autoconf/types.m4
index ebac0cf6..ef245613 100644
--- a/lib/autoconf/types.m4
+++ b/lib/autoconf/types.m4
@@ -589,25 +589,29 @@ AC_DEFUN([AC_TYPE_MBSTATE_T],
 
 # AC_TYPE_UID_T
 # -
-# FIXME: Rewrite using AC_CHECK_TYPE.
 AN_IDENTIFIER([gid_t], [AC_TYPE_UID_T])
 AN_IDENTIFIER([uid_t], [AC_TYPE_UID_T])
 AC_DEFUN([AC_TYPE_UID_T],
-[AC_CACHE_CHECK(for uid_t in sys/types.h, ac_cv_type_uid_t,
-[AC_EGREP_HEADER(uid_t, sys/types.h,
-  ac_cv_type_uid_t=yes, ac_cv_type_uid_t=no)])
-if test $ac_cv_type_uid_t = no; then
-  AC_DEFINE(uid_t, int, [Define to 'int' if  doesn't define.])
-  AC_DEFINE(gid_t, int, [Define to 'int' if  doesn't define.])
-fi
-])
-
+[AC_CHECK_TYPE([uid_t], [],
+  [AC_DEFINE([uid_t], [int],
+   

RFC PATCH: Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.

2023-04-02 Thread Zack Weinberg
AC_TYPE_GETGROUPS is the last remaining use of AC_EGREP_HEADER in
stock Autoconf macros.  It uses it only when cross compiling, as a
fallback from an AC_RUN_IFELSE check, testing for a bug in system
headers from the late 1980s or early 1990s, where gid_t *existed*
but the second argument to getgroups needed to be an array of int,
and this didn’t cause a compile error (i.e. the system headers
declare getgroups with no prototype or an incorrect prototype).
AC_FUNC_GETGROUPS also uses AC_RUN_IFELSE to test for obscure
problems specific to long-obsolete Unixes.

Cross-referencing gnulib’s getgroups.m4 I see that there *are*
current-generation Unixes with bugs in getgroups that are worth
worrying about (notably, FreeBSD mishandles an error case even in
CURRENT).  However, the downsides of AC_RUN_IFELSE and AC_EGREP_HEADER
seem more severe than the chances of someone compiling a current-
generation program, that uses getgroups, on an OS old enough to
have one of the really nasty bugs.

Accordingly, this patch changes AC_FUNC_GETGROUPS to use a
host_os-based *blacklist* both in native and cross compilation.
This is limited to the four host_os values for which either our old
code, or Gnulib, documented a serious bug, but has no version checks.
An incorrect guess by this blacklist can be overridden by setting
ac_cv_func_getgroups_works in config.site.  AC_TYPE_GETGROUPS, for its
part, now does a series of regular old AC_COMPILE_IFELSE checks to
probe the prototype of getgroups, and considers that good enough.

While I was in there I noticed that AC_FUNC_GETGROUPS does not
AC_SUBST a documented output variable, and that the name of this
variable is misspelled in the manual.

I'd appreciate comments and testing on this patch particularly
by users of FreeBSD and MacOS X, which are the currently
developed systems on AC_FUNC_GETGROUPS's blacklist -- see
the commentary in functions.m4.  Testing on really old systems,
old enough to actually have unprototyped declarations in unistd.h,
would also be valuable, if only to exercise the code paths in
AC_TYPE_GETGROUPS that aren't exercised on a modern system.

zwFrom 2182b63d82838d88a41425a4fd4f346715754e8e Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Sun, 2 Apr 2023 15:07:58 -0400
Subject: [PATCH] Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AC_TYPE_GETGROUPS is the last remaining use of AC_EGREP_HEADER in
stock Autoconf macros.  It uses it only when cross compiling, as a
fallback from an AC_RUN_IFELSE check, testing for a bug in system
headers from the late 1980s or early 1990s, where gid_t *existed*
but the second argument to getgroups needed to be an array of int,
and this didn’t cause a compile error (i.e. the system headers
declare getgroups with no prototype or an incorrect prototype).
AC_FUNC_GETGROUPS also uses AC_RUN_IFELSE to test for obscure
problems specific to long-obsolete Unixes.

Cross-referencing gnulib’s getgroups.m4 I see that there *are*
current-generation Unixes with bugs in getgroups that are worth
worrying about (notably, FreeBSD mishandles an error case even in
CURRENT).  However, the downsides of AC_RUN_IFELSE and AC_EGREP_HEADER
seem more severe than the chances of someone compiling a current-
generation program, that uses getgroups, on an OS old enough to
have one of the really nasty bugs.

Accordingly, this patch changes AC_FUNC_GETGROUPS to use a
host_os-based *blacklist* both in native and cross compilation.
This is limited to the four host_os values for which either our old
code, or Gnulib, documented a serious bug, but has no version checks.
An incorrect guess by this blacklist can be overridden by setting
ac_cv_func_getgroups_works in config.site.  AC_TYPE_GETGROUPS, for its
part, now does a series of regular old AC_COMPILE_IFELSE checks to
probe the prototype of getgroups, and considers that good enough.

While I was in there I noticed that AC_FUNC_GETGROUPS does not
AC_SUBST a documented output variable, and that the name of this
variable is misspelled in the manual.

* lib/autoconf/functions.m4 (AC_FUNC_GETGROUPS): Use AC_SEARCH_LIBS
  to probe for getgroups.  Use an AC_CANONICAL_HOST-based blacklist
  for bug detection, not AC_RUN_IFELSE.  AC_SUBST the GETGROUPS_LIB
  output variable.
* lib/autoconf/types.m4 (AC_TYPE_GETGROUPS): Check only the prototype
  of getgroups, using AC_COMPILE_IFELSE; do not use either AC_RUN_IFELSE
  or AC_EGREP_HEADER.
* doc/autoconf.texi: Update to match. Correct misspelling of
  GETGROUPS_LIB.
---
 NEWS  | 11 +
 doc/autoconf.texi | 23 +++---
 lib/autoconf/functions.m4 | 66 ++-
 lib/autoconf/types.m4 | 95 ---
 4 files changed, 123 insertions(+), 72 deletions(-)

diff --git a/NEWS b/NEWS
index 6a106f15..1971e8f4 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,17 @@ GNU Autoconf NEWS - User visible changes.
   This m

Re: RFC PATCH: Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.

2023-04-02 Thread Paul Eggert

On 2023-04-02 12:42, Zack Weinberg wrote:


Cross-referencing gnulib’s getgroups.m4 I see that there *are*
current-generation Unixes with bugs in getgroups that are worth
worrying about (notably, FreeBSD mishandles an error case even in
CURRENT). 


That error case is not very important, as calling getgroups with a 
negative size) since programs are not likely to exercise it. The really 
serious failures are for long-dead systems (Ultrix 4.3, NextSTEP 3.2) 
that we no longer need to worry about.


AC_FUNC_GETGROUPS has been documented as being obsolescent since 
Autoconf 2.70 (2020). I think changing it to report a failure on macOS 
and FreeBSD is more likely to cause problems than cure them. So I 
instead that we instead either leave it alone, or merely add an 
obsoletion notice, or (if we want to be more dramatic) replace it with 
something that merely tests whether the function has the correct 
prototype and links properly.





Re: RFC PATCH: Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.

2023-04-02 Thread Zack Weinberg
On Sun, Apr 2, 2023, at 5:36 PM, Paul Eggert wrote:
> That error case is not very important, since programs are not likely
> to exercise it. The really serious failures are for long-dead systems
> (Ultrix 4.3, NextSTEP 3.2) that we no longer need to worry about.
>
> AC_FUNC_GETGROUPS has been documented as being obsolescent since
> Autoconf 2.70 (2020). I think changing it to report a failure on macOS
> and FreeBSD is more likely to cause problems than cure them.

Yeah, on reflection I agree with that.

My goal here is to get rid of all internal uses of AC_EGREP_CPP and
AC_EGREP_HEADER.  I don't think we should aggressively add to the
list of -Wobsolete warnings in what's supposed to be a bugfix release.
Therefore, how about I revise this patch to remove the case for
freebsd* | darwin*, and make no other changes?

zw



Re: RFC PATCH: Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.

2023-04-02 Thread Paul Eggert

On 2023-04-02 18:30, Zack Weinberg wrote:

how about I revise this patch to remove the case for
freebsd* | darwin*, and make no other changes?


Yes, sounds good, thanks.



patchset v2: remove remaining internal uses of AC_EGREP_{CPP,HEADER}

2023-04-02 Thread Zack Weinberg
This patchset removes all remaining internal uses of AC_EGREP_CPP and
AC_EGREP_HEADER.  (See the bottom of
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/Running-the-Preprocessor.html
for why this is desirable.)

Many of the modified tests are obsolete in some way and I tried to push
them farther down the road to removal, while also striving not to break
existing configure scripts.

See individual patches for notes.  Testing would be appreciated,
especially on older and weirder OSes; the complete patchset is available
from the 'zack/no-internal-egrep-cpp' branch on savannah

.

zwFrom a7dc6d83c7d12b8409c512c3c10ad29f01e6c164 Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Sun, 2 Apr 2023 21:54:31 -0400
Subject: [PATCH 3/4] Fold AC_C_STRINGIZE into AC_PROG_CC.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Another of the last few uses of AC_EGREP_CPP is to check for the ISO C
“stringification” operator.  As this is a feature of C89, let’s fold
the test into the extensive C89 tests we already have, and make
AC_C_STRINGIZE just lean on AC_PROG_CC, in the same way
AC_C_PROTOTYPES does.

* lib/autoconf/c.m4 (_AC_C_C89_TEST_GLOBALS): Add test of preprocessor
  stringification and token pasting.
  (AC_C_STRINGIZE): Just check ac_prog_cc_stdc.
---
 lib/autoconf/c.m4 | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 33648b5b..c8c6a665 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1143,6 +1143,21 @@ static char *f (char * (*g) (char **, int), char **p, ...)
   return s;
 }
 
+/* C89 style stringification. */
+#define noexpand_stringify(a) #a
+const char *stringified = noexpand_stringify(arbitrary+token=sequence);
+
+/* C89 style token pasting.  Exercises some of the corner cases that
+   e.g. old MSVC gets wrong, but not very hard. */
+#define noexpand_concat(a,b) a##b
+#define expand_concat(a,b) noexpand_concat(a,b)
+extern int vA;
+extern int vbee;
+#define aye A
+#define bee B
+int *pvA = &expand_concat(v,aye);
+int *pvbee = &noexpand_concat(v,bee);
+
 /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
function prototypes and stuff, but not \xHH hex character constants.
These do not provoke an error unfortunately, instead are silently treated
@@ -2112,16 +2127,10 @@ fi
 # --
 # Checks if '#' can be used to glue strings together at the CPP level.
 # Defines HAVE_STRINGIZE if positive.
+# Obsolete - new code should assume C89 compliance.
 AC_DEFUN([AC_C_STRINGIZE],
-[AC_CACHE_CHECK([for preprocessor stringizing operator],
-		[ac_cv_c_stringize],
-[AC_EGREP_CPP([@%:@teststring],
-	  [@%:@define x(y) #y
-
-char *s = x(teststring);],
-	  [ac_cv_c_stringize=no],
-	  [ac_cv_c_stringize=yes])])
-if test $ac_cv_c_stringize = yes; then
+[AC_REQUIRE([AC_PROG_CC])
+if test "$ac_prog_cc_stdc" != no; then
   AC_DEFINE(HAVE_STRINGIZE, 1,
 	[Define to 1 if cpp supports the ANSI @%:@ stringizing operator.])
 fi
@@ -2130,8 +2139,8 @@ fi
 
 # AC_C_PROTOTYPES
 # ---
-# Check if the C compiler supports prototypes, included if it needs
-# options.
+# Check if the C compiler supports prototypes.
+# Obsolete - new code should assume C89 compliance.
 AC_DEFUN([AC_C_PROTOTYPES],
 [AC_REQUIRE([AC_PROG_CC])dnl
 if test "$ac_prog_cc_stdc" != no; then
-- 
2.39.2

From b5891a57b586ef6ff78bb752d62915b78cd58d7e Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Sun, 2 Apr 2023 15:07:58 -0400
Subject: [PATCH 2/4] Overhaul AC_TYPE_GETGROUPS and AC_FUNC_GETGROUPS.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AC_TYPE_GETGROUPS is the last remaining use of AC_EGREP_HEADER in
stock Autoconf macros.  It uses it only when cross compiling, as a
fallback from an AC_RUN_IFELSE check, testing for a bug in system
headers from the late 1980s or early 1990s, where gid_t *existed*
but the second argument to getgroups needed to be an array of int,
and this didn’t cause a compile error (i.e. the system headers
declare getgroups with no prototype or an incorrect prototype).
AC_FUNC_GETGROUPS also uses AC_RUN_IFELSE to test for obscure
problems specific to long-obsolete Unixes.

The downsides of AC_RUN_IFELSE and AC_EGREP_HEADER seem more severe
than the chances of someone compiling a current-generation program,
that uses getgroups, on an OS old enough to have one of the really
nasty bugs.  Accordingly, this patch changes AC_FUNC_GETGROUPS to use
a host_os-based *blacklist* both in native and cross compilation.
This is limited to the two host_os values for which either our old
code, or Gnulib, documented a serious bug: ultrix* and nextstep*.
Currently it does not try to pin down the exact version ranges subject
to the bugs — that would require research by someone with access

Re: patchset v2: remove remaining internal uses of AC_EGREP_{CPP,HEADER}

2023-04-02 Thread Paul Eggert

Thanks, I took a quick look at all the patches and see no issues.