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: backport to C90



details:   https://anonhg.NetBSD.org/src/rev/340b27230603
branches:  trunk
changeset: 982172:340b27230603
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 03 14:39:02 2021 +0000

description:
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.

diffstat:

 usr.bin/make/hash.c    |    6 +-
 usr.bin/make/job.c     |   13 ++++-
 usr.bin/make/make.h    |    6 +-
 usr.bin/make/nonints.h |   59 ++++++++++++++++++++++++----
 usr.bin/make/str.c     |   22 ++++++++-
 usr.bin/make/var.c     |  102 +++++++++++++++++++++++++++++++++++-------------
 6 files changed, 157 insertions(+), 51 deletions(-)

diffs (truncated from 455 to 300 lines):

diff -r 24267470c54a -r 340b27230603 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/hash.c       Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
        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;
 }
 
diff -r 24267470c54a -r 340b27230603 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/job.c        Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
 {
        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 @@
 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, &times) >= 0)
                return;
 
diff -r 24267470c54a -r 340b27230603 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/make.h       Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
 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;               \
diff -r 24267470c54a -r 340b27230603 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/nonints.h    Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
        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 @@
 #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 @@
        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,
diff -r 24267470c54a -r 340b27230603 usr.bin/make/str.c
--- a/usr.bin/make/str.c        Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/str.c        Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
                        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 @@
        }
 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;
+       }
 }
 
 /*
diff -r 24267470c54a -r 340b27230603 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Apr 03 14:31:44 2021 +0000
+++ b/usr.bin/make/var.c        Sat Apr 03 14:39:02 2021 +0000
@@ -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 @@
        "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 ModChain {
        Expr *expr;
        /* '\0' or '{' or '(' */



Home | Main Index | Thread Index | Old Index