Module Name:    src
Committed By:   rillig
Date:           Mon Jul 10 09:51:30 UTC 2023

Modified Files:
        src/usr.bin/xlint/common: param.h
        src/usr.bin/xlint/lint1: init.c lex.c tree.c
        src/usr.bin/xlint/lint2: hash.c read.c

Log Message:
lint: clean up wchar_t and hash tables


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/common/param.h
cvs rdiff -u -r1.244 -r1.245 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.558 -r1.559 src/usr.bin/xlint/lint1/tree.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint2/hash.c
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint2/read.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/common/param.h
diff -u src/usr.bin/xlint/common/param.h:1.11 src/usr.bin/xlint/common/param.h:1.12
--- src/usr.bin/xlint/common/param.h:1.11	Fri Jun  9 15:36:31 2023
+++ src/usr.bin/xlint/common/param.h	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.11 2023/06/09 15:36:31 rillig Exp $	*/
+/*	$NetBSD: param.h,v 1.12 2023/07/10 09:51:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -32,19 +32,6 @@
  */
 
 /*
- * Sizes of hash tables
- * Should be primes. Possible primes are
- * 307, 401, 503, 601, 701, 809, 907, 1009, 1103, 1201, 1301, 1409, 1511.
- *
- * HSHSIZ1	symbol table 1st pass
- * HSHSIZ2	symbol table 2nd pass
- * THSHSIZ2	type table 2nd pass
- */
-#define	HSHSIZ1		503
-#define HSHSIZ2		1009
-#define	THSHSIZ2	1009
-
-/*
  * Pull in target-specific parameters.
  */
 #include "targparam.h"
@@ -52,4 +39,4 @@
 /*
  * Make sure this matches wchar_t.
  */
-#define WCHAR	INT
+#define WCHAR_TSPEC	INT

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.244 src/usr.bin/xlint/lint1/init.c:1.245
--- src/usr.bin/xlint/lint1/init.c:1.244	Sat Jul  1 06:09:24 2023
+++ src/usr.bin/xlint/lint1/init.c	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.245 2023/07/10 09:51:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.245 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -206,7 +206,7 @@ can_init_character_array(const type_t *l
 
 	return rst == CHAR
 	    ? lst == CHAR || lst == UCHAR || lst == SCHAR
-	    : lst == WCHAR;
+	    : lst == WCHAR_TSPEC;
 }
 
 /*

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.172 src/usr.bin/xlint/lint1/lex.c:1.173
--- src/usr.bin/xlint/lint1/lex.c:1.172	Sun Jul  9 12:15:07 2023
+++ src/usr.bin/xlint/lint1/lex.c	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.172 2023/07/09 12:15:07 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.173 2023/07/10 09:51:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.172 2023/07/09 12:15:07 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.173 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -182,7 +182,7 @@ static const struct keyword {
  * The symbol table containing all keywords, identifiers and labels. The hash
  * entries are linked via sym_t.s_symtab_next.
  */
-static sym_t *symtab[HSHSIZ1];
+static sym_t *symtab[503];
 
 /*
  * The kind of the next expected symbol, to distinguish the namespaces of
@@ -202,7 +202,7 @@ hash(const char *s)
 		v = (v << 4) + (unsigned char)*p;
 		v ^= v >> 28;
 	}
-	return v % HSHSIZ1;
+	return v % (sizeof(symtab) / sizeof(symtab[0]));
 }
 
 static void
@@ -247,7 +247,7 @@ static void
 symtab_remove_locals(void)
 {
 
-	for (size_t i = 0; i < HSHSIZ1; i++) {
+	for (size_t i = 0; i < sizeof(symtab) / sizeof(symtab[0]); i++) {
 		for (sym_t *sym = symtab[i]; sym != NULL; ) {
 			sym_t *next = sym->s_symtab_next;
 			if (sym->s_block_level >= 1)
@@ -927,7 +927,7 @@ lex_wide_character_constant(void)
 	}
 
 	yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
-	yylval.y_val->v_tspec = WCHAR;
+	yylval.y_val->v_tspec = WCHAR_TSPEC;
 	yylval.y_val->v_char_constant = true;
 	yylval.y_val->u.integer = wc;
 

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.558 src/usr.bin/xlint/lint1/tree.c:1.559
--- src/usr.bin/xlint/lint1/tree.c:1.558	Sun Jul  9 12:04:08 2023
+++ src/usr.bin/xlint/lint1/tree.c	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.558 2023/07/09 12:04:08 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.559 2023/07/10 09:51:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.558 2023/07/09 12:04:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.559 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -539,7 +539,7 @@ build_string(strg_t *strg)
 
 	type_t *tp = expr_zero_alloc(sizeof(*tp));
 	tp->t_tspec = ARRAY;
-	tp->t_subt = gettyp(strg->st_char ? CHAR : WCHAR);
+	tp->t_subt = gettyp(strg->st_char ? CHAR : WCHAR_TSPEC);
 	tp->t_dim = (int)(len + 1);
 
 	tnode_t *n = expr_alloc_tnode();

Index: src/usr.bin/xlint/lint2/hash.c
diff -u src/usr.bin/xlint/lint2/hash.c:1.25 src/usr.bin/xlint/lint2/hash.c:1.26
--- src/usr.bin/xlint/lint2/hash.c:1.25	Fri Jun  9 13:03:49 2023
+++ src/usr.bin/xlint/lint2/hash.c	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.25 2023/06/09 13:03:49 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,13 +37,9 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: hash.c,v 1.25 2023/06/09 13:03:49 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
-/*
- * XXX Really need a generalized hash table package
- */
-
 #include <limits.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -51,21 +47,16 @@ __RCSID("$NetBSD: hash.c,v 1.25 2023/06/
 
 #include "lint2.h"
 
