fixincludes updates
Zack Weinberg
zack@wolery.cumb.org
Sat Jan 29 00:16:00 GMT 2000
This patch:
- turns off the else_endif_label and no_double_slash fixes, now
that the preprocessor will accept these in system headers. The
code is all intact, just if-ed out; if we have to go back to
cccp for 2.96 we can turn it back on.
- fixes some bugs exposed by running on HP/UX, and SunOS4 - need
to put the #ifdefs for matherr/struct exception at the
beginning and end of the file because fix-proto can create
references to struct exception; missing comma in an injected
prototype.
- prevents compile errors on targets where the machine_name fix
doesn't need to do anything (exposed by AIX, of all places)
- provisionally enables NO_BOGOSITY, for a 100+% speedup on
platforms where fork() is slow. Didn't cause any problems on
SunOS, HP/UX, or AIX. 'make stmp-fixinc' now takes less than
two minutes on all three of those (not counting compile time).
- corrects some dependencies.
- updates is_cxx_header as requested by Mark Mitchell. (Note,
nothing is using this now.)
Please beat to death on boxen I don't have. Irix, SCO, Ultrix, etc.
zw
* Makefile.in (fixincl.sh): Don't depend on inclhack.def.
(machname.h): Remove script to separate file. Use two-step
sequence so target is not created if script fails.
* gen-machname.h: New file. Handle case where no non-reserved
identifiers are defined.
* fixlib.c (mn_get_regexps): Return a flag: if MN_NAME_PAT is
an empty string, machine_name doesn't need to do anything at
all.
(is_cxx_header): Add more cases to regexp.
* fixlib.h: Update prototype.
* fixtests.c, fixfixes.c: Update callers of mn_get_regexps.
* fixincl.c: Define NO_BOGOSITY.
* inclhack.def (no_double_slash, else_endif_label): Ifdef out.
(hp_sysfile): Add missing comma.
(math_exception): Put the wrapper ifdefs at the beginning and
the end of the file.
* fixincl.x, inclhack.sh: Regenerate.
===================================================================
Index: Makefile.in
--- Makefile.in 2000/01/26 07:37:30 1.14
+++ Makefile.in 2000/01/29 07:55:51
@@ -1,5 +1,5 @@
# Makefile for GNU compilers.
-# Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+# Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
#This file is part of GNU CC.
@@ -101,7 +101,8 @@ fixincl.x: fixincl.tpl inclhack.def
inclhack.sh: inclhack.def inclhack.tpl hackshell.tpl
cd $(srcdir) ; ./genfixes $@
-fixincl.sh: inclhack.def inclhack.tpl
+# fixinc.sh, unlike the other two, has _no_ dependency on the .def file.
+fixincl.sh: inclhack.tpl
cd $(srcdir) ; ./genfixes $@
clean:
@@ -137,15 +138,6 @@ Makefile: Makefile.in ../config.status
cd .. \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
-# Black magic.
-# Note dependency on ASCII. \040 = space, \011 = tab, \012 = newline.
-
machname.h: ../specs
- @tr -s '\040\011' '\012\012' < ../specs | \
- sed -n 's/^.*-D\([a-zA-Z_][a-zA-Z0-9_]*\).*$$/\1/p' | sort -u | \
- grep -v '^_[_A-Z]' > mn.T
- @echo "Forbidden identifiers: `tr '\012' ' ' <mn.T`"
- @sed 's/^/\\\\</; s/$$/\\\\>/' <mn.T | tr '\012' '|' > mn.T2
- @echo '' >>mn.T2
- @sed 's/^/#define MN_NAME_PAT "/; s/|$$/"/' < mn.T2 > machname.h
- @-rm -f mn.T mn.T2
+ $(SHELL) $(srcdir)/gen-machname.h < ../specs > machname.T
+ mv -f machname.T machname.h
===================================================================
Index: fixfixes.c
--- fixfixes.c 2000/01/24 04:53:58 1.10
+++ fixfixes.c 2000/01/29 07:55:51
@@ -566,7 +566,9 @@ FIX_PROC_HEAD( machine_name_fix )
char scratch[SCRATCHSZ];
size_t len;
- mn_get_regexps (&label_re, &name_re, "machine_name_fix");
+ if (mn_get_regexps (&label_re, &name_re, "machine_name_fix"))
+ abort ();
+
scratch[0] = '_';
scratch[1] = '_';
===================================================================
Index: fixincl.c
--- fixincl.c 2000/01/22 20:55:18 1.25
+++ fixincl.c 2000/01/29 07:55:52
@@ -33,6 +33,8 @@ Boston, MA 02111-1307, USA. */
#include "server.h"
+#define NO_BOGOSITY
+
/* Quality Assurance Marker :-)
Any file that contains this string is presumed to have
===================================================================
Index: fixlib.c
--- fixlib.c 2000/01/20 18:25:12 1.7
+++ fixlib.c 2000/01/29 07:55:52
@@ -122,7 +122,11 @@ is_cxx_header (fname, text)
tSCC cxxpat[] = "\
extern[ \t]*\"C\\+\\+\"|\
-\\*-[ \t]*([mM]ode:[ \t]*)?[cC]\\+\\+[; \t]*-\\*-|\
-template[ \t]*<";
+template[ \t]*<|\
+^[ \t]*class[ \t]|\
+(public|private|protected):|\
+^[ \t]*#[ \t]*pragma[ \t]+(interface|implementation)\
+";
static regex_t cxxre;
static int compiled;
@@ -187,12 +191,16 @@ static regex_t mn_name_re;
static int mn_compiled = 0;
-void
+int
mn_get_regexps( label_re, name_re, who )
regex_t **label_re;
regex_t **name_re;
tCC *who;
{
+ /* Maybe we don't need to do this fix at all? */
+ if (mn_name_pat[0] == '\0')
+ return 1;
+
if (! mn_compiled)
{
compile_re (mn_label_pat, &mn_label_re, 1, "label pattern", who);
@@ -201,4 +209,5 @@ mn_get_regexps( label_re, name_re, who )
}
*label_re = &mn_label_re;
*name_re = &mn_name_re;
+ return 0;
}
===================================================================
Index: fixlib.h
--- fixlib.h 2000/01/20 18:25:12 1.6
+++ fixlib.h 2000/01/29 07:55:52
@@ -99,6 +99,6 @@ char * load_file_data _P_(( FILE* fp ));
t_bool is_cxx_header _P_(( tCC* filename, tCC* filetext ));
void compile_re _P_(( tCC* pat, regex_t* re, int match,
tCC *e1, tCC *e2 ));
-void mn_get_regexps _P_(( regex_t** label_re, regex_t** name_re,
+int mn_get_regexps _P_(( regex_t** label_re, regex_t** name_re,
tCC *who ));
#endif /* FIXINCLUDES_FIXLIB_H */
===================================================================
Index: fixtests.c
--- fixtests.c 2000/01/26 07:37:30 1.11
+++ fixtests.c 2000/01/29 07:55:52
@@ -275,7 +275,8 @@ TEST_FOR_FIX_PROC_HEAD( machine_name_tes
regmatch_t match[2];
tCC *base, *limit;
- mn_get_regexps(&label_re, &name_re, "machine_name_test");
+ if (mn_get_regexps(&label_re, &name_re, "machine_name_test"))
+ return SKIP_FIX;
for (base = text;
regexec (label_re, base, 2, match, 0) == 0;
===================================================================
Index: gen-machname.h
--- gen-machname.h Tue May 5 13:32:27 1998
+++ gen-machname.h Fri Jan 28 23:55:52 2000
@@ -0,0 +1,46 @@
+#! /bin/sh
+
+# Copyright (C) 2000 Free Software Foundation, Inc.
+# This file is part of GNU CC.
+
+# GNU CC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# GNU CC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GNU CC; see the file COPYING. If not, write to
+# the Free Software Foundation, 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# This script extracts from the specs file all the predefined macros
+# that are not in the C89 reserved namespace (the reserved namespace
+# is all identifiers beginnning with two underscores or one underscore
+# followed by a capital letter). The specs file is on standard input.
+# A #define for a regular expression to find any of those macros in a
+# header file is written to standard output.
+
+# Note dependency on ASCII. \040 = space, \011 = tab, \012 = newline.
+# tr ' ' '\n' is, alas, not portable.
+
+tr -s '\040\011' '\012\012' |
+ sed -n 's/^.*-D\([a-zA-Z_][a-zA-Z0-9_]*\).*$/\1/p' |
+ sort -u > mn.T
+
+if grep -v '^_[_A-Z]' mn.T > mn.U
+then
+ echo "Forbidden identifiers: `tr '\012' ' ' <mn.U`" >&2
+ sed 's/^/\\\\</; s/$/\\\\>/' <mn.U | tr '\012' '|' > mn.V
+ echo '' >>mn.V
+ sed 's/^/#define MN_NAME_PAT "/; s/|$/"/' < mn.V
+else
+ echo "No forbidden identifiers defined by this target" >&2
+ echo '#define MN_NAME_PAT ""'
+fi
+rm -f mn.[TUV]
+exit 0
===================================================================
Index: inclhack.def
--- inclhack.def 2000/01/25 08:06:23 1.50
+++ inclhack.def 2000/01/29 07:55:53
@@ -765,6 +765,7 @@ fix = {
};
+#ifdef OLD_CPP
/*
* Remove the double-slash comments. The "double_slash" test will
* try to ignore C++ headers by checking for "CC/", "xx/" and "++/"
@@ -776,6 +777,7 @@ fix = {
c_test = "double_slash";
c_fix = "no_double_slash";
};
+#endif
/*
@@ -811,6 +813,7 @@ fix = {
};
+#ifdef OLD_CPP
/*
* Fix else and endif directives that contain non-commentary text
*/
@@ -824,6 +827,7 @@ fix = {
c_test = "else_endif_label";
c_fix = "else_endif_label";
};
+#endif
/*
@@ -846,7 +850,7 @@ fix = {
hackname = hp_sysfile;
files = sys/file.h;
select = "HPUX_SOURCE";
- sed = 's/(\.\.\.)/(struct file * ...)/';
+ sed = 's/(\.\.\.)/(struct file *, ...)/';
};
@@ -1282,88 +1286,23 @@ fix = {
* the class exception defined in the C++ file std/stdexcept.h. We
* redefine it to __math_exception. This is not a great fix, but I
* haven't been able to think of anything better.
+ * Note that we have to put the #ifdef/#endif blocks at beginning
+ * and end of file, because fixproto runs after us and may insert
+ * additional references to struct exception.
*/
fix = {
hackname = math_exception;
files = math.h;
select = "struct exception";
bypass = "We have a problem when using C\\+\\+";
- sed = "/struct exception/i\\\n"
- "#ifdef __cplusplus\\\n"
- "#define exception __math_exception\\\n"
- "#endif\n";
- sed = "/struct exception/a\\\n"
- "#ifdef __cplusplus\\\n"
- "#undef exception\\\n"
- "#endif\n";
-
-#ifdef MATH_EXCEPTION_FIXED
- sed = "/matherr/i\\\n"
+ sed = "1i\\\n"
"#ifdef __cplusplus\\\n"
"#define exception __math_exception\\\n"
"#endif\n";
-
- sed = "/matherr/a\\\n"
+ sed = "$a\\\n"
"#ifdef __cplusplus\\\n"
"#undef exception\\\n"
"#endif\n";
-
-I think this patch needs some more thinking.
-This is from SVR4.2 (With '#' replaced with '@').
-Perhaps we could do without the "/matherr/a" entries?
-Can we bypass the entire fix if someone was astute
-enough to have '#ifdef __cplusplus' anywhere in the file?
-
-We can definitely do without the "/matherr/a" entries. They are
-there to cover the case where matherr is declared with no prototype
--- inclhack.def int matherr(); -- but we don't need a fix then since there
-is no reference to struct exception.
-
-Bypassing on "#ifdef __cplusplus" is too optimistic, but I've stuck
-in a bypass for the comment in the glibc 2.1 header that indicates
-awareness of the problem. Hmm. Could we use a shell test that did
-cpp -D__cplusplus | grep "struct exception" ?
-
-*** /usr/include/math.h Fri Apr 3 18:54:59 1998
---- math.h Sun May 9 07:28:58 1999
-***************
-*** 25,31 ****
---- 25,37 ----
-
- @ifndef __cplusplus
-
-+ @ifdef __cplusplus
-+ @define exception __math_exception
-+ @endif
- struct exception
-+ @ifdef __cplusplus
-+ @undef exception
-+ @endif
- {
- int type;
- char *name;
-***************
-*** 34,40 ****
---- 40,58 ----
- double retval;
- };
-
-+ @ifdef __cplusplus
-+ @define exception __math_exception
-+ @endif
-+ @ifdef __cplusplus
-+ @define exception __math_exception
-+ @endif
- extern int matherr(struct exception *);
-+ @ifdef __cplusplus
-+ @undef exception
-+ @endif
-+ @ifdef __cplusplus
-+ @undef exception
-+ @endif
-
- @endif /*__cplusplus*/
-#endif
};
fix = {
More information about the Gcc-patches
mailing list