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.
This commit is contained in:
rillig 2021-02-22 23:21:33 +00:00
parent 4acdc7c93b
commit 49c1680d06
4 changed files with 37 additions and 38 deletions

View File

@ -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 @@ CondParser_StringExpr(CondParser *par, const char *start,
}
/*
* 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 @@ CondParser_StringExpr(CondParser *par, const char *start,
* 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,

View File

@ -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 @@ any_is_submake(GNode *gn)
}
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

View File

@ -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 @@ ParseDoInclude(char *directive)
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);
}
/*

View File

@ -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 @@ Var_Append(GNode *scope, const char *name, const char *val)
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);
Var_Append(scope, xname.str, val);
free(name_freeIt);
FStr_Done(&xname);
}
void
@ -4146,11 +4146,11 @@ ParseVarnameLong(
/* 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 @@ FreeEnvVar(void **out_val_freeIt, Var *v, const char *value)
* 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 @@ Var_Parse(const char **pp, GNode *scope, VarEvalFlags eflags, FStr *out_val)
*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) {