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: use unsigned int for line numbers everywhere



details:   https://anonhg.NetBSD.org/src/rev/da04b1c2a8b8
branches:  trunk
changeset: 359974:da04b1c2a8b8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Feb 04 23:22:19 2022 +0000

description:
make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t.  Since line numbers are never negative, use an
unsigned type.  Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions.  Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.

diffstat:

 usr.bin/make/dir.c   |   6 +++---
 usr.bin/make/for.c   |   6 +++---
 usr.bin/make/job.c   |   6 +++---
 usr.bin/make/make.h  |  11 ++++++-----
 usr.bin/make/meta.c  |  34 +++++++++++++++++-----------------
 usr.bin/make/parse.c |  49 ++++++++++++++++++++++++-------------------------
 6 files changed, 56 insertions(+), 56 deletions(-)

diffs (truncated from 448 to 300 lines):

diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/dir.c        Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.277 2022/01/30 13:21:08 christos Exp $       */
+/*     $NetBSD: dir.c,v 1.278 2022/02/04 23:22:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -138,7 +138,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.277 2022/01/30 13:21:08 christos Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.278 2022/02/04 23:22:19 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -1425,7 +1425,7 @@
        gn->path = bmake_strdup(fullName);
        if (!Job_RunTarget(".STALE", gn->fname))
                fprintf(stdout, /* XXX: Why stdout? */
-                   "%s: %s, %zu: ignoring stale %s for %s, found %s\n",
+                   "%s: %s, %u: ignoring stale %s for %s, found %s\n",
                    progname, gn->fname, gn->lineno,
                    makeDependfile, gn->name, fullName);
 
diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/for.c        Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.166 2022/01/27 11:16:44 rillig Exp $ */
+/*     $NetBSD: for.c,v 1.167 2022/02/04 23:22:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.166 2022/01/27 11:16:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.167 2022/02/04 23:22:19 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -485,7 +485,7 @@
 
 /* Run the .for loop, imitating the actions of an include file. */
 void
-For_Run(int headLineno, int bodyReadLines)
+For_Run(unsigned headLineno, unsigned bodyReadLines)
 {
        Buffer buf;
        ForLoop *f = accumFor;
diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/job.c        Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.450 2022/01/30 13:21:08 christos Exp $       */
+/*     $NetBSD: job.c,v 1.451 2022/02/04 23:22:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.450 2022/01/30 13:21:08 christos Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.451 2022/02/04 23:22:19 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1374,7 +1374,7 @@
        if (gn->flags.fromDepend) {
                if (!Job_RunTarget(".STALE", gn->fname))
                        fprintf(stdout,
-                           "%s: %s, %zu: ignoring stale %s for %s\n",
+                           "%s: %s, %u: ignoring stale %s for %s\n",
                            progname, gn->fname, gn->lineno, makeDependfile,
                            gn->name);
                return true;
diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/make.h       Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.296 2022/01/31 20:49:27 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.297 2022/02/04 23:22:19 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -499,7 +499,7 @@
        /* Filename where the GNode got defined, unlimited lifetime */
        const char *fname;
        /* Line number where the GNode got defined, 1-based */
-       size_t lineno;
+       unsigned lineno;
 } GNode;
 
 /* Error levels for diagnostics during parsing. */
@@ -805,7 +805,7 @@
 struct ForLoop;
 int For_Eval(const char *) MAKE_ATTR_USE;
 bool For_Accum(const char *, int *) MAKE_ATTR_USE;
-void For_Run(int, int);
+void For_Run(unsigned, unsigned);
 bool For_NextIteration(struct ForLoop *, Buffer *);
 char *ForLoop_Details(struct ForLoop *);
 void ForLoop_Free(struct ForLoop *);
@@ -832,13 +832,14 @@
 void Parse_Init(void);
 void Parse_End(void);
 
