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): let Var_Value return a const char *
details: https://anonhg.NetBSD.org/src/rev/dd7e6a5880c1
branches: trunk
changeset: 936651:dd7e6a5880c1
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 01 09:25:36 2020 +0000
description:
make(1): let Var_Value return a const char *
The return value must not be modified anyway, so let the compiler check
this for free.
diffstat:
usr.bin/make/compat.c | 10 +++++-----
usr.bin/make/main.c | 13 +++++++------
usr.bin/make/make.c | 12 ++++++------
usr.bin/make/meta.c | 6 +++---
usr.bin/make/nonints.h | 4 ++--
usr.bin/make/parse.c | 30 +++++++++++++-----------------
usr.bin/make/trace.c | 8 ++++----
usr.bin/make/var.c | 8 ++++----
8 files changed, 44 insertions(+), 47 deletions(-)
diffs (truncated from 339 to 300 lines):
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/compat.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.115 2020/07/28 16:42:22 rillig Exp $ */
+/* $NetBSD: compat.c,v 1.116 2020/08/01 09:25:36 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.115 2020/07/28 16:42:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.116 2020/08/01 09:25:36 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: compat.c,v 1.115 2020/07/28 16:42:22 rillig Exp $");
+__RCSID("$NetBSD: compat.c,v 1.116 2020/08/01 09:25:36 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -126,8 +126,8 @@
CompatDeleteTarget(GNode *gn)
{
if ((gn != NULL) && !Targ_Precious (gn)) {
- char *p1;
- char *file = Var_Value(TARGET, gn, &p1);
+ char *p1;
+ const char *file = Var_Value(TARGET, gn, &p1);
if (!noExecute && eunlink(file) != -1) {
Error("*** %s removed", file);
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/main.c
--- a/usr.bin/make/main.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/main.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $ */
+/* $NetBSD: main.c,v 1.289 2020/08/01 09:25:36 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.289 2020/08/01 09:25:36 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.288 2020/08/01 09:08:17 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.289 2020/08/01 09:25:36 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -695,7 +695,7 @@
int argc; /* Number of arguments in argv */
char *args; /* Space used by the args */
char *p1;
- char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
+ const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
if (line == NULL)
return;
@@ -870,7 +870,7 @@
for (ln = Lst_First(variables); ln != NULL;
ln = Lst_Succ(ln)) {
char *var = (char *)Lst_Datum(ln);
- char *value;
+ const char *value;
char *p1;
if (strchr(var, '$')) {
@@ -1975,7 +1975,8 @@
cached_realpath(const char *pathname, char *resolved)
{
GNode *cache;
- char *rp, *cp;
+ const char *rp;
+ char *cp;
if (!pathname || !pathname[0])
return NULL;
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/make.c
--- a/usr.bin/make/make.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/make.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.101 2020/07/28 16:42:22 rillig Exp $ */
+/* $NetBSD: make.c,v 1.102 2020/08/01 09:25:36 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.101 2020/07/28 16:42:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.102 2020/08/01 09:25:36 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: make.c,v 1.101 2020/07/28 16:42:22 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.102 2020/08/01 09:25:36 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -680,7 +680,7 @@
Make_Update(GNode *cgn)
{
GNode *pgn; /* the parent node */
- char *cname; /* the child's name */
+ const char *cname; /* the child's name */
LstNode ln; /* Element in parents and iParents lists */
time_t mtime = -1;
char *p1;
@@ -826,7 +826,7 @@
* of this node.
*/
if (Lst_Open(cgn->iParents) == SUCCESS) {
- char *cpref = Var_Value(PREFIX, cgn, &p1);
+ const char *cpref = Var_Value(PREFIX, cgn, &p1);
while ((ln = Lst_Next(cgn->iParents)) != NULL) {
pgn = (GNode *)Lst_Datum(ln);
@@ -890,7 +890,7 @@
cgn->type |= OP_MARK;
if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) {
- char *child, *allsrc;
+ const char *child, *allsrc;
char *p1 = NULL, *p2 = NULL;
if (cgn->type & OP_ARCHV)
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/meta.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.89 2020/07/28 16:42:22 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.90 2020/08/01 09:25:36 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -314,7 +314,7 @@
static int
is_submake(void *cmdp, void *gnp)
{
- static char *p_make = NULL;
+ static const char *p_make = NULL;
static int p_len;
char *cmd = cmdp;
GNode *gn = gnp;
@@ -1232,7 +1232,7 @@
CHECK_VALID_META(p);
pid = atoi(p);
if (pid > 0 && pid != lastpid) {
- char *ldir;
+ const char *ldir;
char *tp;
if (lastpid > 0) {
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/nonints.h Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.87 2020/07/28 16:42:22 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.88 2020/08/01 09:25:36 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -190,7 +190,7 @@
void Var_Set(const char *, const char *, GNode *);
void Var_Append(const char *, const char *, GNode *);
Boolean Var_Exists(const char *, GNode *);
-char *Var_Value(const char *, GNode *, char **);
+const char *Var_Value(const char *, GNode *, char **);
const char *Var_Parse(const char *, GNode *, VarEvalFlags, int *, void **);
char *Var_Subst(const char *, GNode *, VarEvalFlags);
char *Var_GetTail(const char *);
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/parse.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.243 2020/07/31 20:22:10 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.244 2020/08/01 09:25:36 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.243 2020/07/31 20:22:10 sjg Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.244 2020/08/01 09:25:36 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: parse.c,v 1.243 2020/07/31 20:22:10 sjg Exp $");
+__RCSID("$NetBSD: parse.c,v 1.244 2020/08/01 09:25:36 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -2364,20 +2364,20 @@
static void
ParseSetIncludedFile(void)
{
- char *pf, *fp = NULL;
- char *pd, *dp = NULL;
+ char *pf_freeIt;
+ char *pd_freeIt;
- pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &fp);
+ const char *pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &pf_freeIt);
Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL);
- pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &dp);
+ const char *pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &pd_freeIt);
Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL);
if (DEBUG(PARSE))
fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
"${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
- free(fp);
- free(dp);
+ free(pf_freeIt);
+ free(pd_freeIt);
}
/*-
*---------------------------------------------------------------------
@@ -2428,14 +2428,12 @@
static void
ParseTrackInput(const char *name)
{
- char *old;
- char *ep;
char *fp = NULL;
- size_t name_len = strlen(name);
- old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
+ const char *old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
if (old) {
- ep = old + strlen(old) - name_len;
+ size_t name_len = strlen(name);
+ const char *ep = old + strlen(old) - name_len;
/* does it contain name? */
for (; old != NULL; old = strchr(old, ' ')) {
if (*old == ' ')
@@ -2449,9 +2447,7 @@
}
Var_Append (MAKE_MAKEFILES, name, VAR_GLOBAL);
cleanup:
- if (fp) {
- free(fp);
- }
+ free(fp);
}
diff -r 405e649d51bf -r dd7e6a5880c1 usr.bin/make/trace.c
--- a/usr.bin/make/trace.c Sat Aug 01 09:08:17 2020 +0000
+++ b/usr.bin/make/trace.c Sat Aug 01 09:25:36 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $ */
+/* $NetBSD: trace.c,v 1.13 2020/08/01 09:25:36 rillig Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,11 +31,11 @@
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: trace.c,v 1.13 2020/08/01 09:25:36 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: trace.c,v 1.12 2020/07/03 08:13:23 rillig Exp $");
+__RCSID("$NetBSD: trace.c,v 1.13 2020/08/01 09:25:36 rillig Exp $");
#endif /* not lint */
#endif
@@ -63,7 +63,7 @@
static FILE *trfile;
static pid_t trpid;
-char *trwd;
Home |
Main Index |
Thread Index |
Old Index