Module Name:    src
Committed By:   rillig
Date:           Sun Dec 10 20:03:30 UTC 2023

Modified Files:
        src/usr.bin/make: var.c

Log Message:
make: clean up the check for command line variables

It looked suspicious that to check whether a variable was set via the
command line, the variable value would be needed.  Moving the debug
diagnostic to the calling function resolved this smell.

A variable from the command line scope is never short-lived, so there's
no need to clean up after accessing the variable.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.1079 -r1.1080 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/var.c
diff -u src/usr.bin/make/var.c:1.1079 src/usr.bin/make/var.c:1.1080
--- src/usr.bin/make/var.c:1.1079	Sun Dec 10 19:56:53 2023
+++ src/usr.bin/make/var.c	Sun Dec 10 20:03:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1079 2023/12/10 19:56:53 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1080 2023/12/10 20:03:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1079 2023/12/10 19:56:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1080 2023/12/10 20:03:30 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -917,22 +917,10 @@ Var_UnExport(bool isEnv, const char *arg
  * See 'scope == SCOPE_CMDLINE' in Var_SetWithFlags.
  */
 static bool
-ExistsInCmdline(const char *name, const char *val)
+ExistsInCmdline(const char *name)
 {
-	Var *v;
-
-	v = VarFind(name, SCOPE_CMDLINE, false);
-	if (v == NULL)
-		return false;
-
-	if (v->fromCmd) {
-		DEBUG3(VAR, "%s: %s = %s ignored!\n",
-		    SCOPE_GLOBAL->name, name, val);
-		return true;
-	}
-
-	VarFreeShortLived(v);
-	return false;
+	Var *v = VarFind(name, SCOPE_CMDLINE, false);
+	return v != NULL && v->fromCmd;
 }
 
 /* Set the variable to the value; the name is not expanded. */
@@ -948,8 +936,11 @@ Var_SetWithFlags(GNode *scope, const cha
 		return;
 	}
 
-	if (scope == SCOPE_GLOBAL && ExistsInCmdline(name, val))
+	if (scope == SCOPE_GLOBAL && ExistsInCmdline(name)) {
+		DEBUG3(VAR, "%s: %s = %s ignored!\n",
+		    SCOPE_GLOBAL->name, name, val);
 		return;
+	}
 
 	/*
 	 * Only look for a variable in the given scope since anything set

Reply via email to