-void PrintLocation(FILE *, bool, const char *, size_t);
+void PrintLocation(FILE *, bool, const char *, unsigned);
 void PrintStackTrace(bool);
 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
 bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
 void Parse_AddIncludeDir(const char *);
 void Parse_File(const char *, int);
-void Parse_PushInput(const char *, int, int, Buffer, struct ForLoop *);
+void Parse_PushInput(const char *, unsigned, unsigned, Buffer,
+                    struct ForLoop *);
 void Parse_MainName(GNodeList *);
 int Parse_NumErrors(void) MAKE_ATTR_USE;
 
diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/meta.c       Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.195 2022/01/27 06:02:59 sjg Exp $ */
+/*      $NetBSD: meta.c,v 1.196 2022/02/04 23:22:19 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1025,7 +1025,7 @@
  * Setting oodate true will have that effect.
  */
 #define CHECK_VALID_META(p) if (!(p != NULL && *p != '\0')) { \
-    warnx("%s: %d: malformed", fname, lineno); \
+    warnx("%s: %u: malformed", fname, lineno); \
     oodate = true; \
     continue; \
     }
@@ -1137,7 +1137,7 @@
     if ((fp = fopen(fname, "r")) != NULL) {
        static char *buf = NULL;
        static size_t bufsz;
-       int lineno = 0;
+       unsigned lineno = 0;
        int lastpid = 0;
        int pid;
        int x;
@@ -1174,7 +1174,7 @@
            if (buf[x - 1] == '\n')
                buf[x - 1] = '\0';
            else {
-               warnx("%s: %d: line truncated at %u", fname, lineno, x);
+               warnx("%s: %u: line truncated at %u", fname, lineno, x);
                oodate = true;
                break;
            }
@@ -1195,7 +1195,7 @@
            /* Delimit the record type. */
            p = buf;
 #ifdef DEBUG_META_MODE
-           DEBUG3(META, "%s: %d: %s\n", fname, lineno, buf);
+           DEBUG3(META, "%s: %u: %s\n", fname, lineno, buf);
 #endif
            strsep(&p, " ");
            if (have_filemon) {
@@ -1263,7 +1263,7 @@
                        continue;
 #ifdef DEBUG_META_MODE
                    if (DEBUG(META))
-                       debug_printf("%s: %d: %d: %c: cwd=%s lcwd=%s ldir=%s\n",
+                       debug_printf("%s: %u: %d: %c: cwd=%s lcwd=%s ldir=%s\n",
                                     fname, lineno,
                                     pid, buf[0], cwd, lcwd, latestdir);
 #endif
@@ -1294,7 +1294,7 @@
 #ifdef DEBUG_META_MODE
                            if (DEBUG(META))
                                debug_printf(
-                                       "%s: %d: %d: cwd=%s lcwd=%s ldir=%s\n",
+                                       "%s: %u: %d: cwd=%s lcwd=%s ldir=%s\n",
                                        fname, lineno,
                                        child, cwd, lcwd, latestdir);
 #endif
@@ -1309,7 +1309,7 @@
                    Global_Set(lcwd_vname, lcwd);
                    Global_Set(ldir_vname, lcwd);
 #ifdef DEBUG_META_MODE
-                   DEBUG4(META, "%s: %d: cwd=%s ldir=%s\n",
+                   DEBUG4(META, "%s: %u: cwd=%s ldir=%s\n",
                           fname, lineno, cwd, lcwd);
 #endif
                    break;
@@ -1462,7 +1462,7 @@
 
                        for (sdp = sdirs; *sdp != NULL && !found; sdp++) {
 #ifdef DEBUG_META_MODE
-                           DEBUG3(META, "%s: %d: looking for: %s\n",
+                           DEBUG3(META, "%s: %u: looking for: %s\n",
                                   fname, lineno, *sdp);
 #endif
                            if (cached_stat(*sdp, &cst) == 0) {
@@ -1472,12 +1472,12 @@
                        }
                        if (found) {
 #ifdef DEBUG_META_MODE
-                           DEBUG3(META, "%s: %d: found: %s\n",
+                           DEBUG3(META, "%s: %u: found: %s\n",
                                   fname, lineno, p);
 #endif
                            if (!S_ISDIR(cst.cst_mode) &&
                                cst.cst_mtime > gn->mtime) {
-                               DEBUG3(META, "%s: %d: file '%s' is newer than the target...\n",
+                               DEBUG3(META, "%s: %u: file '%s' is newer than the target...\n",
                                       fname, lineno, p);
                                oodate = true;
                            } else if (S_ISDIR(cst.cst_mode)) {
@@ -1509,7 +1509,7 @@
                 * meta data file.
                 */
                if (cmdNode == NULL) {
-                   DEBUG2(META, "%s: %d: there were more build commands in the meta data file than there are now...\n",
+                   DEBUG2(META, "%s: %u: there were more build commands in the meta data file than there are now...\n",
                           fname, lineno);
                    oodate = true;
                } else {
@@ -1526,7 +1526,7 @@
                    }
                    if (hasOODATE) {
                        needOODATE = true;
-                       DEBUG2(META, "%s: %d: cannot compare command using .OODATE\n",
+                       DEBUG2(META, "%s: %u: cannot compare command using .OODATE\n",
                               fname, lineno);
                    }
                    (void)Var_Subst(cmd, gn, VARE_UNDEFERR, &cmd);
@@ -1549,7 +1549,7 @@
                            x = n;
                            lineno++;
                            if (buf[x - 1] != '\n') {
-                               warnx("%s: %d: line truncated at %u", fname, lineno, x);
+                               warnx("%s: %u: line truncated at %u", fname, lineno, x);
                                break;
                            }
                            cp = strchr(cp + 1, '\n');
@@ -1561,7 +1561,7 @@
                        !hasOODATE &&
                        !(gn->type & OP_NOMETA_CMP) &&
                        (meta_cmd_cmp(gn, p, cmd, cmp_filter) != 0)) {
-                       DEBUG4(META, "%s: %d: a build command has changed\n%s\nvs\n%s\n",
+                       DEBUG4(META, "%s: %u: a build command has changed\n%s\nvs\n%s\n",
                               fname, lineno, p, cmd);
                        if (!metaIgnoreCMDs)
                            oodate = true;
@@ -1575,13 +1575,13 @@
                 * that weren't in the meta data file.
                 */
                if (!oodate && cmdNode != NULL) {
-                   DEBUG2(META, "%s: %d: there are extra build commands now that weren't in the meta data file\n",
+                   DEBUG2(META, "%s: %u: there are extra build commands now that weren't in the meta data file\n",
                           fname, lineno);
                    oodate = true;
                }
                CHECK_VALID_META(p);
                if (strcmp(p, cwd) != 0) {
-                   DEBUG4(META, "%s: %d: the current working directory has changed from '%s' to '%s'\n",
+                   DEBUG4(META, "%s: %u: the current working directory has changed from '%s' to '%s'\n",
                           fname, lineno, p, curdir);
                    oodate = true;
                }
diff -r bb984c468069 -r da04b1c2a8b8 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Fri Feb 04 23:03:38 2022 +0000
+++ b/usr.bin/make/parse.c      Fri Feb 04 23:22:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.660 2022/01/29 10:19:49 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.661 2022/02/04 23:22:19 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -106,18 +106,18 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.660 2022/01/29 10:19:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.661 2022/02/04 23:22:19 rillig Exp $");
 
 /*
  * A file being read.
  */
 typedef struct IncludedFile {
        FStr name;              /* absolute or relative to the cwd */
-       int lineno;             /* 1-based */
-       int readLines;          /* the number of physical lines that have
+       unsigned lineno;        /* 1-based */
+       unsigned readLines;     /* the number of physical lines that have
                                 * been read from the file */
-       int forHeadLineno;      /* 1-based */



Home | Main Index | Thread Index | Old Index