Module Name: src Committed By: rillig Date: Fri May 31 05:50:11 UTC 2024
Modified Files: src/usr.bin/make: arch.c dir.c hash.c hash.h main.c parse.c var.c Log Message: make: clean up API for iterating over hash tables To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/usr.bin/make/arch.c cvs rdiff -u -r1.293 -r1.294 src/usr.bin/make/dir.c cvs rdiff -u -r1.75 -r1.76 src/usr.bin/make/hash.c cvs rdiff -u -r1.48 -r1.49 src/usr.bin/make/hash.h cvs rdiff -u -r1.618 -r1.619 src/usr.bin/make/main.c cvs rdiff -u -r1.727 -r1.728 src/usr.bin/make/parse.c cvs rdiff -u -r1.1113 -r1.1114 src/usr.bin/make/var.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/make/arch.c diff -u src/usr.bin/make/arch.c:1.217 src/usr.bin/make/arch.c:1.218 --- src/usr.bin/make/arch.c:1.217 Sat Apr 27 20:41:32 2024 +++ src/usr.bin/make/arch.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $ */ +/* $NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -126,7 +126,7 @@ #include "config.h" /* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: arch.c,v 1.217 2024/04/27 20:41:32 rillig Exp $"); +MAKE_RCSID("$NetBSD: arch.c,v 1.218 2024/05/31 05:50:11 rillig Exp $"); typedef struct List ArchList; typedef struct ListNode ArchListNode; @@ -156,7 +156,7 @@ ArchFree(Arch *a) HashIter hi; HashIter_Init(&hi, &a->members); - while (HashIter_Next(&hi) != NULL) + while (HashIter_Next(&hi)) free(hi.entry->value); free(a->name); Index: src/usr.bin/make/dir.c diff -u src/usr.bin/make/dir.c:1.293 src/usr.bin/make/dir.c:1.294 --- src/usr.bin/make/dir.c:1.293 Sat May 25 08:03:19 2024 +++ src/usr.bin/make/dir.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $ */ +/* $NetBSD: dir.c,v 1.294 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -132,7 +132,7 @@ #include "job.h" /* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $"); +MAKE_RCSID("$NetBSD: dir.c,v 1.294 2024/05/31 05:50:11 rillig Exp $"); /* * A search path is a list of CachedDir structures. A CachedDir has in it the @@ -507,7 +507,7 @@ FreeCachedTable(HashTable *tbl) { HashIter hi; HashIter_Init(&hi, tbl); - while (HashIter_Next(&hi) != NULL) + while (HashIter_Next(&hi)) free(hi.entry->value); HashTable_Done(tbl); } @@ -656,7 +656,7 @@ DirMatchFiles(const char *pattern, Cache */ HashIter_InitSet(&hi, &dir->files); - while (HashIter_Next(&hi) != NULL) { + while (HashIter_Next(&hi)) { const char *base = hi.entry->key; StrMatchResult res = Str_Match(base, pattern); /* TODO: handle errors from res.error */ Index: src/usr.bin/make/hash.c diff -u src/usr.bin/make/hash.c:1.75 src/usr.bin/make/hash.c:1.76 --- src/usr.bin/make/hash.c:1.75 Fri May 24 22:54:07 2024 +++ src/usr.bin/make/hash.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.75 2024/05/24 22:54:07 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.76 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -74,7 +74,7 @@ #include "make.h" /* "@(#)hash.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: hash.c,v 1.75 2024/05/24 22:54:07 rillig Exp $"); +MAKE_RCSID("$NetBSD: hash.c,v 1.76 2024/05/31 05:50:11 rillig Exp $"); /* * The ratio of # entries to # buckets at which we rebuild the table to @@ -300,7 +300,7 @@ HashTable_DeleteEntry(HashTable *t, Hash * Return the next entry in the hash table, or NULL if the end of the table * is reached. */ -HashEntry * +bool HashIter_Next(HashIter *hi) { HashTable *t = hi->table; @@ -313,11 +313,11 @@ HashIter_Next(HashIter *hi) while (he == NULL) { /* find the next nonempty chain */ if (hi->nextBucket >= bucketsSize) - return NULL; + return false; he = buckets[hi->nextBucket++]; } hi->entry = he; - return he; + return he != NULL; } void Index: src/usr.bin/make/hash.h diff -u src/usr.bin/make/hash.h:1.48 src/usr.bin/make/hash.h:1.49 --- src/usr.bin/make/hash.h:1.48 Tue Dec 19 19:33:39 2023 +++ src/usr.bin/make/hash.h Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.48 2023/12/19 19:33:39 rillig Exp $ */ +/* $NetBSD: hash.h,v 1.49 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -140,7 +140,7 @@ void HashTable_Set(HashTable *, const ch void HashTable_DeleteEntry(HashTable *, HashEntry *); void HashTable_DebugStats(HashTable *, const char *); -HashEntry *HashIter_Next(HashIter *); +bool HashIter_Next(HashIter *); MAKE_INLINE void HashSet_Init(HashSet *set) Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.618 src/usr.bin/make/main.c:1.619 --- src/usr.bin/make/main.c:1.618 Tue May 28 19:09:04 2024 +++ src/usr.bin/make/main.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.618 2024/05/28 19:09:04 sjg Exp $ */ +/* $NetBSD: main.c,v 1.619 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.618 2024/05/28 19:09:04 sjg Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.619 2024/05/31 05:50:11 rillig Exp $"); #if defined(MAKE_NATIVE) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1970,13 +1970,13 @@ execDie(const char *af, const char *av) static void purge_relative_cached_realpaths(void) { - HashEntry *he, *next; HashIter hi; HashIter_Init(&hi, &cached_realpaths); - he = HashIter_Next(&hi); - while (he != NULL) { - next = HashIter_Next(&hi); + HashIter_Next(&hi); + while (hi.entry != NULL) { + HashEntry *he = hi.entry; + HashIter_Next(&hi); if (he->key[0] != '/') { DEBUG1(DIR, "cached_realpath: purging %s\n", he->key); HashTable_DeleteEntry(&cached_realpaths, he); @@ -1985,7 +1985,6 @@ purge_relative_cached_realpaths(void) * free them or document why they cannot be freed. */ } - he = next; } } Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.727 src/usr.bin/make/parse.c:1.728 --- src/usr.bin/make/parse.c:1.727 Sat May 25 22:08:35 2024 +++ src/usr.bin/make/parse.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.727 2024/05/25 22:08:35 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -105,7 +105,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.727 2024/05/25 22:08:35 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -2985,7 +2985,7 @@ Parse_End(void) assert(includes.len == 0); Vector_Done(&includes); HashIter_Init(&hi, &guards); - while (HashIter_Next(&hi) != NULL) { + while (HashIter_Next(&hi)) { Guard *guard = hi.entry->value; free(guard->name); free(guard); Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1113 src/usr.bin/make/var.c:1.1114 --- src/usr.bin/make/var.c:1.1113 Thu May 30 21:50:34 2024 +++ src/usr.bin/make/var.c Fri May 31 05:50:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1113 2024/05/30 21:50:34 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1114 2024/05/31 05:50:11 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -132,7 +132,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1113 2024/05/30 21:50:34 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1114 2024/05/31 05:50:11 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -588,7 +588,7 @@ Var_DeleteAll(GNode *scope) { HashIter hi; HashIter_Init(&hi, &scope->vars); - while (HashIter_Next(&hi) != NULL) { + while (HashIter_Next(&hi)) { Var *v = hi.entry->value; Buf_Done(&v->val); free(v); @@ -781,7 +781,7 @@ Var_ReexportVars(GNode *scope) /* Ouch! Exporting all variables at once is crazy. */ HashIter_Init(&hi, &SCOPE_GLOBAL->vars); - while (HashIter_Next(&hi) != NULL) { + while (HashIter_Next(&hi)) { Var *var = hi.entry->value; ExportVar(var->name.str, scope, VEM_ENV); } @@ -4805,7 +4805,7 @@ Var_Dump(GNode *scope) Vector_Init(&vec, sizeof(const char *)); HashIter_Init(&hi, &scope->vars); - while (HashIter_Next(&hi) != NULL) + while (HashIter_Next(&hi)) *(const char **)Vector_Push(&vec) = hi.entry->key; varnames = vec.items;