Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): rename hash functions to identify the ...



details:   https://anonhg.NetBSD.org/src/rev/7d613842e4b8
branches:  trunk
changeset: 956298:7d613842e4b8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 25 19:19:07 2020 +0000

description:
make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them.  Except for void pointers.

diffstat:

 usr.bin/make/arch.c |  24 +++++++++---------
 usr.bin/make/dir.c  |  59 ++++++++++++++++++++++++-----------------------
 usr.bin/make/hash.c |  66 +++++++++++++++++++---------------------------------
 usr.bin/make/hash.h |  23 ++++++++---------
 usr.bin/make/main.c |   6 ++--
 usr.bin/make/targ.c |  22 ++++++++--------
 usr.bin/make/var.c  |  26 ++++++++++----------
 7 files changed, 104 insertions(+), 122 deletions(-)

diffs (truncated from 698 to 300 lines):

diff -r d8ecad07d634 -r 7d613842e4b8 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sun Oct 25 19:11:30 2020 +0000
+++ b/usr.bin/make/arch.c       Sun Oct 25 19:19:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.146 2020/10/25 07:57:01 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.147 2020/10/25 19:19:07 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.146 2020/10/25 07:57:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.147 2020/10/25 19:19:07 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -172,11 +172,11 @@
     /* Free memory from hash entries */
     HashIter_Init(&hi, &a->members);
     while ((he = HashIter_Next(&hi)) != NULL)
-       free(Hash_GetValue(he));
+       free(HashEntry_Get(he));
 
     free(a->name);
     free(a->fnametab);
-    Hash_DeleteTable(&a->members);
+    HashTable_Done(&a->members);
     free(a);
 }
 #endif
@@ -445,7 +445,7 @@
        struct ar_hdr *hdr;
 
        ar = ln->datum;
-       hdr = Hash_FindValue(&ar->members, member);
+       hdr = HashTable_FindValue(&ar->members, member);
        if (hdr != NULL)
            return hdr;
 
@@ -458,7 +458,7 @@
                len = AR_MAX_NAME_LEN;
                snprintf(copy, sizeof copy, "%s", member);
            }
-           hdr = Hash_FindValue(&ar->members, copy);
+           hdr = HashTable_FindValue(&ar->members, copy);
            return hdr;
        }
     }
@@ -503,7 +503,7 @@
     ar->name = bmake_strdup(archive);
     ar->fnametab = NULL;
     ar->fnamesize = 0;
-    Hash_InitTable(&ar->members);
+    HashTable_Init(&ar->members);
     memName[AR_MAX_NAME_LEN] = '\0';
 
     while (fread((char *)&arh, sizeof(struct ar_hdr), 1, arch) == 1) {
@@ -580,9 +580,9 @@
 
            {
                HashEntry *he;
-               he = Hash_CreateEntry(&ar->members, memName, NULL);
-               Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
-               memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
+               he = HashTable_CreateEntry(&ar->members, memName, NULL);
+               HashEntry_Set(he, bmake_malloc(sizeof(struct ar_hdr)));
+               memcpy(HashEntry_Get(he), &arh, sizeof(struct ar_hdr));
            }
        }
        if (fseek(arch, ((long)size + 1) & ~1, SEEK_CUR) != 0)
@@ -597,11 +597,11 @@
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
-    return Hash_FindValue(&ar->members, member);
+    return HashTable_FindValue(&ar->members, member);
 
 badarch:
     fclose(arch);
-    Hash_DeleteTable(&ar->members);
+    HashTable_Done(&ar->members);
     free(ar->fnametab);
     free(ar);
     return NULL;
diff -r d8ecad07d634 -r 7d613842e4b8 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sun Oct 25 19:11:30 2020 +0000
+++ b/usr.bin/make/dir.c        Sun Oct 25 19:19:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.187 2020/10/25 10:00:20 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.188 2020/10/25 19:19:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -135,7 +135,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.187 2020/10/25 10:00:20 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.188 2020/10/25 19:19:07 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -228,7 +228,7 @@
 OpenDirs_Init(OpenDirs *odirs)
 {
     odirs->list = Lst_New();
-    Hash_InitTable(&odirs->table);
+    HashTable_Init(&odirs->table);
 }
 
 #ifdef CLEANUP
@@ -243,37 +243,37 @@
        ln = next;
     }
     Lst_Free(odirs->list);
-    Hash_DeleteTable(&odirs->table);
+    HashTable_Done(&odirs->table);
 }
 #endif
 
 static CachedDir *
 OpenDirs_Find(OpenDirs *odirs, const char *name)
 {
-    CachedDirListNode *ln = Hash_FindValue(&odirs->table, name);
+    CachedDirListNode *ln = HashTable_FindValue(&odirs->table, name);
     return ln != NULL ? ln->datum : NULL;
 }
 
 static void
 OpenDirs_Add(OpenDirs *odirs, CachedDir *cdir)
 {
-    HashEntry *he = Hash_FindEntry(&odirs->table, cdir->name);
+    HashEntry *he = HashTable_FindEntry(&odirs->table, cdir->name);
     if (he != NULL)
        return;
-    he = Hash_CreateEntry(&odirs->table, cdir->name, NULL);
+    he = HashTable_CreateEntry(&odirs->table, cdir->name, NULL);
     Lst_Append(odirs->list, cdir);
-    Hash_SetValue(he, odirs->list->last);
+    HashEntry_Set(he, odirs->list->last);
 }
 
 static void
 OpenDirs_Remove(OpenDirs *odirs, const char *name)
 {
-    HashEntry *he = Hash_FindEntry(&odirs->table, name);
+    HashEntry *he = HashTable_FindEntry(&odirs->table, name);
     CachedDirListNode *ln;
     if (he == NULL)
        return;
-    ln = Hash_GetValue(he);
-    Hash_DeleteEntry(&odirs->table, he);
+    ln = HashEntry_Get(he);
+    HashTable_DeleteEntry(&odirs->table, he);
     Lst_Remove(odirs->list, ln);
 }
 
