Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint2 lint: write the entries for the librarie...
details: https://anonhg.NetBSD.org/src/rev/2c0c671984be
branches: trunk
changeset: 985503:2c0c671984be
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 28 17:18:42 2021 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint2/emit.exp-ln | 11 ++++--
tests/usr.bin/xlint/lint2/emit_lp64.exp-ln | 4 +-
usr.bin/xlint/lint2/emit2.c | 6 +-
usr.bin/xlint/lint2/externs2.h | 3 +-
usr.bin/xlint/lint2/hash.c | 50 ++++++++++++++++++++++++++++-
5 files changed, 62 insertions(+), 12 deletions(-)
diffs (159 lines):
diff -r 2756b4520855 -r 2c0c671984be tests/usr.bin/xlint/lint2/emit.exp-ln
--- a/tests/usr.bin/xlint/lint2/emit.exp-ln Sat Aug 28 17:17:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint2/emit.exp-ln Sat Aug 28 17:18:42 2021 +0000
@@ -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 @@
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
diff -r 2756b4520855 -r 2c0c671984be tests/usr.bin/xlint/lint2/emit_lp64.exp-ln
--- a/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln Sat Aug 28 17:17:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint2/emit_lp64.exp-ln Sat Aug 28 17:18:42 2021 +0000
@@ -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 tu 15int128_variable J
0 d 0.0 du 16uint128_function F0 uJ
-0 d 0.0 tu 15int128_variable J
diff -r 2756b4520855 -r 2c0c671984be usr.bin/xlint/lint2/emit2.c
--- a/usr.bin/xlint/lint2/emit2.c Sat Aug 28 17:17:47 2021 +0000
+++ b/usr.bin/xlint/lint2/emit2.c Sat Aug 28 17:18:42 2021 +0000
@@ -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 @@
outfiles();
/* write all definitions with external linkage */
- symtab_forall(dumpname);
+ symtab_forall_sorted(dumpname);
/* close the output */
outclose();
diff -r 2756b4520855 -r 2c0c671984be usr.bin/xlint/lint2/externs2.h
--- a/usr.bin/xlint/lint2/externs2.h Sat Aug 28 17:17:47 2021 +0000
+++ b/usr.bin/xlint/lint2/externs2.h Sat Aug 28 17:18:42 2021 +0000
@@ -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 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))
diff -r 2756b4520855 -r 2c0c671984be usr.bin/xlint/lint2/hash.c
--- a/usr.bin/xlint/lint2/hash.c Sat Aug 28 17:17:47 2021 +0000
+++ b/usr.bin/xlint/lint2/hash.c Sat Aug 28 17:18:42 2021 +0000
@@ -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 @@
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 @@
}
}
+
+/* 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.
*/
Home |
Main Index |
Thread Index |
Old Index