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: remove freestanding freeIt variables
details: https://anonhg.NetBSD.org/src/rev/cf3c83986eb7
branches: trunk
changeset: 952983:cf3c83986eb7
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Feb 22 23:21:33 2021 +0000
description:
make: remove freestanding freeIt variables
These variables all belong to a string variable. Connect them using
FStr, which reduces the number of variables to keep track of.
No functional change.
diffstat:
usr.bin/make/cond.c | 7 +++----
usr.bin/make/meta.c | 18 ++++++++++--------
usr.bin/make/parse.c | 19 +++++++++----------
usr.bin/make/var.c | 33 ++++++++++++++++-----------------
4 files changed, 38 insertions(+), 39 deletions(-)
diffs (211 lines):
diff -r 6bc62f193273 -r cf3c83986eb7 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Mon Feb 22 22:55:43 2021 +0000
+++ b/usr.bin/make/cond.c Mon Feb 22 23:21:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.256 2021/02/05 05:15:12 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.257 2021/02/22 23:21:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.256 2021/02/05 05:15:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.257 2021/02/22 23:21:33 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -440,7 +440,7 @@
}
/*
* XXX: Can there be any situation in which a returned
- * var_Error requires freeIt?
+ * var_Error needs to be freed?
*/
FStr_Done(inout_str);
/*
@@ -473,7 +473,6 @@
* Results:
* Returns the string, absent any quotes, or NULL on error.
* Sets out_quoted if the string was quoted.
- * Sets out_freeIt.
*/
static void
CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS,
diff -r 6bc62f193273 -r cf3c83986eb7 usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Mon Feb 22 22:55:43 2021 +0000
+++ b/usr.bin/make/meta.c Mon Feb 22 23:21:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.177 2021/02/05 19:19:17 sjg Exp $ */
+/* $NetBSD: meta.c,v 1.178 2021/02/22 23:21:33 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -373,17 +373,19 @@
}
static void
-printCMD(const char *cmd, FILE *fp, GNode *gn)
+printCMD(const char *ucmd, FILE *fp, GNode *gn)
{
- char *cmd_freeIt = NULL;
+ FStr xcmd = FStr_InitRefer(ucmd);
- if (strchr(cmd, '$') != NULL) {
- (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmd_freeIt);
+ if (strchr(ucmd, '$') != NULL) {
+ char *expanded;
+ (void)Var_Subst(ucmd, gn, VARE_WANTRES, &expanded);
/* TODO: handle errors */
- cmd = cmd_freeIt;
+ xcmd = FStr_InitOwn(expanded);
}
- fprintf(fp, "CMD %s\n", cmd);
- free(cmd_freeIt);
+
+ fprintf(fp, "CMD %s\n", xcmd.str);
+ FStr_Done(&xcmd);
}
static void
diff -r 6bc62f193273 -r cf3c83986eb7 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Mon Feb 22 22:55:43 2021 +0000
+++ b/usr.bin/make/parse.c Mon Feb 22 23:21:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.549 2021/02/05 05:46:27 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.550 2021/02/22 23:21:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.549 2021/02/05 05:46:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.550 2021/02/22 23:21:33 rillig Exp $");
/* types and constants */
@@ -2266,25 +2266,24 @@
static void
SetFilenameVars(const char *filename, const char *dirvar, const char *filevar)
{
- const char *slash, *dirname, *basename;
- void *freeIt;
+ const char *slash, *basename;
+ FStr dirname;
slash = strrchr(filename, '/');
if (slash == NULL) {
- dirname = curdir;
+ dirname = FStr_InitRefer(curdir);
basename = filename;
- freeIt = NULL;
} else {
- dirname = freeIt = bmake_strsedup(filename, slash);
+ dirname = FStr_InitOwn(bmake_strsedup(filename, slash));
basename = slash + 1;
}
- Global_SetExpand(dirvar, dirname);
+ Global_SetExpand(dirvar, dirname.str);
Global_SetExpand(filevar, basename);
DEBUG5(PARSE, "%s: ${%s} = `%s' ${%s} = `%s'\n",
- __func__, dirvar, dirname, filevar, basename);
- free(freeIt);
+ __func__, dirvar, dirname.str, filevar, basename);
+ FStr_Done(&dirname);
}
/*
diff -r 6bc62f193273 -r cf3c83986eb7 usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Feb 22 22:55:43 2021 +0000
+++ b/usr.bin/make/var.c Mon Feb 22 23:21:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.837 2021/02/22 22:55:43 rillig Exp $ */
+/* $NetBSD: var.c,v 1.838 2021/02/22 23:21:33 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.837 2021/02/22 22:55:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.838 2021/02/22 23:21:33 rillig Exp $");
typedef enum VarFlags {
VFL_NONE = 0,
@@ -1160,28 +1160,28 @@
void
Var_AppendExpand(GNode *scope, const char *name, const char *val)
{
- char *name_freeIt = NULL;
+ FStr xname = FStr_InitRefer(name);
assert(val != NULL);
if (strchr(name, '$') != NULL) {
- const char *unexpanded_name = name;
- (void)Var_Subst(name, scope, VARE_WANTRES, &name_freeIt);
+ char *expanded;
+ (void)Var_Subst(name, scope, VARE_WANTRES, &expanded);
/* TODO: handle errors */
- name = name_freeIt;
- if (name[0] == '\0') {
+ xname = FStr_InitOwn(expanded);
+ if (expanded[0] == '\0') {
/* TODO: update function name in the debug message */
DEBUG2(VAR, "Var_Append(\"%s\", \"%s\", ...) "
"name expands to empty string - ignored\n",
- unexpanded_name, val);
- free(name_freeIt);
+ name, val);
+ FStr_Done(&xname);
return;
}
}
- Var_Append(scope, name, val);
-
- free(name_freeIt);
+ Var_Append(scope, xname.str, val);
+
+ FStr_Done(&xname);
}
void
@@ -4146,11 +4146,11 @@
/* Free the environment variable now since we own it. */
static void
-FreeEnvVar(void **out_val_freeIt, Var *v, const char *value)
+FreeEnvVar(Var *v, FStr *inout_val)
{
char *varValue = Buf_DoneData(&v->val);
- if (value == varValue)
- *out_val_freeIt = varValue;
+ if (inout_val->str == varValue)
+ inout_val->freeIt = varValue;
else
free(varValue);
@@ -4194,7 +4194,6 @@
* expression into a defined expression.
* XXX: It is not guaranteed that an error message has
* been printed.
- * *out_val_freeIt Must be freed by the caller after using *out_val.
*/
/* coverity[+alloc : arg-*4] */
VarParseResult
@@ -4311,7 +4310,7 @@
*pp = p;
if (v->flags & VFL_FROM_ENV) {
- FreeEnvVar(&expr.value.freeIt, v, expr.value.str);
+ FreeEnvVar(v, &expr.value);
} else if (expr.defined != DEF_REGULAR) {
if (expr.defined == DEF_UNDEF) {
Home |
Main Index |
Thread Index |
Old Index