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): make dir.c, for.c and hash.c ready for...



details:   https://anonhg.NetBSD.org/src/rev/96b93a2fe3c5
branches:  trunk
changeset: 955648:96b93a2fe3c5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Oct 05 20:21:30 2020 +0000

description:
make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.

diffstat:

 usr.bin/make/dir.c  |   8 ++++----
 usr.bin/make/dir.h  |   6 +++---
 usr.bin/make/for.c  |  17 +++++++++--------
 usr.bin/make/hash.c |  29 +++++++++++++++--------------
 usr.bin/make/hash.h |  12 ++++++------
 5 files changed, 37 insertions(+), 35 deletions(-)

diffs (237 lines):

diff -r fdb972f30b6c -r 96b93a2fe3c5 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Oct 05 19:59:07 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Oct 05 20:21:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.159 2020/10/05 19:30:37 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.160 2020/10/05 20:21:30 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.159 2020/10/05 19:30:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.160 2020/10/05 20:21:30 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -1377,7 +1377,7 @@
  */
 Boolean
 Dir_FindHereOrAbove(const char *here, const char *search_path,
-                   char *result, int result_len)
+                   char *result, size_t result_len)
 {
     struct make_stat mst;
     char dirbase[MAXPATHLEN + 1], *dirbase_end;
@@ -1446,7 +1446,7 @@
  *     found one for it, the full name is placed in the path slot.
  *-----------------------------------------------------------------------
  */
-int
+time_t
 Dir_MTime(GNode *gn, Boolean recheck)
 {
     char *fullName;            /* the full pathname of name */
diff -r fdb972f30b6c -r 96b93a2fe3c5 usr.bin/make/dir.h
--- a/usr.bin/make/dir.h        Mon Oct 05 19:59:07 2020 +0000
+++ b/usr.bin/make/dir.h        Mon Oct 05 20:21:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.h,v 1.27 2020/09/27 22:17:07 rillig Exp $  */
+/*     $NetBSD: dir.h,v 1.28 2020/10/05 20:21:30 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,8 +99,8 @@
 Boolean Dir_HasWildcards(const char *);
 void Dir_Expand(const char *, SearchPath *, StringList *);
 char *Dir_FindFile(const char *, SearchPath *);
-Boolean Dir_FindHereOrAbove(const char *, const char *, char *, int);
-int Dir_MTime(GNode *, Boolean);
+Boolean Dir_FindHereOrAbove(const char *, const char *, char *, size_t);
+time_t Dir_MTime(GNode *, Boolean);
 CachedDir *Dir_AddDir(SearchPath *, const char *);
 char *Dir_MakeFlags(const char *, SearchPath *);
 void Dir_ClearPath(SearchPath *);
diff -r fdb972f30b6c -r 96b93a2fe3c5 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Mon Oct 05 19:59:07 2020 +0000
+++ b/usr.bin/make/for.c        Mon Oct 05 20:21:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.92 2020/10/05 19:27:47 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.93 2020/10/05 20:21:30 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -61,7 +61,7 @@
 #include    "strlist.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.92 2020/10/05 19:27:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.93 2020/10/05 20:21:30 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -83,7 +83,7 @@
      * are substituted, the parser must handle $V expressions as well, not
      * only ${V} and $(V). */
     Boolean short_var;
-    int sub_next;
+    unsigned int sub_next;
 } For;
 
 static For *accumFor;          /* Loop being accumulated */
@@ -149,7 +149,7 @@
     new_for->sub_next = 0;
 
     /* Grab the variables. Terminate on "in". */
-    while (TRUE) {
+    for (;;) {
        size_t len;
 
        cpp_skip_whitespace(&ptr);
@@ -168,7 +168,8 @@
        if (len == 1)
            new_for->short_var = TRUE;
 
-       strlist_add_str(&new_for->vars, bmake_strldup(ptr, len), len);
+       strlist_add_str(&new_for->vars, bmake_strldup(ptr, len),
+                       (unsigned int)len);
        ptr += len;
     }
 
@@ -325,8 +326,8 @@
 
     /* If there were no escapes, or the only escape is the other variable
      * terminator, then just substitute the full string */
-    if (!(escapes &
-         (ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
+    if (!(escapes & (ech == ')' ? ~(unsigned)FOR_SUB_ESCAPE_BRACE
+                               : ~(unsigned)FOR_SUB_ESCAPE_PAREN))) {
        Buf_AddStr(cmds, item);
        return;
     }
@@ -352,7 +353,7 @@
 ForIterate(void *v_arg, size_t *ret_len)
 {
     For *arg = v_arg;
-    int i;
+    unsigned int i;
     char *var;
     const char *cp;
     const char *cmd_cp;
diff -r fdb972f30b6c -r 96b93a2fe3c5 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Mon Oct 05 19:59:07 2020 +0000
+++ b/usr.bin/make/hash.c       Mon Oct 05 20:21:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.43 2020/10/05 19:27:47 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.44 2020/10/05 20:21:30 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.43 2020/10/05 19:27:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.44 2020/10/05 20:21:30 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -104,7 +104,7 @@
 HashTable_Find(Hash_Table *t, unsigned int h, const char *key)
 {
        Hash_Entry *e;
-       int chainlen = 0;
+       unsigned int chainlen = 0;
 
 #ifdef DEBUG_HASH_LOOKUP
        DEBUG4(HASH, "%s: %p h=%x key=%s\n", __func__, t, h, key);
@@ -126,7 +126,7 @@
 void
 Hash_InitTable(Hash_Table *t)
 {
-       size_t n = 16, i;
+       unsigned int n = 16, i;
        struct Hash_Entry **hp;
 
        t->numEntries = 0;
@@ -146,7 +146,7 @@
        struct Hash_Entry **hp, *h, *nexth = NULL;
        int i;
 
-       for (hp = t->buckets, i = t->bucketsSize; --i >= 0;) {
+       for (hp = t->buckets, i = (int)t->bucketsSize; --i >= 0;) {
                for (h = *hp++; h != NULL; h = nexth) {
                        nexth = h->next;
                        free(h);
@@ -191,19 +191,20 @@
 RebuildTable(Hash_Table *t)
 {
        Hash_Entry *e, *next = NULL, **hp, **xp;
-       int i, mask;
+       int i;
+       unsigned int mask, oldsize, newsize;
        Hash_Entry **oldhp;
-       int oldsize;
 
        oldhp = t->buckets;
-       oldsize = i = t->bucketsSize;
-       i <<= 1;
-       t->bucketsSize = i;
-       t->bucketsMask = mask = i - 1;
-       t->buckets = hp = bmake_malloc(sizeof(*hp) * i);
+       oldsize = t->bucketsSize;
+       newsize = oldsize << 1;
+       t->bucketsSize = (unsigned int)newsize;
+       t->bucketsMask = mask = newsize - 1;
+       t->buckets = hp = bmake_malloc(sizeof(*hp) * newsize);
+       i = (int)newsize;
        while (--i >= 0)
                *hp++ = NULL;
-       for (hp = oldhp, i = oldsize; --i >= 0;) {
+       for (hp = oldhp, i = (int)oldsize; --i >= 0;) {
                for (e = *hp++; e != NULL; e = next) {
                        next = e->next;
                        xp = &t->buckets[e->namehash & mask];
@@ -349,6 +350,6 @@
 void
 Hash_DebugStats(Hash_Table *t, const char *name)
 {
-       DEBUG4(HASH, "Hash_Table %s: size=%d numEntries=%d maxchain=%d\n",
+       DEBUG4(HASH, "Hash_Table %s: size=%u numEntries=%u maxchain=%u\n",
               name, t->bucketsSize, t->numEntries, t->maxchain);
 }
diff -r fdb972f30b6c -r 96b93a2fe3c5 usr.bin/make/hash.h
--- a/usr.bin/make/hash.h       Mon Oct 05 19:59:07 2020 +0000
+++ b/usr.bin/make/hash.h       Mon Oct 05 20:21:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.h,v 1.25 2020/09/27 21:35:16 rillig Exp $ */
+/*     $NetBSD: hash.h,v 1.26 2020/10/05 20:21:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -90,10 +90,10 @@
 typedef struct Hash_Table {
     Hash_Entry **buckets;      /* Pointers to Hash_Entry, one
                                 * for each bucket in the table. */
-    int bucketsSize;
-    int numEntries;            /* Number of entries in the table. */
-    int bucketsMask;           /* Used to select the bucket for a hash. */
-    int maxchain;              /* max length of chain detected */
+    unsigned int bucketsSize;
+    unsigned int numEntries;   /* Number of entries in the table. */
+    unsigned int bucketsMask;  /* Used to select the bucket for a hash. */
+    unsigned int maxchain;     /* max length of chain detected */
 } Hash_Table;
 
 /*
@@ -102,7 +102,7 @@
  */
 typedef struct Hash_Search {
     Hash_Table *table;         /* Table being searched. */
-    int nextBucket;            /* Next bucket to check (after current). */
+    unsigned int nextBucket;   /* Next bucket to check (after current). */
     Hash_Entry *entry;         /* Next entry to check in current bucket. */
 } Hash_Search;
 



Home | Main Index | Thread Index | Old Index