Module Name: src
Committed By: rillig
Date: Sat Dec 19 20:47:24 UTC 2020
Modified Files:
src/usr.bin/make: nonints.h var.c
Log Message:
make(1): extract Var_DeleteVar from Var_Delete
To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.735 -r1.736 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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.174 src/usr.bin/make/nonints.h:1.175
--- src/usr.bin/make/nonints.h:1.174 Sat Dec 19 20:16:36 2020
+++ src/usr.bin/make/nonints.h Sat Dec 19 20:47:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.174 2020/12/19 20:16:36 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.175 2020/12/19 20:47:24 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -342,6 +342,7 @@ typedef enum VarExportMode {
VEM_LITERAL
} VarExportMode;
+void Var_DeleteVar(const char *, GNode *);
void Var_Delete(const char *, GNode *);
void Var_Undef(char *);
void Var_Set(const char *, const char *, GNode *);
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.735 src/usr.bin/make/var.c:1.736
--- src/usr.bin/make/var.c:1.735 Sat Dec 19 20:16:36 2020
+++ src/usr.bin/make/var.c Sat Dec 19 20:47:24 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.735 2020/12/19 20:16:36 rillig Exp $ */
+/* $NetBSD: var.c,v 1.736 2020/12/19 20:47:24 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.735 2020/12/19 20:16:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.736 2020/12/19 20:47:24 rillig Exp $");
/* A string that may need to be freed after use. */
typedef struct FStr {
@@ -488,35 +488,47 @@ VarAdd(const char *name, const char *val
DEBUG3(VAR, "%s:%s = %s\n", ctxt->name, name, val);
}
+/*
+ * Remove a variable from a context, freeing all related memory as well.
+ * The variable name is kept as-is, it is not expanded.
+ */
+void
+Var_DeleteVar(const char *varname, GNode *ctxt)
+{
+ HashEntry *he = HashTable_FindEntry(&ctxt->vars, varname);
+ Var *v;
+
+ if (he == NULL) {
+ DEBUG2(VAR, "%s:delete %s (not found)\n", ctxt->name, varname);
+ return;
+ }
+
+ DEBUG2(VAR, "%s:delete %s\n", ctxt->name, varname);
+ v = HashEntry_Get(he);
+ if (v->flags & VAR_EXPORTED)
+ unsetenv(v->name.str);
+ if (strcmp(v->name.str, MAKE_EXPORTED) == 0)
+ var_exportedVars = VAR_EXPORTED_NONE;
+ assert(v->name.freeIt == NULL);
+ HashTable_DeleteEntry(&ctxt->vars, he);
+ Buf_Destroy(&v->val, TRUE);
+ free(v);
+}
+
/* Remove a variable from a context, freeing all related memory as well.
* The variable name is expanded once. */
void
Var_Delete(const char *name, GNode *ctxt)
{
char *name_freeIt = NULL;
- HashEntry *he;
if (strchr(name, '$') != NULL) {
(void)Var_Subst(name, VAR_GLOBAL, VARE_WANTRES, &name_freeIt);
/* TODO: handle errors */
name = name_freeIt;
}
- he = HashTable_FindEntry(&ctxt->vars, name);
- DEBUG3(VAR, "%s:delete %s%s\n",
- ctxt->name, name, he != NULL ? "" : " (not found)");
- free(name_freeIt);
- if (he != NULL) {
- Var *v = HashEntry_Get(he);
- if (v->flags & VAR_EXPORTED)
- unsetenv(v->name.str);
- if (strcmp(v->name.str, MAKE_EXPORTED) == 0)
- var_exportedVars = VAR_EXPORTED_NONE;
- assert(v->name.freeIt == NULL);
- HashTable_DeleteEntry(&ctxt->vars, he);
- Buf_Destroy(&v->val, TRUE);
- free(v);
- }
+ Var_DeleteVar(name, ctxt);
}
void