This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
restrict fix-header to cpplib public interface
- To: gcc-patches at gcc dot gnu dot org
- Subject: restrict fix-header to cpplib public interface
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Tue, 8 Feb 2000 13:26:09 -0800
This is the same patch I posted back in January.
It's been reviewed by Geoff Keating and I have now committed it.
zw
2000-02-08 Zack Weinberg <zack@wolery.cumb.org>
* Makefile.in (GEN_PROTOS_OBJS): Remove libcpp.a.
(gen_protos.o): Don't depend on cpplib.h or cpphash.h.
(fix-header.o): Don't depend on cpphash.h.
* scan.c (hashstr): New function.
* scan.h: Prototype it.
* fix-header.c: Don't include cpphash.h. Use hashstr.
* gen-protos.c: Don't include cpphash.h or cpplib.h. Use
hashstr. Report hash table statistics. Add private
definition of xrealloc.
===================================================================
Index: ChangeLog
--- ChangeLog 2000/02/08 17:14:59 1.5637
+++ ChangeLog 2000/02/08 21:22:49
@@ -1,3 +1,16 @@
+2000-02-08 Zack Weinberg <zack@wolery.cumb.org>
+
+ * Makefile.in (GEN_PROTOS_OBJS): Remove libcpp.a.
+ (gen_protos.o): Don't depend on cpplib.h or cpphash.h.
+ (fix-header.o): Don't depend on cpphash.h.
+
+ * scan.c (hashstr): New function.
+ * scan.h: Prototype it.
+ * fix-header.c: Don't include cpphash.h. Use hashstr.
+ * gen-protos.c: Don't include cpphash.h or cpplib.h. Use
+ hashstr. Report hash table statistics. Add private
+ definition of xrealloc.
+
2000-02-08 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* i386.h (TARGET_SWITCHES): Fix typo in option name.
===================================================================
Index: Makefile.in
--- Makefile.in 2000/02/06 03:40:45 1.379
+++ Makefile.in 2000/02/08 21:22:50
@@ -2246,12 +2246,12 @@ deduced.h: $(GCC_PASSES) $(srcdir)/scan-
touch deduced.h; \
fi
-GEN_PROTOS_OBJS = gen-protos.o scan.o libcpp.a
+GEN_PROTOS_OBJS = gen-protos.o scan.o
gen-protos: $(GEN_PROTOS_OBJS) $(HOST_LIBDEPS)
${HOST_CC} $(HOST_CFLAGS) $(HOST_LDFLAGS) -o gen-protos \
$(GEN_PROTOS_OBJS) $(HOST_LIBS)
-gen-protos.o: gen-protos.c scan.h $(build_xm_file) system.h cpplib.h cpphash.h
+gen-protos.o: gen-protos.c scan.h $(build_xm_file) system.h
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gen-protos.c
scan.o: scan.c scan.h $(build_xm_file) system.h
@@ -2272,7 +2272,7 @@ fix-header: fix-header.o scan-decls.o sc
scan-decls.o scan.o libcpp.a $(HOST_LIBS)
fix-header.o: fix-header.c $(srcdir)/../include/obstack.h scan.h \
- xsys-protos.h $(build_xm_file) system.h cpplib.h cpphash.h
+ xsys-protos.h $(build_xm_file) system.h cpplib.h
$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/fix-header.c
scan-decls.o: scan-decls.c scan.h cpplib.h $(build_xm_file) system.h
===================================================================
Index: fix-header.c
--- fix-header.c 2000/01/14 17:14:43 1.32
+++ fix-header.c 2000/02/08 21:22:50
@@ -75,7 +75,6 @@ Foundation, 59 Temple Place - Suite 330,
#include "obstack.h"
#include "scan.h"
#include "cpplib.h"
-#include "cpphash.h"
static void v_fatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
static void fatal PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
@@ -381,7 +380,7 @@ lookup_std_proto (name, name_length)
const char *name;
int name_length;
{
- int i = hashf (name, name_length, HASH_SIZE);
+ int i = hashstr (name, name_length) % HASH_SIZE;
int i0 = i;
for (;;)
{
===================================================================
Index: gen-protos.c
--- gen-protos.c 1999/10/03 16:28:33 1.14
+++ gen-protos.c 2000/02/08 21:22:50
@@ -18,8 +18,6 @@ Foundation, 59 Temple Place - Suite 330,
#include "hconfig.h"
#include "system.h"
#include "scan.h"
-#include "cpplib.h"
-#include "cpphash.h"
#undef abort
int verbose = 0;
@@ -31,6 +29,7 @@ static int parse_fn_proto PARAMS ((char
#define HASH_SIZE 2503 /* a prime */
int hash_tab[HASH_SIZE];
int next_index;
+int collisions;
static void
add_hash (fname)
@@ -39,10 +38,11 @@ add_hash (fname)
int i, i0;
/* NOTE: If you edit this, also edit lookup_std_proto in fix-header.c !! */
- i = hashf (fname, strlen (fname), HASH_SIZE);
+ i = hashstr (fname, strlen (fname)) % HASH_SIZE;
i0 = i;
if (hash_tab[i] != 0)
{
+ collisions++;
for (;;)
{
i = (i+1) % HASH_SIZE;
@@ -186,5 +186,26 @@ main (argc, argv)
fprintf (outf, " %d,\n", hash_tab[i]);
fprintf (outf, "};\n");
+ fprintf (stderr, "gen-protos: %d entries %d collisions\n",
+ next_index, collisions);
+
return 0;
+}
+
+/* Needed by scan.o. We can't use libiberty here. */
+PTR
+xrealloc (p, s)
+ PTR p;
+ size_t s;
+{
+ PTR r;
+ if (s == 0)
+ s = 1;
+ if (p)
+ r = realloc (p, s);
+ else
+ r = malloc (s);
+ if (!r)
+ abort ();
+ return r;
}
===================================================================
Index: scan.c
--- scan.c 1999/09/05 03:49:51 1.8
+++ scan.c 2000/02/08 21:22:50
@@ -236,3 +236,18 @@ get_token (fp, s)
*s->ptr = 0;
return c;
}
+
+unsigned int
+hashstr (str, len)
+ const char *str;
+ unsigned int len;
+{
+ unsigned int n = len;
+ unsigned int r = 0;
+ const unsigned char *s = (const unsigned char *)str;
+
+ do
+ r = r * 67 + (*s++ - 113);
+ while (--n);
+ return r + len;
+}
===================================================================
Index: scan.h
--- scan.h 1999/11/03 20:40:32 1.10
+++ scan.h 2000/02/08 21:22:50
@@ -60,6 +60,7 @@ extern int read_upto _PARAMS((FILE *, ss
extern unsigned long hash _PARAMS((const char *));
extern void recognized_function _PARAMS((const char *, int, int, const char *, int, int, const char *, int));
extern void recognized_extern _PARAMS((const char *, int, const char *, int));
+extern unsigned int hashstr _PARAMS((const char *, unsigned int));
/* get_token is a simple C lexer. */
#define IDENTIFIER_TOKEN 300