This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
gen-protos/fix-header: don't use cpplib internal routines
- To: gcc-patches at gcc dot gnu dot org
- Subject: gen-protos/fix-header: don't use cpplib internal routines
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 15 Jan 2000 15:40:10 -0800
gen-protos and fix-header both use a cpplib internal routine that is
likely to disappear in the near future. This patch corrects that.
Who owns this part of the code?
zw
* scan.c (hashstr): New function.
* scan.h: Prototype it.
* gen-protos.c: Don't include cpplib.h or cpphash.h.
Use hashstr instead of hashf. Collect statistics on hash
collisions. Provide xrealloc.
* fix-header.c: Don't include cpphash.h. Use hashstr.
* Makefile.in (gen-protos.o, fix-header.o): Update
dependencies.
(gen-protos): Don't bother linking with libcpp.a.
===================================================================
Index: scan.c
--- scan.c 1999/09/05 03:49:51 1.8
+++ scan.c 2000/01/15 23:36:08
@@ -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/01/15 23:36:08
@@ -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
===================================================================
Index: gen-protos.c
--- gen-protos.c 1999/10/03 16:28:33 1.14
+++ gen-protos.c 2000/01/15 23:36:07
@@ -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: fix-header.c
--- fix-header.c 2000/01/14 17:14:43 1.32
+++ fix-header.c 2000/01/15 23:36:08
@@ -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: Makefile.in
--- Makefile.in 2000/01/14 02:01:21 1.365
+++ Makefile.in 2000/01/15 23:36:09
@@ -2232,12 +2232,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
@@ -2258,7 +2258,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