-/* pointer to hash table, initialized in inithash() */
+#define HTAB_BUCKETS		1009
+
 static	hte_t	**htab;
 
-/*
- * Initialize hash table.
- */
 hte_t **
 htab_new(void)
 {
-	return xcalloc(HSHSIZ2, sizeof(*htab_new()));
+	return xcalloc(HTAB_BUCKETS, sizeof(*htab_new()));
 }
 
-/*
- * Compute hash value from a string.
- */
 static unsigned int
 hash(const char *s)
 {
@@ -77,7 +68,7 @@ hash(const char *s)
 		v = (v << 4) + (unsigned char)*p;
 		v ^= v >> 28;
 	}
-	return v % HSHSIZ2;
+	return v % HTAB_BUCKETS;
 }
 
 /*
@@ -163,7 +154,7 @@ symtab_forall(void (*action)(hte_t *))
 	hte_t *hte;
 	hte_t **table = htab;
 
-	for (i = 0; i < HSHSIZ2; i++) {
+	for (i = 0; i < HTAB_BUCKETS; i++) {
 		for (hte = table[i]; hte != NULL; hte = hte->h_link)
 			action(hte);
 	}
@@ -178,7 +169,7 @@ symtab_forall_sorted(void (*action)(hte_
 	size_t i;
 	hte_t **table = htab;
 
-	for (i = 0; i < HSHSIZ2; i++)
+	for (i = 0; i < HTAB_BUCKETS; i++)
 		for (hte = table[i]; hte != NULL; hte = hte->h_link)
 			hte_list_add(&sorted, hte);
 
@@ -202,7 +193,7 @@ _destroyhash(hte_t **table)
 	if (table == NULL)
 		err(1, "_destroyhash called on main hash table");
 
-	for (i = 0; i < HSHSIZ2; i++) {
+	for (i = 0; i < HTAB_BUCKETS; i++) {
 		for (hte = table[i]; hte != NULL; hte = nexthte) {
 			free(__UNCONST(hte->h_name));
 			nexthte = hte->h_link;

Index: src/usr.bin/xlint/lint2/read.c
diff -u src/usr.bin/xlint/lint2/read.c:1.83 src/usr.bin/xlint/lint2/read.c:1.84
--- src/usr.bin/xlint/lint2/read.c:1.83	Sat Jul  8 11:18:16 2023
+++ src/usr.bin/xlint/lint2/read.c	Mon Jul 10 09:51:30 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.83 2023/07/08 11:18:16 rillig Exp $ */
+/* $NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: read.c,v 1.83 2023/07/08 11:18:16 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -81,7 +81,7 @@ typedef struct thtab {
 	unsigned short th_idx;
 	struct thtab *th_next;
 } thtab_t;
-static	thtab_t	**thtab;		/* hash table */
+static	thtab_t	*thtab[1009];		/* hash table */
 type_t	**tlst;				/* array for indexed access */
 static	size_t	tlstlen;		/* length of tlst */
 
@@ -226,8 +226,6 @@ readfile(const char *name)
 		flines = xcalloc(nfnames, sizeof(*flines));
 	if (tlstlen == 0)
 		tlst = xcalloc(tlstlen = 256, sizeof(*tlst));
-	if (thtab == NULL)
-		thtab = xcalloc(THSHSIZ2, sizeof(*thtab));
 
 	renametab = htab_new();
 
@@ -993,7 +991,7 @@ thash(const char *s, size_t len)
 		v = (v << sizeof(v)) + (unsigned char)*s++;
 		v ^= v >> (sizeof(v) * CHAR_BIT - sizeof(v));
 	}
-	return v % THSHSIZ2;
+	return v % (sizeof(thtab) / sizeof(thtab[0]));
 }
 
 /*

Reply via email to