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): add Hash_FindValue, for direct access ...



details:   https://anonhg.NetBSD.org/src/rev/ac4d0eb8655d
branches:  trunk
changeset: 955310:ac4d0eb8655d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 26 14:48:31 2020 +0000

description:
make(1): add Hash_FindValue, for direct access to hash table data

diffstat:

 usr.bin/make/arch.c |  40 ++++++++++++++++++----------------------
 usr.bin/make/hash.c |  11 +++++++++--
 usr.bin/make/hash.h |   3 ++-
 usr.bin/make/var.c  |  30 ++++++++++++------------------
 4 files changed, 41 insertions(+), 43 deletions(-)

diffs (225 lines):

diff -r 295ae2d59dfd -r ac4d0eb8655d usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Sep 26 14:18:06 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Sep 26 14:48:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.121 2020/09/25 14:49:51 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -133,7 +133,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.121 2020/09/25 14:49:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.122 2020/09/26 14:48:31 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -466,7 +466,6 @@
     char         magic[SARMAG];
     ArchListNode *ln;
     Arch         *ar;        /* Archive descriptor */
-    Hash_Entry   *he;        /* Entry containing member's description */
     struct ar_hdr arh;        /* archive-member header for reading archive */
     char         memName[MAXPATHLEN+1];
                            /* Current member name while hashing. */
@@ -489,13 +488,14 @@
     }
 
     if (ln != NULL) {
-       ar = LstNode_Datum(ln);
-
-       he = Hash_FindEntry(&ar->members, member);
+       struct ar_hdr *hdr;
 
-       if (he != NULL) {
-           return (struct ar_hdr *)Hash_GetValue(he);
-       } else {
+       ar = LstNode_Datum(ln);
+       hdr = Hash_FindValue(&ar->members, member);
+       if (hdr != NULL)
+           return hdr;
+
+       {
            /* Try truncated name */
            char copy[AR_MAX_NAME_LEN+1];
            size_t len = strlen(member);
@@ -504,9 +504,8 @@
                len = AR_MAX_NAME_LEN;
                snprintf(copy, sizeof copy, "%s", member);
            }
-           if ((he = Hash_FindEntry(&ar->members, copy)) != NULL)
-               return (struct ar_hdr *)Hash_GetValue(he);
-           return NULL;
+           hdr = Hash_FindValue(&ar->members, copy);
+           return hdr;
        }
     }
 
@@ -628,9 +627,12 @@
            }
 #endif
 
-           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));
+           {
+               Hash_Entry *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));
+           }
        }
        if (fseek(arch, ((long)size + 1) & ~1, SEEK_CUR) != 0)
            goto badarch;
@@ -644,13 +646,7 @@
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
-    he = Hash_FindEntry(&ar->members, member);
-
-    if (he != NULL) {
-       return (struct ar_hdr *)Hash_GetValue(he);
-    } else {
-       return NULL;
-    }
+    return Hash_FindValue(&ar->members, member);
 
 badarch:
     fclose(arch);
diff -r 295ae2d59dfd -r ac4d0eb8655d usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Sat Sep 26 14:18:06 2020 +0000
+++ b/usr.bin/make/hash.c       Sat Sep 26 14:48:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.32 2020/09/13 15:15:51 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.33 2020/09/26 14:48:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
 #include "make.h"
 
 /*     "@(#)hash.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: hash.c,v 1.32 2020/09/13 15:15:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.33 2020/09/26 14:48:31 rillig Exp $");
 
 /*
  * Forward references to local procedures that are used before they're
@@ -188,6 +188,13 @@
        return e;
 }
 
+void *
+Hash_FindValue(Hash_Table *t, const char *key)
+{
+    Hash_Entry *he = Hash_FindEntry(t, key);
+    return he != NULL ? he->value : NULL;
+}
+
 /* Searches the hash table for an entry corresponding to the key.
  * If no entry is found, then one is created.
  *
diff -r 295ae2d59dfd -r ac4d0eb8655d usr.bin/make/hash.h
--- a/usr.bin/make/hash.h       Sat Sep 26 14:18:06 2020 +0000
+++ b/usr.bin/make/hash.h       Sat Sep 26 14:48:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.h,v 1.23 2020/09/13 15:27:25 rillig Exp $ */
+/*     $NetBSD: hash.h,v 1.24 2020/09/26 14:48:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -121,6 +121,7 @@
 void Hash_InitTable(Hash_Table *);
 void Hash_DeleteTable(Hash_Table *);
 Hash_Entry *Hash_FindEntry(Hash_Table *, const char *);
+void *Hash_FindValue(Hash_Table *, const char *);
 Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *);
 void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
 Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
diff -r 295ae2d59dfd -r ac4d0eb8655d usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Sep 26 14:18:06 2020 +0000
+++ b/usr.bin/make/var.c        Sat Sep 26 14:48:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.541 2020/09/25 15:54:51 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.542 2020/09/26 14:48:31 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.541 2020/09/25 15:54:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.542 2020/09/26 14:48:31 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)   \
     if (!(DEBUG(VAR) && (cond)))       \
@@ -277,7 +277,7 @@
 static Var *
 VarFind(const char *name, GNode *ctxt, VarFindFlags flags)
 {
-    Hash_Entry *var;
+    Var *var;
 
     /*
      * If the variable name begins with a '.', it could very well be one of
@@ -322,7 +322,7 @@
        }
     }
 
-#ifdef notyet
+#if 0
     /* for compatibility with gmake */
     if (name[0] == '^' && name[1] == '\0')
        name = ALLSRC;
@@ -333,18 +333,18 @@
      * look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order,
      * depending on the FIND_* flags in 'flags'
      */
-    var = Hash_FindEntry(&ctxt->context, name);
+    var = Hash_FindValue(&ctxt->context, name);
 
     if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMD)
-       var = Hash_FindEntry(&VAR_CMD->context, name);
+       var = Hash_FindValue(&VAR_CMD->context, name);
 
     if (!checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) &&
        ctxt != VAR_GLOBAL)
     {
-       var = Hash_FindEntry(&VAR_GLOBAL->context, name);
+       var = Hash_FindValue(&VAR_GLOBAL->context, name);
        if (var == NULL && ctxt != VAR_INTERNAL) {
            /* VAR_INTERNAL is subordinate to VAR_GLOBAL */
-           var = Hash_FindEntry(&VAR_INTERNAL->context, name);
+           var = Hash_FindValue(&VAR_INTERNAL->context, name);
        }
     }
 
@@ -365,22 +365,16 @@
        }
 
        if (checkEnvFirst && (flags & FIND_GLOBAL) && ctxt != VAR_GLOBAL) {
-           var = Hash_FindEntry(&VAR_GLOBAL->context, name);
+           var = Hash_FindValue(&VAR_GLOBAL->context, name);
            if (var == NULL && ctxt != VAR_INTERNAL)
-               var = Hash_FindEntry(&VAR_INTERNAL->context, name);
-           if (var == NULL)
-               return NULL;
-           else
-               return (Var *)Hash_GetValue(var);
+               var = Hash_FindValue(&VAR_INTERNAL->context, name);
+           return var;
        }
 
        return NULL;
     }
 
-    if (var == NULL)
-       return NULL;
-    else
-       return (Var *)Hash_GetValue(var);
+    return var;
 }
 
 /*-



Home | Main Index | Thread Index | Old Index