@@ -333,10 +333,10 @@
     if (!pathname || !pathname[0])
        return -1;
 
-    entry = Hash_FindEntry(htp, pathname);
+    entry = HashTable_FindEntry(htp, pathname);
 
     if (entry && !(flags & CST_UPDATE)) {
-       cst = Hash_GetValue(entry);
+       cst = HashEntry_Get(entry);
 
        mst->mst_mode = cst->mode;
        mst->mst_mtime = (flags & CST_LSTAT) ? cst->lmtime : cst->mtime;
@@ -360,12 +360,12 @@
     mst->mst_mtime = sys_st.st_mtime;
 
     if (entry == NULL)
-       entry = Hash_CreateEntry(htp, pathname, NULL);
-    if (Hash_GetValue(entry) == NULL) {
-       Hash_SetValue(entry, bmake_malloc(sizeof(*cst)));
-       memset(Hash_GetValue(entry), 0, sizeof(*cst));
+       entry = HashTable_CreateEntry(htp, pathname, NULL);
+    if (HashEntry_Get(entry) == NULL) {
+       HashEntry_Set(entry, bmake_malloc(sizeof(*cst)));
+       memset(HashEntry_Get(entry), 0, sizeof(*cst));
     }
-    cst = Hash_GetValue(entry);
+    cst = HashEntry_Get(entry);
     if (flags & CST_LSTAT) {
        cst->lmtime = sys_st.st_mtime;
     } else {
@@ -396,8 +396,8 @@
 {
     dirSearchPath = Lst_New();
     OpenDirs_Init(&openDirs);
-    Hash_InitTable(&mtimes);
-    Hash_InitTable(&lmtimes);
+    HashTable_Init(&mtimes);
+    HashTable_Init(&lmtimes);
 }
 
 void
@@ -409,7 +409,7 @@
     dotLast->refCount = 1;
     dotLast->hits = 0;
     dotLast->name = bmake_strdup(".DOTLAST");
-    Hash_InitTable(&dotLast->files);
+    HashTable_Init(&dotLast->files);
 }
 
 /*
@@ -480,7 +480,7 @@
     Dir_ClearPath(dirSearchPath);
     Lst_Free(dirSearchPath);
     OpenDirs_Done(&openDirs);
-    Hash_DeleteTable(&mtimes);
+    HashTable_Done(&mtimes);
 #endif
 }
 
@@ -872,7 +872,7 @@
 
     DIR_DEBUG1("   %s ...\n", dir->name);
 
-    if (Hash_FindEntry(&dir->files, base) == NULL)
+    if (HashTable_FindEntry(&dir->files, base) == NULL)
        return NULL;
 
     file = str_concat3(dir->name, "/", base);
@@ -925,7 +925,7 @@
     if (*dnp != '\0' || np != cp - 1)
        return NULL;
 
-    if (Hash_FindEntry(&dir->files, cp) == NULL) {
+    if (HashTable_FindEntry(&dir->files, cp) == NULL) {
        DIR_DEBUG0("   must be here but isn't -- returning\n");
        return bmake_strdup("");        /* to terminate the search */
     }
@@ -942,13 +942,14 @@
 DirFindDot(const char *name, const char *base)
 {
 
-    if (Hash_FindEntry(&dot->files, base) != NULL) {
+    if (HashTable_FindEntry(&dot->files, base) != NULL) {
        DIR_DEBUG0("   in '.'\n");
        hits++;
        dot->hits++;
        return bmake_strdup(name);
     }
-    if (cur != NULL && Hash_FindEntry(&cur->files, base) != NULL) {
+
+    if (cur != NULL && HashTable_FindEntry(&cur->files, base) != NULL) {
        DIR_DEBUG1("   in ${.CURDIR} = %s\n", cur->name);
        hits++;
        cur->hits++;
@@ -1423,7 +1424,7 @@
        dir->name = bmake_strdup(name);
        dir->hits = 0;
        dir->refCount = 1;
-       Hash_InitTable(&dir->files);
+       HashTable_Init(&dir->files);
 
        while ((dp = readdir(d)) != NULL) {
 #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */
@@ -1436,7 +1437,7 @@
                continue;
            }
 #endif /* sun && d_ino */
-           (void)Hash_CreateEntry(&dir->files, dp->d_name, NULL);
+           (void)HashTable_CreateEntry(&dir->files, dp->d_name, NULL);
        }
        (void)closedir(d);
        OpenDirs_Add(&openDirs, dir);
@@ -1530,7 +1531,7 @@
     if (dir->refCount == 0) {
        OpenDirs_Remove(&openDirs, dir->name);
 
-       Hash_DeleteTable(&dir->files);
+       HashTable_Done(&dir->files);
        free(dir->name);
        free(dir);
     }
diff -r d8ecad07d634 -r 7d613842e4b8 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Sun Oct 25 19:11:30 2020 +0000
+++ b/usr.bin/make/hash.c       Sun Oct 25 19:19:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.53 2020/10/25 18:40:00 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.54 2020/10/25 19:19:07 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.53 2020/10/25 18:40:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.54 2020/10/25 19:19:07 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -123,9 +123,9 @@



Home | Main Index | Thread Index | Old Index