Module Name: src Committed By: rillig Date: Sat Apr 3 14:39:02 UTC 2021
Modified Files: src/usr.bin/make: hash.c job.c make.h nonints.h str.c var.c Log Message: make: backport to C90 In the past few months I had accidentally used C99 features in the make code. According to tools/README, tools that are used in the build system should restrict themselves to C90. This allows make to build with GCC's options "-pedantic -Wno-system-headers -Dinline= -Wno-error=cast-qual". I didn't notice anyone actively complaining though, I just wanted to see how much work this backporting would be. The identifier __func__ is still used, as in other tools. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 src/usr.bin/make/hash.c cvs rdiff -u -r1.421 -r1.422 src/usr.bin/make/job.c cvs rdiff -u -r1.257 -r1.258 src/usr.bin/make/make.h cvs rdiff -u -r1.207 -r1.208 src/usr.bin/make/nonints.h cvs rdiff -u -r1.82 -r1.83 src/usr.bin/make/str.c cvs rdiff -u -r1.896 -r1.897 src/usr.bin/make/var.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/hash.c diff -u src/usr.bin/make/hash.c:1.62 src/usr.bin/make/hash.c:1.63 --- src/usr.bin/make/hash.c:1.62 Sat Apr 3 11:08:40 2021 +++ src/usr.bin/make/hash.c Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.62 2021/04/03 11:08:40 rillig Exp $ */ +/* $NetBSD: hash.c,v 1.63 2021/04/03 14:39:02 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.62 2021/04/03 11:08:40 rillig Exp $"); +MAKE_RCSID("$NetBSD: hash.c,v 1.63 2021/04/03 14:39:02 rillig Exp $"); /* * The ratio of # entries to # buckets at which we rebuild the table to @@ -227,7 +227,7 @@ HashTable_Enlarge(HashTable *t) t->bucketsMask = newMask; t->buckets = newBuckets; DEBUG5(HASH, "%s: %p size=%d entries=%d maxchain=%d\n", - __func__, t, t->bucketsSize, t->numEntries, t->maxchain); + __func__, (void *)t, t->bucketsSize, t->numEntries, t->maxchain); t->maxchain = 0; } Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.421 src/usr.bin/make/job.c:1.422 --- src/usr.bin/make/job.c:1.421 Sat Apr 3 11:08:40 2021 +++ src/usr.bin/make/job.c Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.421 2021/04/03 11:08:40 rillig Exp $ */ +/* $NetBSD: job.c,v 1.422 2021/04/03 14:39:02 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.421 2021/04/03 11:08:40 rillig Exp $"); +MAKE_RCSID("$NetBSD: job.c,v 1.422 2021/04/03 14:39:02 rillig Exp $"); /* * A shell defines how the commands are run. All commands for a target are @@ -1000,7 +1000,10 @@ JobPrintCommands(Job *job) { StringListNode *ln; bool seen = false; - ShellWriter wr = { job->cmdFILE, false }; + ShellWriter wr; + + wr.f = job->cmdFILE; + wr.xtraced = false; for (ln = job->node->commands.first; ln != NULL; ln = ln->next) { const char *cmd = ln->datum; @@ -1216,10 +1219,12 @@ static void TouchRegular(GNode *gn) { const char *file = GNode_Path(gn); - struct utimbuf times = { now, now }; + struct utimbuf times; int fd; char c; + times.actime = now; + times.modtime = now; if (utime(file, ×) >= 0) return; Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.257 src/usr.bin/make/make.h:1.258 --- src/usr.bin/make/make.h:1.257 Sat Apr 3 11:08:40 2021 +++ src/usr.bin/make/make.h Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.257 2021/04/03 11:08:40 rillig Exp $ */ +/* $NetBSD: make.h,v 1.258 2021/04/03 14:39:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -101,7 +101,7 @@ #define FD_CLOEXEC 1 #endif -#if defined(__GNUC__) +#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L #define MAKE_GNUC_PREREQ(x, y) \ ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ (__GNUC__ > (x))) @@ -738,7 +738,7 @@ GNode_VarArchive(GNode *gn) { return GNo MAKE_INLINE const char * GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); } -#ifdef __GNUC__ +#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L #define UNCONST(ptr) ({ \ union __unconst { \ const void *__cp; \ Index: src/usr.bin/make/nonints.h diff -u src/usr.bin/make/nonints.h:1.207 src/usr.bin/make/nonints.h:1.208 --- src/usr.bin/make/nonints.h:1.207 Sat Apr 3 11:08:40 2021 +++ src/usr.bin/make/nonints.h Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.207 2021/04/03 11:08:40 rillig Exp $ */ +/* $NetBSD: nonints.h,v 1.208 2021/04/03 14:39:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -186,18 +186,31 @@ typedef struct Words { void *freeIt; } Words; +#if __STDC_VERSION__ >= 199901L +# define FStr_Literal(str, freeIt) (FStr) { str, freeIt } +#else +MAKE_INLINE FStr +FStr_Literal(const char *str, void *freeIt) +{ + FStr fstr; + fstr.str = str; + fstr.freeIt = freeIt; + return fstr; +} +#endif + /* Return a string that is the sole owner of str. */ MAKE_INLINE FStr FStr_InitOwn(char *str) { - return (FStr){ str, str }; + return FStr_Literal(str, str); } /* Return a string that refers to the shared str. */ MAKE_INLINE FStr FStr_InitRefer(const char *str) { - return (FStr){ str, NULL }; + return FStr_Literal(str, NULL); } MAKE_INLINE void @@ -210,18 +223,31 @@ FStr_Done(FStr *fstr) #endif } +#if __STDC_VERSION__ >= 199901L +# define MFStr_Literal(str, freeIt) (MFStr) { str, freeIt } +#else +MAKE_INLINE MFStr +MFStr_Literal(char *str, void *freeIt) +{ + MFStr mfstr; + mfstr.str = str; + mfstr.freeIt = freeIt; + return mfstr; +} +#endif + /* Return a string that is the sole owner of str. */ MAKE_INLINE MFStr MFStr_InitOwn(char *str) { - return (MFStr){ str, str }; + return MFStr_Literal(str, str); } /* Return a string that refers to the shared str. */ MAKE_INLINE MFStr MFStr_InitRefer(char *str) { - return (MFStr){ str, NULL }; + return MFStr_Literal(str, NULL); } MAKE_INLINE void @@ -344,10 +370,25 @@ typedef struct VarEvalFlags { bool : 0; } VarEvalFlags; -#define VARE_PARSE_ONLY (VarEvalFlags) { false, false, false, false } -#define VARE_WANTRES (VarEvalFlags) { true, false, false, false } -#define VARE_UNDEFERR (VarEvalFlags) { true, true, false, false } -#define VARE_KEEP_DOLLAR_UNDEF (VarEvalFlags) { true, false, true, true } +#if __STDC_VERSION__ >= 199901L +#define VarEvalFlagsLiteral(wantRes, undefErr, keep) \ + (VarEvalFlags) { wantRes, undefErr, keep, keep } +#else +MAKE_INLINE VarEvalFlags +VarEvalFlagsLiteral(bool wantRes, bool undefErr, bool keep) +{ + VarEvalFlags eflags; + eflags.wantRes = wantRes; + eflags.undefErr = undefErr; + eflags.keepDollar = keep; + eflags.keepUndef = keep; + return eflags; +} +#endif +#define VARE_PARSE_ONLY VarEvalFlagsLiteral(false, false, false) +#define VARE_WANTRES VarEvalFlagsLiteral(true, false, false) +#define VARE_UNDEFERR VarEvalFlagsLiteral(true, true, false) +#define VARE_KEEP_DOLLAR_UNDEF VarEvalFlagsLiteral(true, false, true) typedef enum VarSetFlags { VAR_SET_NONE = 0, Index: src/usr.bin/make/str.c diff -u src/usr.bin/make/str.c:1.82 src/usr.bin/make/str.c:1.83 --- src/usr.bin/make/str.c:1.82 Sat Apr 3 11:08:40 2021 +++ src/usr.bin/make/str.c Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.82 2021/04/03 11:08:40 rillig Exp $ */ +/* $NetBSD: str.c,v 1.83 2021/04/03 14:39:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -71,7 +71,7 @@ #include "make.h" /* "@(#)str.c 5.8 (Berkeley) 6/1/90" */ -MAKE_RCSID("$NetBSD: str.c,v 1.82 2021/04/03 11:08:40 rillig Exp $"); +MAKE_RCSID("$NetBSD: str.c,v 1.83 2021/04/03 14:39:02 rillig Exp $"); /* Return the concatenation of s1 and s2, freshly allocated. */ char * @@ -213,9 +213,15 @@ Str_Words(const char *str, bool expand) word_start = NULL; if (ch == '\n' || ch == '\0') { if (expand && inquote != '\0') { + Words res; + free(words); free(words_buf); - return (Words){ NULL, 0, NULL }; + + res.words = NULL; + res.len = 0; + res.freeIt = NULL; + return res; } goto done; } @@ -263,7 +269,15 @@ Str_Words(const char *str, bool expand) } done: words[words_len] = NULL; /* useful for argv */ - return (Words){ words, words_len, words_buf }; + + { + Words result; + + result.words = words; + result.len = words_len; + result.freeIt = words_buf; + return result; + } } /* Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.896 src/usr.bin/make/var.c:1.897 --- src/usr.bin/make/var.c:1.896 Sat Apr 3 14:31:44 2021 +++ src/usr.bin/make/var.c Sat Apr 3 14:39:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.896 2021/04/03 14:31:44 rillig Exp $ */ +/* $NetBSD: var.c,v 1.897 2021/04/03 14:39:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -140,7 +140,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.896 2021/04/03 14:31:44 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.897 2021/04/03 14:39:02 rillig Exp $"); typedef enum VarFlags { VFL_NONE = 0, @@ -2049,12 +2049,18 @@ static const char *const ExprDefined_Nam "defined" }; +#if __STDC_VERSION__ >= 199901L +#define const_member const +#else +#define const_member /* no const possible */ +#endif + /* A variable expression such as $@ or ${VAR:Mpattern:Q}. */ typedef struct Expr { Var *var; FStr value; - VarEvalFlags const eflags; - GNode *const scope; + VarEvalFlags const_member eflags; + GNode *const_member scope; ExprDefined defined; } Expr; @@ -2087,9 +2093,9 @@ typedef struct Expr { typedef struct ModChain { Expr *expr; /* '\0' or '{' or '(' */ - const char startc; + char const_member startc; /* '\0' or '}' or ')' */ - const char endc; + char const_member endc; /* Word separator in expansions (see the :ts modifier). */ char sep; /* @@ -2866,6 +2872,17 @@ ParsePatternFlags(const char **pp, VarPa } } +#if __STDC_VERSION__ >= 199901L +#define VarPatternFlags_Literal() (VarPatternFlags) { false, false, false, false } +#else +MAKE_INLINE VarPatternFlags +VarPatternFlags_Literal(void) +{ + VarPatternFlags pflags = { false, false, false, false }; + return pflags; +} +#endif + /* :S,from,to, */ static ApplyModifierResult ApplyModifier_Subst(const char **pp, ModChain *ch) @@ -2884,7 +2901,7 @@ ApplyModifier_Subst(const char **pp, Mod *pp += 2; - args.pflags = (VarPatternFlags){ false, false, false, false }; + args.pflags = VarPatternFlags_Literal(); args.matched = false; if (**pp == '^') { @@ -2945,7 +2962,7 @@ ApplyModifier_Regex(const char **pp, Mod return AMR_CLEANUP; } - args.pflags = (VarPatternFlags){ false, false, false, false }; + args.pflags = VarPatternFlags_Literal(); args.matched = false; oneBigWord = ch->oneBigWord; ParsePatternFlags(pp, &args.pflags, &oneBigWord); @@ -3582,9 +3599,11 @@ ApplyModifier_SysV(const char **pp, ModC if (lhs[0] == '\0' && expr->value.str[0] == '\0') { /* Do not turn an empty expression into non-empty. */ } else { - struct ModifyWord_SYSVSubstArgs args = { - expr->scope, lhs, rhs - }; + struct ModifyWord_SYSVSubstArgs args; + + args.scope = expr->scope; + args.lhs = lhs; + args.rhs = rhs; ModifyWords(ch, ModifyWord_SYSVSubst, &args, ch->oneBigWord); } free(lhs); @@ -3845,6 +3864,23 @@ ApplySingleModifier(const char **pp, Mod return AMR_OK; } +#if __STDC_VERSION__ >= 199901L +#define ModChain_Literal(expr, startc, endc, sep, oneBigWord) \ + (ModChain) { expr, startc, endc, sep, oneBigWord } +#else +MAKE_INLINE ModChain +ModChain_Literal(Expr *expr, char startc, char endc, char sep, bool oneBigWord) +{ + ModChain ch; + ch.expr = expr; + ch.startc = startc; + ch.endc = endc; + ch.sep = sep; + ch.oneBigWord = oneBigWord; + return ch; +} +#endif + /* Apply any modifiers (such as :Mpattern or :@var@loop@ or :Q or ::=value). */ static void ApplyModifiers( @@ -3854,13 +3890,7 @@ ApplyModifiers( char endc /* ')' or '}'; or '\0' for indirect modifiers */ ) { - ModChain ch = { - expr, - startc, - endc, - ' ', /* .sep */ - false /* .oneBigWord */ - }; + ModChain ch = ModChain_Literal(expr, startc, endc, ' ', false); const char *p; const char *mod; @@ -4121,8 +4151,12 @@ FindLocalLegacyVar(const char *varname, return NULL; { - char name[] = { varname[0], '\0' }; - Var *v = VarFind(name, scope, false); + char name[2]; + Var *v; + + name[0] = varname[0]; + name[1] = '\0'; + v = VarFind(name, scope, false); if (v != NULL) { if (varname[1] == 'D') { @@ -4283,6 +4317,25 @@ FreeEnvVar(Var *v, FStr *inout_val) free(v); } +#if __STDC_VERSION__ >= 199901L +#define Expr_Literal(var, value, eflags, scope, defined) \ + { var, value, eflags, scope, defined } +#else +MAKE_INLINE Expr +Expr_Literal(Var *var, FStr value, VarEvalFlags eflags, GNode *scope, + ExprDefined defined) +{ + Expr expr; + + expr.var = var; + expr.value = value; + expr.eflags = eflags; + expr.scope = scope; + expr.defined = defined; + return expr; +} +#endif + /* * Given the start of a variable expression (such as $v, $(VAR), * ${VAR:Mpattern}), extract the variable name and value, and the modifiers, @@ -4339,14 +4392,7 @@ Var_Parse(const char **pp, GNode *scope, bool dynamic; const char *extramodifiers; Var *v; - - Expr expr = { - NULL, - FStr_InitRefer(NULL), - eflags, - scope, - DEF_REGULAR - }; + Expr expr = Expr_Literal(NULL, FStr_InitRefer(NULL), eflags, scope, DEF_REGULAR); DEBUG2(VAR, "Var_Parse: %s (%s)\n", start, VarEvalFlags_ToString(eflags));