bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

glob, spawn: use improved '_Restrict_' definition


From: Bruno Haible
Subject: glob, spawn: use improved '_Restrict_' definition
Date: Sun, 23 Feb 2020 14:28:57 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; )

Paul improved the definitions of '_Restrict_' and '_Restrict_arr_' on
2018-06-28:

    * lib/regex.h: Fix a problem with glibc installed-header checking,
    as follows:
    (_Restrict_): Prefer __restrict if defined or if GCC 2.95 or later.
    (_Restrict_arr_): Prefer __restrict_arr if defined,
    otherwise prefer _Restrict_ if C99 or GCC 3.1 or later (but not C++).

This patch propagates the improvements to glob.in.h and spawn.in.h.

The comment "Don't trust sys/cdefs.h's definition of __restrict_arr,
though, as it mishandles gcc -ansi -pedantic." apparently refers to a
problem that existed in glibc in 2008. We can ignore that now.


2020-02-23  Bruno Haible  <address@hidden>

        glob, spawn: Use improved '_Restrict_' definition.
        * lib/glob.in.h (_Restrict_): Use same definition as in lib/regex.h.
        * lib/spawn.in.h (_Restrict_, _Restrict_arr_): Likewise.

diff --git a/lib/glob.in.h b/lib/glob.in.h
index 1072588..7061a25 100644
--- a/lib/glob.in.h
+++ b/lib/glob.in.h
@@ -38,16 +38,17 @@
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
+/* For plain 'restrict', use glibc's __restrict if defined.
+   Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
    "restrict", and "configure" may have defined "restrict".
    Other compilers use __restrict, __restrict__, and _Restrict, and
    'configure' might #define 'restrict' to those words, so pick a
    different name.  */
 #ifndef _Restrict_
-# if 199901L <= __STDC_VERSION__
-#  define _Restrict_ restrict
-# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
+# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
 #  define _Restrict_ __restrict
+# elif 199901L <= __STDC_VERSION__ || defined restrict
+#  define _Restrict_ restrict
 # else
 #  define _Restrict_
 # endif
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
index 4878acb..c4dd01a 100644
--- a/lib/spawn.in.h
+++ b/lib/spawn.in.h
@@ -43,28 +43,28 @@
 # define __THROW
 #endif
 
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
+/* For plain 'restrict', use glibc's __restrict if defined.
+   Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
    "restrict", and "configure" may have defined "restrict".
    Other compilers use __restrict, __restrict__, and _Restrict, and
    'configure' might #define 'restrict' to those words, so pick a
    different name.  */
 #ifndef _Restrict_
-# if 199901L <= __STDC_VERSION__
-#  define _Restrict_ restrict
-# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
+# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
 #  define _Restrict_ __restrict
+# elif 199901L <= __STDC_VERSION__ || defined restrict
+#  define _Restrict_ restrict
 # else
 #  define _Restrict_
 # endif
 #endif
-/* gcc 3.1 and up support the [restrict] syntax.  Don't trust
-   sys/cdefs.h's definition of __restrict_arr, though, as it
-   mishandles gcc -ansi -pedantic.  */
+/* For [restrict], use glibc's __restrict_arr if available.
+   Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict].  */
 #ifndef _Restrict_arr_
-# if ((199901L <= __STDC_VERSION__                                      \
-       || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))     \
-           && !defined __STRICT_ANSI__))                                       
 \
-      && !defined __GNUG__)
+# ifdef __restrict_arr
+#  define _Restrict_arr_ __restrict_arr
+# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \
+        && !defined __GNUG__)
 #  define _Restrict_arr_ _Restrict_
 # else
 #  define _Restrict_arr_




reply via email to

[Prev in Thread] Current Thread [Next in Thread]