Module Name: src Committed By: rillig Date: Fri Feb 4 23:22:19 UTC 2022
Modified Files: src/usr.bin/make: dir.c for.c job.c make.h meta.c parse.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.277 -r1.278 src/usr.bin/make/dir.c cvs rdiff -u -r1.166 -r1.167 src/usr.bin/make/for.c cvs rdiff -u -r1.450 -r1.451 src/usr.bin/make/job.c cvs rdiff -u -r1.296 -r1.297 src/usr.bin/make/make.h cvs rdiff -u -r1.195 -r1.196 src/usr.bin/make/meta.c cvs rdiff -u -r1.660 -r1.661 src/usr.bin/make/parse.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/dir.c diff -u src/usr.bin/make/dir.c:1.277 src/usr.bin/make/dir.c:1.278 --- src/usr.bin/make/dir.c:1.277 Sun Jan 30 13:21:08 2022 +++ src/usr.bin/make/dir.c Fri Feb 4 23:22:19 2022 @@ -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 @@ ResolveMovedDepends(GNode *gn) 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); Index: src/usr.bin/make/for.c diff -u src/usr.bin/make/for.c:1.166 src/usr.bin/make/for.c:1.167 --- src/usr.bin/make/for.c:1.166 Thu Jan 27 11:16:44 2022 +++ src/usr.bin/make/for.c Fri Feb 4 23:22:19 2022 @@ -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 @@ For_NextIteration(ForLoop *f, Buffer *bo /* 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; Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.450 src/usr.bin/make/job.c:1.451 --- src/usr.bin/make/job.c:1.450 Sun Jan 30 13:21:08 2022 +++ src/usr.bin/make/job.c Fri Feb 4 23:22:19 2022 @@ -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 @@ Job_CheckCommands(GNode *gn, void (*abor 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; Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.296 src/usr.bin/make/make.h:1.297 --- src/usr.bin/make/make.h:1.296 Mon Jan 31 20:49:27 2022 +++ src/usr.bin/make/make.h Fri Feb 4 23:22:19 2022 @@ -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 @@ typedef struct GNode { /* 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 @@ void SearchPath_Free(SearchPath *); 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 @@ bool GetBooleanExpr(const char *, bool); 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; Index: src/usr.bin/make/meta.c diff -u src/usr.bin/make/meta.c:1.195 src/usr.bin/make/meta.c:1.196 --- src/usr.bin/make/meta.c:1.195 Thu Jan 27 06:02:59 2022 +++ src/usr.bin/make/meta.c Fri Feb 4 23:22:19 2022 @@ -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 @@ meta_ignore(GNode *gn, const char *p) * 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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) /* 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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) #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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) } 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_oodate(GNode *gn, bool oodate) * 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 @@ meta_oodate(GNode *gn, bool oodate) } 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 @@ meta_oodate(GNode *gn, bool oodate) 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 @@ meta_oodate(GNode *gn, bool oodate) !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 @@ meta_oodate(GNode *gn, bool oodate) * 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; } Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.660 src/usr.bin/make/parse.c:1.661 --- src/usr.bin/make/parse.c:1.660 Sat Jan 29 10:19:49 2022 +++ src/usr.bin/make/parse.c Fri Feb 4 23:22:19 2022 @@ -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 */ - int forBodyReadLines; /* the number of physical lines that have + unsigned forHeadLineno; /* 1-based */ + unsigned forBodyReadLines; /* the number of physical lines that have * been read from the file above the body of * the .for loop */ unsigned int cond_depth; /* 'if' nesting when file opened */ @@ -378,13 +378,13 @@ PrintStackTrace(bool includingInnermost) if (entry->forLoop != NULL) { char *details = ForLoop_Details(entry->forLoop); - debug_printf("\tin .for loop from %s:%d with %s\n", + debug_printf("\tin .for loop from %s:%u with %s\n", fname, entry->forHeadLineno, details); free(details); } else if (i + 1 < n && entries[i + 1].forLoop != NULL) { /* entry->lineno is not a useful line number */ } else - debug_printf("\tin %s:%d\n", fname, entry->lineno); + debug_printf("\tin %s:%u\n", fname, entry->lineno); } } @@ -436,13 +436,13 @@ FindKeyword(const char *str) } void -PrintLocation(FILE *f, bool useVars, const char *fname, size_t lineno) +PrintLocation(FILE *f, bool useVars, const char *fname, unsigned lineno) { char dirbuf[MAXPATHLEN + 1]; FStr dir, base; if (!useVars || fname[0] == '/' || strcmp(fname, "(stdin)") == 0) { - (void)fprintf(f, "\"%s\" line %u: ", fname, (unsigned)lineno); + (void)fprintf(f, "\"%s\" line %u: ", fname, lineno); return; } @@ -456,15 +456,14 @@ PrintLocation(FILE *f, bool useVars, con if (base.str == NULL) base.str = str_basename(fname); - (void)fprintf(f, "\"%s/%s\" line %u: ", - dir.str, base.str, (unsigned)lineno); + (void)fprintf(f, "\"%s/%s\" line %u: ", dir.str, base.str, lineno); FStr_Done(&base); FStr_Done(&dir); } static void MAKE_ATTR_PRINTFLIKE(6, 0) -ParseVErrorInternal(FILE *f, bool useVars, const char *fname, size_t lineno, +ParseVErrorInternal(FILE *f, bool useVars, const char *fname, unsigned lineno, ParseErrorLevel type, const char *fmt, va_list ap) { static bool fatal_warning_error_printed = false; @@ -494,7 +493,7 @@ ParseVErrorInternal(FILE *f, bool useVar } static void MAKE_ATTR_PRINTFLIKE(4, 5) -ParseErrorInternal(const char *fname, size_t lineno, +ParseErrorInternal(const char *fname, unsigned lineno, ParseErrorLevel type, const char *fmt, ...) { va_list ap; @@ -525,7 +524,7 @@ Parse_Error(ParseErrorLevel type, const { va_list ap; const char *fname; - size_t lineno; + unsigned lineno; if (includes.len == 0) { fname = NULL; @@ -533,7 +532,7 @@ Parse_Error(ParseErrorLevel type, const } else { IncludedFile *curFile = CurFile(); fname = curFile->name.str; - lineno = (size_t)curFile->lineno; + lineno = curFile->lineno; } (void)fflush(stdout); @@ -1802,13 +1801,13 @@ GNode_AddCommand(GNode *gn, char *cmd) Lst_Append(&gn->commands, cmd); Parse_Error(PARSE_WARNING, "overriding commands for target \"%s\"; " - "previous commands defined at %s: %d ignored", + "previous commands defined at %s: %u ignored", gn->name, gn->fname, gn->lineno); #else Parse_Error(PARSE_WARNING, "duplicate script for target \"%s\" ignored", gn->name); - ParseErrorInternal(gn->fname, (size_t)gn->lineno, PARSE_WARNING, + ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING, "using previous script for \"%s\" defined here", gn->name); #endif @@ -2104,8 +2103,8 @@ TrackInput(const char *name) /* Parse from the given buffer, later return to the current file. */ void -Parse_PushInput(const char *name, int lineno, int readLines, Buffer buf, - struct ForLoop *forLoop) +Parse_PushInput(const char *name, unsigned lineno, unsigned readLines, + Buffer buf, struct ForLoop *forLoop) { IncludedFile *curFile; @@ -2114,7 +2113,7 @@ Parse_PushInput(const char *name, int li else TrackInput(name); - DEBUG3(PARSE, "Parse_PushInput: %s %s, line %d\n", + DEBUG3(PARSE, "Parse_PushInput: %s %s, line %u\n", forLoop != NULL ? ".for loop in": "file", name, lineno); curFile = Vector_Push(&includes); @@ -2287,7 +2286,7 @@ ParseEOF(void) } curFile = CurFile(); - DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n", + DEBUG2(PARSE, "ParseEOF: returning to file %s, line %u\n", curFile->name.str, curFile->readLines + 1); SetParseFile(curFile->name.str); @@ -2529,8 +2528,8 @@ static bool ParseForLoop(const char *line) { int rval; - int forHeadLineno; - int bodyReadLines; + unsigned forHeadLineno; + unsigned bodyReadLines; int forLevel; rval = For_Eval(line); @@ -2877,7 +2876,7 @@ Parse_File(const char *name, int fd) do { while ((line = ReadHighLevelLine()) != NULL) { - DEBUG2(PARSE, "Parsing line %d: %s\n", + DEBUG2(PARSE, "Parsing line %u: %s\n", CurFile()->lineno, line); ParseLine(line); }