This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix fixincludes
- From: Ralf Wildenhues <Ralf dot Wildenhues at gmx dot de>
- To: Bruce Korb <bkorb at gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 3 Sep 2009 21:23:41 +0200
- Subject: fix fixincludes
Hi Bruce,
the patch below fixes some typos and so on in fixincludes files, and
then addresses sed portability issues in inclhack.def:
- in a sed BRE, backslash-n has to be used to match a newline. However,
in the replacement string of an 's' command (that's the second
argument to 's'), a newline has to be encoded as backslash-newline
(i.e., literal newline!). Using a backslash-n here works with GNU sed
but is not POSIX conforming (and doesn't work with BSD sed).
So, for example:
$ (echo a; echo b) | sed 'N; s/\n/x\
y/'
prints:
ax
yb
Note the difference in encoding the newline in the two arguments.
- the \+ operator is neither POSIX nor portable sed, but \{1,\} is;
also, there was one instance where literal + was certainly intended
('extern "C\+\+"' in sco_math), but we may want to run this by
somebody with system access to ensure that that is what should happen,
- the alternation operator \| is neither POSIX, not fully portable
(Solaris sed does not support it), I've replaced them with repeated
sed scripts for each instance.
- more issues, quoting autoconf.info:
If a sed script is specified on the command line and ends in an
`a', `c', or `i' command, the last line of inserted text should be
followed by a newline. Otherwise some `sed' implementations
(e.g., OpenBSD 3.9) do not append a newline to the inserted text.
Many `sed' implementations (e.g., MacOS X 10.4, OpenBSD 3.9,
Solaris 10 `/usr/ucb/sed') strip leading white space from the text
of `a', `c', and `i' commands. Prepend a backslash to work around
this incompatibility with Posix
I have tested the patch on GNU/Linux, with sed 4.2.1, 4.1.5, 3.02,
HP-UX 11.11 sed, FreeBSD 6.4 sed, and Solaris 10 sed. They now all
pass all fixincludes tests.
OK to apply (after the freeze)?
Thanks,
Ralf
fixincludes/ChangeLog:
2009-09-03 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* check.tpl: Fix typos.
* README: Likewise. Also, document that 'select' uses ERE.
* mkheaders.in: Update copyright years in --version output.
* inclhack.def (sco_math): Add missing final newline in sed
script 'a', 'c', or 'i' commands, for BSD sed.
(sco_math): In the text of 'a', 'c', or 'i' sed
commands, prepend leading white space with a backslash to avoid
the whitespace to be removed by BSD sed.
(sco_math): Match plain 'C++' instead of 'C\+\+' in sed regex.
(x11_new): Fix sed expression, for BSD sed.
(glibc_mutex_init): Fix newlines in sed 's' command replacement
part, for GNU sed 3.02 and Solaris sed.
(glibc_mutex_init): Replace unportable \+ sed regex operator
with \{1,\}.
(glibc_c99_inline_2, glibc_mutex_init): Avoid unportable sed
alternation \| regex operator.
(solaris_complex): Remove superfluous backslashes from
replacement string. Replace \+ operator with \{1,\}.
* tests/base/Xm/Traversal.h: This is fixed for BSD sed now.
* fixincl.x: Regenerate.
diff --git a/fixincludes/README b/fixincludes/README
index e9e4654..5536a34 100644
--- a/fixincludes/README
+++ b/fixincludes/README
@@ -51,7 +51,7 @@ To make your fix, you will need to do several things:
the proper functioning of a different fix. Make sure your
fix is properly tested and it does what it is supposed to do.
-6. Now that you have the right things happening, syncronize the
+6. Now that you have the right things happening, synchronize the
$(srcdir)/tests/base directory with the $(builddir)/tests/res
directory. The output of "make check" will be some diffs that
should give you some hints about what to do.
@@ -82,22 +82,23 @@ MAKING CHANGES TO INCLHACK.DEF
and "c-test" because they are performed internally:
* select - Run a regex on the contents of the file being considered.
- All such regex-es must match.
+ All such regex-es must match. Matching is done with
+ extended regular expressions.
* bypass - Run a regex on the contents of the file being considered.
No such regex may match.
- * c-test - call a function in fixtests.c. See that file.
+ * c_test - call a function in fixtests.c. See that file.
* files - the "fnmatch" pattern of the file(s) to examine for
the issue. There may be several copies of this attribute.
If the header lives in a /usr/include subdirectory, be
sure to include that subdirectory in the name. e.g. net/if.h
- * mach - Match the output of config.conf against a series of fnmatch
+ * mach - Match the output of config.guess against a series of fnmatch
patterns. It must match at least one of the patterns, unless
"not-machine" has also been specified. In that case, the
- config.conf output must not match any of the patterns.
+ config.guess output must not match any of the patterns.
The next test is relatively slow because it must be handled in a
separate shell process. Some platforms do not support server shells,
@@ -113,7 +114,7 @@ MAKING CHANGES TO INCLHACK.DEF
1. Be positive for all header files that require the fix.
- It is desireable to:
+ It is desirable to:
2. Be negative as often as possible whenever the fix is not
required, avoiding the process overhead.
diff --git a/fixincludes/check.tpl b/fixincludes/check.tpl
index bb93bcc..b239d8b 100644
--- a/fixincludes/check.tpl
+++ b/fixincludes/check.tpl
@@ -1,7 +1,7 @@
[= autogen5 template sh=check.sh =]
[=
#
-# This file contanes the shell template to run tests on the fixes
+# This file contains the shell template to run tests on the fixes
#
=]#!/bin/sh
diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
index f7ad877..0d2602d 100644
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -1451,10 +1451,19 @@ fix = {
hackname = glibc_c99_inline_2;
files = sys/stat.h, '*/sys/stat.h';
select = "extern __inline__ int";
- sed = "s/extern int \\(stat\\|lstat\\|fstat\\|mknod\\)/"
+ sed = "s/extern int \\(stat\\)/"
"#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
"__inline__ int \\1/";
- sed = "s/extern int __REDIRECT\\(_NTH\\|\\) (\\(stat\\|lstat\\|fstat\\)/"
+ sed = "s/extern int \\([lf]stat\\)/"
+ "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
+ "__inline__ int \\1/";
+ sed = "s/extern int \\(mknod\\)/"
+ "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
+ "__inline__ int \\1/";
+ sed = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\(stat\\)/"
+ "#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
+ "__inline__ int __REDIRECT\\1 (\\2/";
+ sed = "s/extern int __REDIRECT\\(_NTH\\)\\{0,1\\} (\\([lf]stat\\)/"
"#ifdef __GNUC_GNU_INLINE__\\\nextern\\\n#endif\\\n"
"__inline__ int __REDIRECT\\1 (\\2/";
sed = "s/^extern __inline__ int/"
@@ -1509,25 +1518,33 @@ fix = {
hackname = glibc_mutex_init;
files = pthread.h;
select = '\{ *\{ *0, *\} *\}';
- sed = "/define[ \t]\\+PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/{\n"
+ sed = "/define[ \t]\\{1,\\}PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/{\n"
"N\ns/{ { 0, } }/{ { 0, 0, 0, 0, 0, 0 } }/\n}";
sed = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
- "\\(RECURSIVE\\|ERRORCHECK\\|ADAPTIVE\\)_NP\\) }/{ \\1, 0 }/";
+ "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0 }/";
+ sed = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
+ "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0 }/";
+ sed = "s/{ \\(0, 0, 0, 0, PTHREAD_MUTEX_"
+ "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0 }/";
+ sed = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
+ "\\(RECURSIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
+ sed = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
+ "\\(ERRORCHECK\\)_NP\\) }/{ \\1, 0, 0 }/";
sed = "s/{ \\(0, 0, 0, PTHREAD_MUTEX_"
- "\\(RECURSIVE\\|ERRORCHECK\\|ADAPTIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
- sed = "/define[ \t]\\+PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/"
+ "\\(ADAPTIVE\\)_NP\\) }/{ \\1, 0, 0 }/";
+ sed = "/define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/"
"N;s/^[ \t]*#[ \t]*"
- "\\(define[ \t]\\+PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\\\)\\n"
- "[ \t]*{ { 0, } }/# if __WORDSIZE == 64\\n"
- "# \\1\\n"
- " { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\n"
- "# else\\n"
- "# \\1\\n"
- " { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\n"
+ "\\(define[ \t]\\{1,\\}PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\\\)\\n"
+ "[ \t]*{ { 0, } }/# if __WORDSIZE == 64\\\n"
+ "# \\1\\\n"
+ " { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
+ "# else\\\n"
+ "# \\1\\\n"
+ " { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
"# endif/";
sed = "s/{ \\(0, 0, 0, 0, 0, 0, "
"PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP\\) }/{ \\1, 0 }/";
- sed = "/define[ \t]\\+PTHREAD_COND_INITIALIZER/"
+ sed = "/define[ \t]\\{1,\\}PTHREAD_COND_INITIALIZER/"
"s/{ { 0, } }/{ { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }/";
test_text = <<- _EOText_
@@ -3222,18 +3239,18 @@ fix = {
"/.*__builtin_generic/a\\\n"
"#else\\\n"
"#define __fp_class(a) \\\\\\\n"
-" __builtin_choose_expr(__builtin_types_compatible_p(typeof(a),long double),\\\\\\\n"
-" __fpclassifyl(a), \\\\\\\n"
-" __builtin_choose_expr(__builtin_types_compatible_p(typeof(a), float), \\\\\\\n"
-" __fpclassifyf(a),__fpclassify(a)))\\\n"
-"#endif";
+"\\ __builtin_choose_expr(__builtin_types_compatible_p(typeof(a),long double),\\\\\\\n"
+"\\ __fpclassifyl(a), \\\\\\\n"
+"\\ __builtin_choose_expr(__builtin_types_compatible_p(typeof(a), float), \\\\\\\n"
+"\\ __fpclassifyf(a),__fpclassify(a)))\\\n"
+"#endif\n";
- sed = "/extern \"C\\+\\+\"/N;"
+ sed = "/extern \"C++\"/N;"
"/inline double abs/i\\\n"
"#ifndef __GNUC__\n";
sed = "/inline long double trunc/N;"
- "/inline long double trunc.*}.*extern \"C\\+\\+\"/a\\\n"
- "#endif /* ! __GNUC__ */";
+ "/inline long double trunc.*}.*extern \"C++\"/a\\\n"
+ "#endif /* ! __GNUC__ */\n";
test_text =
"#define __fp_class(a) \\\\\n"
@@ -3253,10 +3270,10 @@ fix = {
files = complex.h;
select = "#define[ \t]_Complex_I[ \t]_Complex_I";
sed = "s/#define[ \t]_Complex_I[ \t]_Complex_I/"
- "#define\t_Complex_I\t\\(__extension__ 1.0iF\\)/";
+ "#define\t_Complex_I\t(__extension__ 1.0iF)/";
sed = "/#define[ \t]_Imaginary_I[ \t]_Imaginary_I/d";
sed = "/#define[ \t]imaginary[ \t]_Imaginary/d";
- sed = "s/#define[ \t]I[ \t]\\+_Imaginary_I/#define\tI\t\t_Complex_I/";
+ sed = "s/#define[ \t]I[ \t]\\{1,\\}_Imaginary_I/#define\tI\t\t_Complex_I/";
test_text = "#define _Complex_I _Complex_I\n"
"#define complex _Complex\n"
"#define _Imaginary_I _Imaginary_I\n"
@@ -4438,7 +4455,7 @@ fix = {
sed = "/Widget\told, new;/i\\\n"
"#ifdef __cplusplus\\\n"
- "\tWidget\told, c_new;\\\n"
+ "\\\tWidget\told, c_new;\\\n"
"#else\n";
sed = "/Widget\told, new;/a\\\n"
@@ -4447,7 +4464,7 @@ fix = {
sed = "s/Widget new,/Widget c_new,/g";
test_text =
"struct wedge {\n"
- " Widget\told, new; /* fixinc check FAILS ON BSD */\n"
+ " Widget\told, new;\n"
"};\nextern Wedged( Widget new, Widget old );";
};
diff --git a/fixincludes/mkheaders.in b/fixincludes/mkheaders.in
index 33a7a52..9109b05 100644
--- a/fixincludes/mkheaders.in
+++ b/fixincludes/mkheaders.in
@@ -41,7 +41,7 @@ fi
if [ x$1 = x--version ] ; then
echo "mkheaders (GCC) version $version"
- echo "Copyright 2002, 2007 Free Software Foundation, Inc."
+ echo "Copyright 2002, 2007, 2009 Free Software Foundation, Inc."
echo "This program is free software; you may redistribute it under the"
echo "terms of the GNU General Public License. This program has"
echo "absolutely no warranty."
diff --git a/fixincludes/tests/base/Xm/Traversal.h b/fixincludes/tests/base/Xm/Traversal.h
index 61e6df1..2b3cba7 100644
--- a/fixincludes/tests/base/Xm/Traversal.h
+++ b/fixincludes/tests/base/Xm/Traversal.h
@@ -14,7 +14,7 @@ struct wedge {
#ifdef __cplusplus
Widget old, c_new;
#else
- Widget old, new; /* fixinc check FAILS ON BSD */
+ Widget old, new;
#endif
};
extern Wedged( Widget c_new, Widget old );