Module Name:    src
Committed By:   rillig
Date:           Sat Aug 28 17:18:42 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint2: emit.exp-ln emit_lp64.exp-ln
        src/usr.bin/xlint/lint2: emit2.c externs2.h hash.c

Log Message:
lint: write the entries for the libraries in alphabetical order

This makes them easier to read by humans.

The checks are still performed in hashcode order since there are no
tests that would cover this change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint2/emit.exp-ln \
    src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint2/externs2.h
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint2/hash.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint2/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint2/emit.exp-ln:1.2 src/tests/usr.bin/xlint/lint2/emit.exp-ln:1.3
--- src/tests/usr.bin/xlint/lint2/emit.exp-ln:1.2	Tue Aug 24 23:38:51 2021
+++ src/tests/usr.bin/xlint/lint2/emit.exp-ln	Sat Aug 28 17:18:42 2021
@@ -1,4 +1,4 @@
-# $NetBSD: emit.exp-ln,v 1.2 2021/08/24 23:38:51 rillig Exp $
+# $NetBSD: emit.exp-ln,v 1.3 2021/08/28 17:18:42 rillig Exp $
 
 S llib-lemit.ln
 0 s llib-lemit.ln
@@ -11,8 +11,11 @@ S llib-lemit.ln
 1s emit.c
 2s expr_promote.c
 
-# from emit.c
-0 d 0.0 t u 11defined_int I
-0 d 0.0 d u 14cover_outqchar F0 V
+# Since emit2.c 1.22 from 2021-08-28, the symbols are written in alphabetic
+# order.
+
 # from expr_promote.c
 0 d 0.0 d u 6caller F1 PsT116arithmetic_types V
+# from emit.c
+0 d 0.0 d u 14cover_outqchar F0 V
+0 d 0.0 t u 11defined_int I
Index: src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln
diff -u src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln:1.2 src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln:1.3
--- src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln:1.2	Tue Aug 24 23:38:51 2021
+++ src/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln	Sat Aug 28 17:18:42 2021
@@ -1,7 +1,7 @@
-# $NetBSD: emit_lp64.exp-ln,v 1.2 2021/08/24 23:38:51 rillig Exp $
+# $NetBSD: emit_lp64.exp-ln,v 1.3 2021/08/28 17:18:42 rillig Exp $
 
 S llib-lemit_lp64.ln
 0 s llib-lemit_lp64.ln
 
-0 d 0.0 du 16uint128_function F0 uJ
 0 d 0.0 tu 15int128_variable J
+0 d 0.0 du 16uint128_function F0 uJ

Index: src/usr.bin/xlint/lint2/emit2.c
diff -u src/usr.bin/xlint/lint2/emit2.c:1.21 src/usr.bin/xlint/lint2/emit2.c:1.22
--- src/usr.bin/xlint/lint2/emit2.c:1.21	Sat Aug 28 17:11:19 2021
+++ src/usr.bin/xlint/lint2/emit2.c	Sat Aug 28 17:18:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit2.c,v 1.21 2021/08/28 17:11:19 rillig Exp $ */
+/* $NetBSD: emit2.c,v 1.22 2021/08/28 17:18:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit2.c,v 1.21 2021/08/28 17:11:19 rillig Exp $");
+__RCSID("$NetBSD: emit2.c,v 1.22 2021/08/28 17:18:42 rillig Exp $");
 #endif
 
 #include "lint2.h"
@@ -246,7 +246,7 @@ outlib(const char *name)
 	outfiles();
 
 	/* write all definitions with external linkage */
-	symtab_forall(dumpname);
+	symtab_forall_sorted(dumpname);
 
 	/* close the output */
 	outclose();

Index: src/usr.bin/xlint/lint2/externs2.h
diff -u src/usr.bin/xlint/lint2/externs2.h:1.13 src/usr.bin/xlint/lint2/externs2.h:1.14
--- src/usr.bin/xlint/lint2/externs2.h:1.13	Sat Aug 28 17:11:19 2021
+++ src/usr.bin/xlint/lint2/externs2.h	Sat Aug 28 17:18:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: externs2.h,v 1.13 2021/08/28 17:11:19 rillig Exp $ */
+/* $NetBSD: externs2.h,v 1.14 2021/08/28 17:18:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -54,6 +54,7 @@ extern	void	_inithash(hte_t ***);
 extern	hte_t	*_hsearch(hte_t **, const char *, bool);
 extern	void	symtab_forall(void (*)(hte_t *));
 extern	void	_destroyhash(hte_t **);
+extern	void	symtab_forall_sorted(void (*)(hte_t *));
 
 #define	inithash()	_inithash(NULL);
 #define	hsearch(a, b)	_hsearch(NULL, (a), (b))

Index: src/usr.bin/xlint/lint2/hash.c
diff -u src/usr.bin/xlint/lint2/hash.c:1.18 src/usr.bin/xlint/lint2/hash.c:1.19
--- src/usr.bin/xlint/lint2/hash.c:1.18	Sat Aug 28 17:11:19 2021
+++ src/usr.bin/xlint/lint2/hash.c	Sat Aug 28 17:18:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.18 2021/08/28 17:11:19 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.19 2021/08/28 17:18:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: hash.c,v 1.18 2021/08/28 17:11:19 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.19 2021/08/28 17:18:42 rillig Exp $");
 #endif
 
 /*
@@ -127,6 +127,32 @@ _hsearch(hte_t **table, const char *s, b
 	return hte;
 }
 
+struct hte_list {
+	hte_t **items;
+	size_t len;
+	size_t cap;
+};
+
+static void
+hte_list_add(struct hte_list *list, hte_t *item)
+{
+	if (list->len >= list->cap) {
+		list->cap = list->cap == 0 ? 1024 : 2 * list->cap;
+		list->items = xrealloc(list->items,
+		    sizeof(list->items[0]) * list->cap);
+	}
+	list->items[list->len++] = item;
+}
+
+static int
+hte_by_name(const void *va, const void *vb)
+{
+	const hte_t *a = *((const hte_t *const *)va);
+	const hte_t *b = *((const hte_t *const *)vb);
+
+	return strcmp(a->h_name, b->h_name);
+}
+
 /*
  * Call the action for each name in the hash table.
  */
@@ -143,6 +169,26 @@ symtab_forall(void (*action)(hte_t *))
 	}
 }
 
+
+/* Run the action for each name in the symbol table, in alphabetic order. */
+void
+symtab_forall_sorted(void (*action)(hte_t *))
+{
+	hte_t *hte;
+	struct hte_list sorted = { NULL, 0, 0 };
+	size_t i;
+	hte_t **table = htab;
+
+	for (i = 0; i < HSHSIZ2; i++)
+		for (hte = table[i]; hte != NULL; hte = hte->h_link)
+			hte_list_add(&sorted, hte);
+
+	qsort(sorted.items, sorted.len, sizeof(sorted.items[0]), hte_by_name);
+
+	for (i = 0; i < sorted.len; i++)
+		action(sorted.items[i]);
+}
+
 /*
  * Free all contents of the hash table that this module allocated.
  */

Reply via email to