* glob, spawn: use improved '_Restrict_' definition
@ 2020-02-23 13:28 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2020-02-23 13:28 UTC (permalink / raw)
To: bug-gnulib
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 <bruno@clisp.org>
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_
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-02-23 13:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-23 13:28 glob, spawn: use improved '_Restrict_' definition Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).