CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec 21 02:38:57 UTC 2020

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

Log Message:
make(1): remove redundant parameters from ParseModifierPart


To generate a diff of this commit:
cvs rdiff -u -r1.759 -r1.760 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.759 src/usr.bin/make/var.c:1.760
--- src/usr.bin/make/var.c:1.759	Mon Dec 21 00:30:13 2020
+++ src/usr.bin/make/var.c	Mon Dec 21 02:38:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.759 2020/12/21 00:30:13 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.760 2020/12/21 02:38:57 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.759 2020/12/21 00:30:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.760 2020/12/21 02:38:57 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1975,25 +1975,11 @@ IsEscapedModifierPart(const char *p, cha
 	return p[1] == '&' && subst != NULL;
 }
 
-/*
- * Parse a part of a modifier such as the "from" and "to" in :S/from/to/ or
- * the "var" or "replacement ${var}" in :@var@replacement ${var}@, up to and
- * including the next unescaped delimiter.  The delimiter, as well as the
- * backslash or the dollar, can be escaped with a backslash.
- *
- * Return the parsed (and possibly expanded) string, or NULL if no delimiter
- * was found.  On successful return, the parsing position pp points right
- * after the delimiter.  The delimiter is not included in the returned
- * value though.
- */
+/* See ParseModifierPart */
 static VarParseResult
-ParseModifierPart(
-/* The parsing position, updated upon return */
+ParseModifierPartSubst(
 const char **pp,
-/* Parsing stops at this delimiter */
 char delim,
-/* Flags for evaluating nested variables; if VARE_WANTRES is not set,
- * the text is only parsed. */
 VarEvalFlags eflags,
 ApplyModifiersState *st,
 char **out_part,
@@ -2116,6 +2102,34 @@ ParseModifierPart(
 	return VPR_OK;
 }
 
+/*
+ * Parse a part of a modifier such as the "from" and "to" in :S/from/to/ or
+ * the "var" or "replacement ${var}" in :@var@replacement ${var}@, up to and
+ * including the next unescaped delimiter.  The delimiter, as well as the
+ * backslash or the dollar, can be escaped with a backslash.
+ *
+ * Return the parsed (and possibly expanded) string, or NULL if no delimiter
+ * was found.  On successful return, the parsing position pp points right
+ * after the delimiter.  The delimiter is not included in the returned
+ * value though.
+ */
+static VarParseResult
+ParseModifierPart(
+/* The parsing position, updated upon return */
+const char **pp,
+/* Parsing stops at this delimiter */
+char delim,
+/* Flags for evaluating nested variables; if VARE_WANTRES is not set,
+ * the text is only parsed. */
+VarEvalFlags eflags,
+ApplyModifiersState *st,
+char **out_part
+)
+{
+	return ParseModifierPartSubst(pp, delim, eflags, st, out_part,
+	NULL, NULL, NULL);
+}
+
 /* Test whether mod starts with modname, followed by a delimiter. */
 MAKE_INLINE Boolean
 ModMatch(const char *mod, const char *modname, char endc)
@@ -2205,8 +2219,7 @@ ApplyModifier_Loop(const char **pp, cons
 	args.ctx = st->ctxt;
 
 	(*pp)++;		/* Skip the first '@' */
-	res = ParseModifierPart(pp, '@', VARE_NONE, st,
-	, NULL, NULL, NULL);
+	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	if (opts.lint && strchr(args.tvar, '$') != NULL) {
@@ -2217,8 +2230,7 @@ ApplyModifier_Loop(const char **pp, cons
 		return AMR_CLEANUP;
 	}
 
-	res = ParseModifierPart(pp, '@', VARE_NONE, st,
-	, NULL, NULL, NULL);
+	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
@@ -2423,8 +2435,7 @@ ApplyModifier_ShellCommand(const char **
 	VarParseResult res;
 
 	(*pp)++;
-	res = ParseModifierPart(pp, '!', st->eflags, st,
-	, NULL, NULL, NULL);
+	res = ParseModifierPart(pp, '!', st->eflags, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
@@ -2596,14 +2607,14 @@ ApplyModifier_Subst(const char **pp, con
 		(*pp)++;
 	}
 
-	res = ParseModifierPart(pp, delim, st->eflags, st,
-	, , , NULL);
+	res = ParseModifierPartSubst(pp, delim, st->eflags, st, ,
+	, , NULL);
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	args.lhs = lhs;
 
-	res = ParseModifierPart(pp, delim, st->eflags, st,
-	, , NULL, );
+	res = ParseModifierPartSubst(pp, delim, st->eflags, st, ,
+	, NULL, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	args.rhs = rhs;
@@ -2653,13 +2664,11 @@ ApplyModifier_Regex(const char **pp, con
 
 	*pp += 2;
 
-	res = ParseModifierPart(pp, delim, st->eflags, st,
-	, NULL, NULL, NULL);
+	res = 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec 21 02:09:34 UTC 2020

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

Log Message:
make(1): fix garbled output for failed shell command (since 2020-12-20)

Passing a struct as printf argument for the %s conversion doesn't work.
On NetBSD-8.0-x86_64, the output looks normal, but on SunOS-5.9, the
output is garbled, containing bytes 0xFF and 0xFE.

This bug had been introduced in parse.c 1.507 from 2020-12-20 14:52:16.

Thanks to sjg for finding this bug so quickly.


To generate a diff of this commit:
cvs rdiff -u -r1.508 -r1.509 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.508 src/usr.bin/make/parse.c:1.509
--- src/usr.bin/make/parse.c:1.508	Sun Dec 20 18:23:24 2020
+++ src/usr.bin/make/parse.c	Mon Dec 21 02:09:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.508 2020/12/20 18:23:24 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.509 2020/12/21 02:09:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.508 2020/12/20 18:23:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.509 2020/12/21 02:09:34 rillig Exp $");
 
 /* types and constants */
 
@@ -1980,7 +1980,7 @@ VarAssign_EvalShell(const char *name, co
 	*out_avalue = FStr_InitOwn(cmdOut);
 
 	if (errfmt != NULL)
-		Parse_Error(PARSE_WARNING, errfmt, cmd);
+		Parse_Error(PARSE_WARNING, errfmt, cmd.str);
 
 	FStr_Done();
 }



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec 21 00:30:13 UTC 2020

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

Log Message:
make(1): save a few memory allocations in variable expressions


To generate a diff of this commit:
cvs rdiff -u -r1.758 -r1.759 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.758 src/usr.bin/make/var.c:1.759
--- src/usr.bin/make/var.c:1.758	Mon Dec 21 00:20:58 2020
+++ src/usr.bin/make/var.c	Mon Dec 21 00:30:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.758 2020/12/21 00:20:58 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.759 2020/12/21 00:30:13 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.758 2020/12/21 00:20:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.759 2020/12/21 00:30:13 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2432,7 +2432,7 @@ ApplyModifier_ShellCommand(const char **
 	if (st->eflags & VARE_WANTRES)
 		st->newVal = FStr_InitOwn(Cmd_Exec(cmd, ));
 	else
-		st->newVal = FStr_InitOwn(bmake_strdup(""));
+		st->newVal = FStr_InitRefer("");
 	if (errfmt != NULL)
 		Error(errfmt, cmd);	/* XXX: why still return AMR_OK? */
 	free(cmd);
@@ -2899,7 +2899,7 @@ ApplyModifier_Words(const char **pp, con
 
 	if (estr[0] == '#' && estr[1] == '\0') { /* Found ":[#]" */
 		if (st->oneBigWord) {
-			st->newVal = FStr_InitOwn(bmake_strdup("1"));
+			st->newVal = FStr_InitRefer("1");
 		} else {
 			Buffer buf;
 
@@ -3177,7 +3177,7 @@ ok:
 		}
 	}
 	free(val);
-	st->newVal = FStr_InitOwn(bmake_strdup(""));
+	st->newVal = FStr_InitRefer("");
 	return AMR_OK;
 }
 
@@ -3303,7 +3303,7 @@ ApplyModifier_SunShell(const char **pp, 
 			if (errfmt != NULL)
 Error(errfmt, val);
 		} else
-			st->newVal = FStr_InitOwn(bmake_strdup(""));
+			st->newVal = FStr_InitRefer("");
 		*pp = p + 2;
 		return AMR_OK;
 	} else



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec 21 00:20:58 UTC 2020

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

Log Message:
make(1): switch memory handling from MFStr to FStr

This makes all intermediate strings constant.  For this simple
search-and-replace refactoring, all intermediate locations where the
"current value of the expression" was stored had to be of the type
MFStr.

Using FStr instead of MFStr allows to save a few memory allocations,
which will be done in the follow-up commits.


To generate a diff of this commit:
cvs rdiff -u -r1.757 -r1.758 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.757 src/usr.bin/make/var.c:1.758
--- src/usr.bin/make/var.c:1.757	Mon Dec 21 00:11:29 2020
+++ src/usr.bin/make/var.c	Mon Dec 21 00:20:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.757 2020/12/21 00:11:29 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.758 2020/12/21 00:20:58 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.757 2020/12/21 00:11:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.758 2020/12/21 00:20:58 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1930,7 +1930,7 @@ typedef struct ApplyModifiersState {
 	 * The new value of the expression, after applying the modifier,
 	 * never NULL.
 	 */
-	MFStr newVal;
+	FStr newVal;
 	/* Word separator in expansions (see the :ts modifier). */
 	char sep;
 	/*
@@ -2225,7 +2225,7 @@ ApplyModifier_Loop(const char **pp, cons
 	args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 	prev_sep = st->sep;
 	st->sep = ' ';		/* XXX: should be st->sep for consistency */
-	st->newVal = MFStr_InitOwn(
+	st->newVal = FStr_InitOwn(
 	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2237,7 +2237,7 @@ ApplyModifier_Loop(const char **pp, cons
 
 /* :Ddefined or :Uundefined */
 static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, char *val, ApplyModifiersState *st)
+ApplyModifier_Defined(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	Buffer buf;
 	const char *p;
@@ -2286,9 +2286,9 @@ ApplyModifier_Defined(const char **pp, c
 	ApplyModifiersState_Define(st);
 
 	if (eflags & VARE_WANTRES) {
-		st->newVal = MFStr_InitOwn(Buf_Destroy(, FALSE));
+		st->newVal = FStr_InitOwn(Buf_Destroy(, FALSE));
 	} else {
-		st->newVal = MFStr_InitRefer(val);
+		st->newVal = FStr_InitRefer(val);
 		Buf_Destroy(, TRUE);
 	}
 	return AMR_OK;
@@ -2299,7 +2299,7 @@ static ApplyModifierResult
 ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
 {
 	ApplyModifiersState_Define(st);
-	st->newVal = MFStr_InitOwn(bmake_strdup(st->var->name.str));
+	st->newVal = FStr_InitOwn(bmake_strdup(st->var->name.str));
 	(*pp)++;
 	return AMR_OK;
 }
@@ -2345,7 +2345,7 @@ ApplyModifier_Gmtime(const char **pp, co
 		utc = 0;
 		*pp = mod + 6;
 	}
-	st->newVal = MFStr_InitOwn(VarStrftime(val, TRUE, utc));
+	st->newVal = FStr_InitOwn(VarStrftime(val, TRUE, utc));
 	return AMR_OK;
 }
 
@@ -2372,7 +2372,7 @@ ApplyModifier_Localtime(const char **pp,
 		utc = 0;
 		*pp = mod + 9;
 	}
-	st->newVal = MFStr_InitOwn(VarStrftime(val, FALSE, utc));
+	st->newVal = FStr_InitOwn(VarStrftime(val, FALSE, utc));
 	return AMR_OK;
 }
 
@@ -2383,7 +2383,7 @@ ApplyModifier_Hash(const char **pp, cons
 	if (!ModMatch(*pp, "hash", st->endc))
 		return AMR_UNKNOWN;
 
-	st->newVal = MFStr_InitOwn(VarHash(val));
+	st->newVal = FStr_InitOwn(VarHash(val));
 	*pp += 4;
 	return AMR_OK;
 }
@@ -2408,7 +2408,7 @@ ApplyModifier_Path(const char **pp, Appl
 	}
 	if (path == NULL)
 		path = bmake_strdup(st->var->name.str);
-	st->newVal = MFStr_InitOwn(path);
+	st->newVal = FStr_InitOwn(path);
 
 	(*pp)++;
 	return AMR_OK;
@@ -2430,9 +2430,9 @@ ApplyModifier_ShellCommand(const char **
 
 	errfmt = NULL;
 	if (st->eflags & VARE_WANTRES)
-		st->newVal = MFStr_InitOwn(Cmd_Exec(cmd, ));
+		st->newVal = FStr_InitOwn(Cmd_Exec(cmd, ));
 	else
-		st->newVal = MFStr_InitOwn(bmake_strdup(""));
+		st->newVal = FStr_InitOwn(bmake_strdup(""));
 	if (errfmt != NULL)
 		Error(errfmt, cmd);	/* XXX: why still return AMR_OK? */
 	free(cmd);
@@ -2483,7 +2483,7 @@ ApplyModifier_Range(const char **pp, con
 		Buf_AddInt(, 1 + (int)i);
 	}
 
-	st->newVal = MFStr_InitOwn(Buf_Destroy(, FALSE));
+	st->newVal = FStr_InitOwn(Buf_Destroy(, FALSE));
 	return AMR_OK;
 }
 
@@ -2560,7 +2560,7 @@ ApplyModifier_Match(const char **pp, con
 	st->var->name.str, val, pattern);
 
 	callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
-	st->newVal = MFStr_InitOwn(ModifyWords(val, callback, pattern,
+	st->newVal = FStr_InitOwn(ModifyWords(val, callback, pattern,
 	st->oneBigWord, 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Dec 21 00:11:29 UTC 2020

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

Log Message:
make(1): clean up memory management for expanding variable expressions

Previously, memory management had been split among several variables.
The general idea was very simple though.  The current value of the
expression needs to be kept in memory, and each modifier either keeps
that value or replaces it with its own newly allocated result, or
var_Error or varUndefined.

Using MFStr, it does not matter anymore that var_Error and varUndefined
are statically allocated since these are assigned using MFStr_InitRefer.

The complexity of the implementation is now closer to the actual
complexity.  Most probably the code can be simplified even more.


To generate a diff of this commit:
cvs rdiff -u -r1.756 -r1.757 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.756 src/usr.bin/make/var.c:1.757
--- src/usr.bin/make/var.c:1.756	Sun Dec 20 23:27:37 2020
+++ src/usr.bin/make/var.c	Mon Dec 21 00:11:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.756 2020/12/20 23:27:37 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.757 2020/12/21 00:11:29 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.756 2020/12/20 23:27:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.757 2020/12/21 00:11:29 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3420,8 +3420,8 @@ ApplyModifier(const char **pp, char *val
 	}
 }
 
-static char *ApplyModifiers(const char **, char *, char, char, Var *,
-			VarExprFlags *, GNode *, VarEvalFlags, void **);
+static MFStr ApplyModifiers(const char **, MFStr, char, char, Var *,
+			VarExprFlags *, GNode *, VarEvalFlags);
 
 typedef enum ApplyModifiersIndirectResult {
 	/* The indirect modifiers have been applied successfully. */
@@ -3450,7 +3450,7 @@ typedef enum ApplyModifiersIndirectResul
  */
 static ApplyModifiersIndirectResult
 ApplyModifiersIndirect(ApplyModifiersState *st, const char **pp,
-		   char **inout_val, void **inout_freeIt)
+		   MFStr *inout_value)
 {
 	const char *p = *pp;
 	FStr mods;
@@ -3468,10 +3468,10 @@ ApplyModifiersIndirect(ApplyModifiersSta
 
 	if (mods.str[0] != '\0') {
 		const char *modsp = mods.str;
-		*inout_val = ApplyModifiers(, *inout_val, '\0', '\0',
-		st->var, >exprFlags, st->ctxt, st->eflags,
-		inout_freeIt);
-		if (*inout_val == var_Error || *inout_val == varUndefined ||
+		MFStr newVal = ApplyModifiers(, *inout_value, '\0', '\0',
+		st->var, >exprFlags, st->ctxt, st->eflags);
+		*inout_value = newVal;
+		if (newVal.str == var_Error || newVal.str == varUndefined ||
 		*modsp != '\0') {
 			FStr_Done();
 			*pp = p;
@@ -3496,11 +3496,11 @@ ApplyModifiersIndirect(ApplyModifiersSta
 
 static ApplyModifierResult
 ApplySingleModifier(ApplyModifiersState *st, const char *mod, char endc,
-		const char **pp, char *val, char **out_val,
-		void **inout_freeIt)
+		const char **pp, MFStr *inout_value)
 {
 	ApplyModifierResult res;
 	const char *p = *pp;
+	char *const val = inout_value->str;
 
 	if (DEBUG(VAR))
 		LogBeforeApply(st, mod, endc, val);
@@ -3527,7 +3527,6 @@ ApplySingleModifier(ApplyModifiersState 
 		st->newVal = MFStr_InitRefer(var_Error);
 	}
 	if (res == AMR_CLEANUP || res == AMR_BAD) {
-		*out_val = val;
 		*pp = p;
 		return res;
 	}
@@ -3536,20 +3535,14 @@ ApplySingleModifier(ApplyModifiersState 
 		LogAfterApply(st, p, mod);
 
 	if (st->newVal.str != val) {
-		if (*inout_freeIt != NULL) {
-			assert(*inout_freeIt == val);
-			free(*inout_freeIt);
-			*inout_freeIt = NULL;
-		}
-		val = st->newVal.str;
-		if (val != var_Error && val != varUndefined)
-			*inout_freeIt = val;
+		MFStr_Done(inout_value);
+		*inout_value = st->newVal;
 	}
 	if (*p == '\0' && st->endc != '\0') {
 		Error(
 		"Unclosed variable specification (expecting '%c') "
 		"for \"%s\" (value \"%s\") modifier %c",
-		st->endc, st->var->name.str, val, *mod);
+		st->endc, st->var->name.str, inout_value->str, *mod);
 	} else if (*p == ':') {
 		p++;
 	} else if (opts.lint && *p != '\0' && *p != endc) {
@@ -3562,22 +3555,20 @@ ApplySingleModifier(ApplyModifiersState 
 		 */
 	}
 	*pp = p;
-	*out_val = val;
 	return AMR_OK;
 }
 
 /* Apply any modifiers (such as :Mpattern or :@var@loop@ or :Q or ::=value). */
-static char *
+static MFStr
 ApplyModifiers(
 const char **pp,		/* the parsing position, updated upon return */
-char *val,			/* the current value of the expression */
+MFStr value,		/* the current value of the expression */
 char startc,		/* '(' or '{', or '\0' for indirect modifiers */
 char endc,			/* ')' or '}', or '\0' for indirect modifiers */
 Var *v,
 

CVS commit: src/usr.bin/make/unit-tests

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 23:29:50 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varmod-to-many-words.mk
varmod-to-one-word.mk

Log Message:
make(1): add tests for :tW and :tw modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-to-many-words.mk \
src/usr.bin/make/unit-tests/varmod-to-one-word.mk

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/unit-tests/varmod-to-many-words.mk
diff -u src/usr.bin/make/unit-tests/varmod-to-many-words.mk:1.2 src/usr.bin/make/unit-tests/varmod-to-many-words.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-to-many-words.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varmod-to-many-words.mk	Sun Dec 20 23:29:50 2020
@@ -1,9 +1,21 @@
-# $NetBSD: varmod-to-many-words.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-to-many-words.mk,v 1.3 2020/12/20 23:29:50 rillig Exp $
 #
 # Tests for the :tw modifier, which treats the variable as many words,
 # to undo a previous :tW modifier.
 
-# TODO: Implementation
+SENTENCE=	The quick brown fox jumps over the lazy brown dog.
+
+.if ${SENTENCE:tw:[#]} != 10
+.  error
+.endif
+.if ${SENTENCE:tW:[#]} != 1
+.  error
+.endif
+
+# Protect against accidental freeing of the variable value.
+.if ${SENTENCE} != "The quick brown fox jumps over the lazy brown dog."
+.  error
+.endif
 
 all:
 	@:;
Index: src/usr.bin/make/unit-tests/varmod-to-one-word.mk
diff -u src/usr.bin/make/unit-tests/varmod-to-one-word.mk:1.2 src/usr.bin/make/unit-tests/varmod-to-one-word.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-to-one-word.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varmod-to-one-word.mk	Sun Dec 20 23:29:50 2020
@@ -1,9 +1,21 @@
-# $NetBSD: varmod-to-one-word.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-to-one-word.mk,v 1.3 2020/12/20 23:29:50 rillig Exp $
 #
 # Tests for the :tW variable modifier, which treats the variable value
 # as a single word, for all following modifiers.
 
-# TODO: Implementation
+SENTENCE=	The quick brown fox jumps over the lazy brown dog.
+
+.if ${SENTENCE:tW:[#]} != 1
+.  error
+.endif
+.if ${SENTENCE:tw:[#]} != 10
+.  error
+.endif
+
+# Protect against accidental freeing of the variable value.
+.if ${SENTENCE} != "The quick brown fox jumps over the lazy brown dog."
+.  error
+.endif
 
 all:
 	@:;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 23:27:37 UTC 2020

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

Log Message:
make(1): use FStr for ApplyModifiersState.newVal

Memory management is still complicated in this area.  To clean this up,
the previous value of the expression needs to be converted to an MFStr
first, and later to an FStr.


To generate a diff of this commit:
cvs rdiff -u -r1.755 -r1.756 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.755 src/usr.bin/make/var.c:1.756
--- src/usr.bin/make/var.c:1.755	Sun Dec 20 19:51:37 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 23:27:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.755 2020/12/20 19:51:37 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.756 2020/12/20 23:27:37 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.755 2020/12/20 19:51:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.756 2020/12/20 23:27:37 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1930,7 +1930,7 @@ typedef struct ApplyModifiersState {
 	 * The new value of the expression, after applying the modifier,
 	 * never NULL.
 	 */
-	char *newVal;
+	MFStr newVal;
 	/* Word separator in expansions (see the :ts modifier). */
 	char sep;
 	/*
@@ -2225,8 +2225,8 @@ ApplyModifier_Loop(const char **pp, cons
 	args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 	prev_sep = st->sep;
 	st->sep = ' ';		/* XXX: should be st->sep for consistency */
-	st->newVal = ModifyWords(val, ModifyWord_Loop, ,
-	st->oneBigWord, st->sep);
+	st->newVal = MFStr_InitOwn(
+	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
 	Var_Delete(args.tvar, st->ctxt);
@@ -2286,9 +2286,9 @@ ApplyModifier_Defined(const char **pp, c
 	ApplyModifiersState_Define(st);
 
 	if (eflags & VARE_WANTRES) {
-		st->newVal = Buf_Destroy(, FALSE);
+		st->newVal = MFStr_InitOwn(Buf_Destroy(, FALSE));
 	} else {
-		st->newVal = val;
+		st->newVal = MFStr_InitRefer(val);
 		Buf_Destroy(, TRUE);
 	}
 	return AMR_OK;
@@ -2299,7 +2299,7 @@ static ApplyModifierResult
 ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
 {
 	ApplyModifiersState_Define(st);
-	st->newVal = bmake_strdup(st->var->name.str);
+	st->newVal = MFStr_InitOwn(bmake_strdup(st->var->name.str));
 	(*pp)++;
 	return AMR_OK;
 }
@@ -2345,7 +2345,7 @@ ApplyModifier_Gmtime(const char **pp, co
 		utc = 0;
 		*pp = mod + 6;
 	}
-	st->newVal = VarStrftime(val, TRUE, utc);
+	st->newVal = MFStr_InitOwn(VarStrftime(val, TRUE, utc));
 	return AMR_OK;
 }
 
@@ -2372,7 +2372,7 @@ ApplyModifier_Localtime(const char **pp,
 		utc = 0;
 		*pp = mod + 9;
 	}
-	st->newVal = VarStrftime(val, FALSE, utc);
+	st->newVal = MFStr_InitOwn(VarStrftime(val, FALSE, utc));
 	return AMR_OK;
 }
 
@@ -2383,7 +2383,7 @@ ApplyModifier_Hash(const char **pp, cons
 	if (!ModMatch(*pp, "hash", st->endc))
 		return AMR_UNKNOWN;
 
-	st->newVal = VarHash(val);
+	st->newVal = MFStr_InitOwn(VarHash(val));
 	*pp += 4;
 	return AMR_OK;
 }
@@ -2408,7 +2408,7 @@ ApplyModifier_Path(const char **pp, Appl
 	}
 	if (path == NULL)
 		path = bmake_strdup(st->var->name.str);
-	st->newVal = path;
+	st->newVal = MFStr_InitOwn(path);
 
 	(*pp)++;
 	return AMR_OK;
@@ -2430,9 +2430,9 @@ ApplyModifier_ShellCommand(const char **
 
 	errfmt = NULL;
 	if (st->eflags & VARE_WANTRES)
-		st->newVal = Cmd_Exec(cmd, );
+		st->newVal = MFStr_InitOwn(Cmd_Exec(cmd, ));
 	else
-		st->newVal = bmake_strdup("");
+		st->newVal = MFStr_InitOwn(bmake_strdup(""));
 	if (errfmt != NULL)
 		Error(errfmt, cmd);	/* XXX: why still return AMR_OK? */
 	free(cmd);
@@ -2483,7 +2483,7 @@ ApplyModifier_Range(const char **pp, con
 		Buf_AddInt(, 1 + (int)i);
 	}
 
-	st->newVal = Buf_Destroy(, FALSE);
+	st->newVal = MFStr_InitOwn(Buf_Destroy(, FALSE));
 	return AMR_OK;
 }
 
@@ -2560,8 +2560,8 @@ ApplyModifier_Match(const char **pp, con
 	st->var->name.str, val, pattern);
 
 	callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
-	st->newVal = ModifyWords(val, callback, pattern,
-	st->oneBigWord, st->sep);
+	st->newVal = MFStr_InitOwn(ModifyWords(val, callback, pattern,
+	st->oneBigWord, st->sep));
 	free(pattern);
 	return AMR_OK;
 }
@@ -2624,8 +2624,8 @@ ApplyModifier_Subst(const char **pp, con
 		break;
 	}
 
-	st->newVal = ModifyWords(val, ModifyWord_Subst, ,
-	oneBigWord, st->sep);
+	st->newVal = MFStr_InitOwn(ModifyWords(val, ModifyWord_Subst, ,
+	oneBigWord, st->sep));
 
 	free(lhs);
 	free(rhs);
@@ -2694,8 +2694,9 @@ ApplyModifier_Regex(const char **pp, con
 	args.nsub = args.re.re_nsub + 1;
 	if (args.nsub > 10)
 		args.nsub = 10;
-	st->newVal = ModifyWords(val, 

CVS commit: src/usr.bin/make/unit-tests

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 22:57:40 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: varmod-extension.exp varmod-extension.mk
varmod-head.exp varmod-head.mk varmod-root.exp varmod-root.mk
varmod-tail.exp varmod-tail.mk

Log Message:
make(1): add tests for variable modifiers on trailing slashes


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-extension.exp \
src/usr.bin/make/unit-tests/varmod-head.exp \
src/usr.bin/make/unit-tests/varmod-root.exp \
src/usr.bin/make/unit-tests/varmod-tail.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-extension.mk \
src/usr.bin/make/unit-tests/varmod-head.mk \
src/usr.bin/make/unit-tests/varmod-root.mk \
src/usr.bin/make/unit-tests/varmod-tail.mk

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/unit-tests/varmod-extension.exp
diff -u src/usr.bin/make/unit-tests/varmod-extension.exp:1.2 src/usr.bin/make/unit-tests/varmod-extension.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-extension.exp:1.2	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-extension.exp	Sun Dec 20 22:57:40 2020
@@ -7,4 +7,5 @@ extension of 'a.a' is 'a'
 extension of '.gitignore' is 'gitignore'
 extension of 'a' is ''
 extension of 'a.a' is 'a'
+extension of 'trailing/' is ''
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-head.exp
diff -u src/usr.bin/make/unit-tests/varmod-head.exp:1.2 src/usr.bin/make/unit-tests/varmod-head.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-head.exp:1.2	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-head.exp	Sun Dec 20 22:57:40 2020
@@ -7,4 +7,5 @@ head (dirname) of 'a.a' is '.'
 head (dirname) of '.gitignore' is '.'
 head (dirname) of 'a' is '.'
 head (dirname) of 'a.a' is '.'
+head (dirname) of 'trailing/' is 'trailing'
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-root.exp
diff -u src/usr.bin/make/unit-tests/varmod-root.exp:1.2 src/usr.bin/make/unit-tests/varmod-root.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-root.exp:1.2	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-root.exp	Sun Dec 20 22:57:40 2020
@@ -7,4 +7,5 @@ root of 'a.a' is 'a'
 root of '.gitignore' is ''
 root of 'a' is 'a'
 root of 'a.a' is 'a'
+root of 'trailing/' is 'trailing/'
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-tail.exp
diff -u src/usr.bin/make/unit-tests/varmod-tail.exp:1.2 src/usr.bin/make/unit-tests/varmod-tail.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-tail.exp:1.2	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-tail.exp	Sun Dec 20 22:57:40 2020
@@ -7,4 +7,5 @@ tail (basename) of 'a.a' is 'a.a'
 tail (basename) of '.gitignore' is '.gitignore'
 tail (basename) of 'a' is 'a'
 tail (basename) of 'a.a' is 'a.a'
+tail (basename) of 'trailing/' is ''
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-extension.mk
diff -u src/usr.bin/make/unit-tests/varmod-extension.mk:1.3 src/usr.bin/make/unit-tests/varmod-extension.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-extension.mk:1.3	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-extension.mk	Sun Dec 20 22:57:40 2020
@@ -1,9 +1,9 @@
-# $NetBSD: varmod-extension.mk,v 1.3 2020/08/23 15:09:15 rillig Exp $
+# $NetBSD: varmod-extension.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $
 #
 # Tests for the :E variable modifier, which returns the filename extension
 # of each word in the variable.
 
 all:
-.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
+.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/
 	@echo "extension of '"${path:Q}"' is '"${path:E:Q}"'"
 .endfor
Index: src/usr.bin/make/unit-tests/varmod-head.mk
diff -u src/usr.bin/make/unit-tests/varmod-head.mk:1.3 src/usr.bin/make/unit-tests/varmod-head.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-head.mk:1.3	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-head.mk	Sun Dec 20 22:57:40 2020
@@ -1,9 +1,9 @@
-# $NetBSD: varmod-head.mk,v 1.3 2020/08/23 15:09:15 rillig Exp $
+# $NetBSD: varmod-head.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $
 #
 # Tests for the :H variable modifier, which returns the dirname of
 # each of the words in the variable value.
 
 all:
-.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
+.for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/
 	@echo "head (dirname) of '"${path:Q}"' is '"${path:H:Q}"'"
 .endfor
Index: src/usr.bin/make/unit-tests/varmod-root.mk
diff -u src/usr.bin/make/unit-tests/varmod-root.mk:1.3 src/usr.bin/make/unit-tests/varmod-root.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-root.mk:1.3	Sun Aug 23 15:09:15 2020
+++ src/usr.bin/make/unit-tests/varmod-root.mk	Sun Dec 20 22:57:40 2020
@@ -1,9 +1,9 @@
-# $NetBSD: varmod-root.mk,v 1.3 2020/08/23 15:09:15 rillig Exp $
+# $NetBSD: varmod-root.mk,v 1.4 2020/12/20 22:57:40 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 22:36:40 UTC 2020

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

Log Message:
make(1): fix undefined behavior in meta_oodate

Do not increment a null pointer.

Do not assign to a variable twice in the same statement.  To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/usr.bin/make/meta.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/meta.c
diff -u src/usr.bin/make/meta.c:1.163 src/usr.bin/make/meta.c:1.164
--- src/usr.bin/make/meta.c:1.163	Sun Dec 20 22:12:36 2020
+++ src/usr.bin/make/meta.c	Sun Dec 20 22:36:40 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: meta.c,v 1.163 2020/12/20 22:12:36 rillig Exp $ */
+/*  $NetBSD: meta.c,v 1.164 2020/12/20 22:36:40 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -820,9 +820,10 @@ meta_job_output(Job *job, char *cp, cons
 		meta_prefix_len = strlen(meta_prefix);
 	}
 	if (strncmp(cp, meta_prefix, meta_prefix_len) == 0) {
-		cp = strchr(cp+1, '\n');
-		if (!cp++)
+		cp = strchr(cp + 1, '\n');
+		if (cp == NULL)
 		return;
+		cp++;
 	}
 	}
 	fprintf(pbm->mfp, "%s%s", cp, nl);
@@ -1527,7 +1528,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 warnx("%s: %d: line truncated at %u", fname, lineno, x);
 break;
 			}
-			cp = strchr(++cp, '\n');
+			cp = strchr(cp + 1, '\n');
 			} while (cp != NULL);
 			if (buf[x - 1] == '\n')
 			buf[x - 1] = '\0';



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 22:12:36 UTC 2020

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

Log Message:
make(1): reduce scope of cp in meta_oodate

That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/make/meta.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/meta.c
diff -u src/usr.bin/make/meta.c:1.162 src/usr.bin/make/meta.c:1.163
--- src/usr.bin/make/meta.c:1.162	Sun Dec 20 22:02:54 2020
+++ src/usr.bin/make/meta.c	Sun Dec 20 22:12:36 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: meta.c,v 1.162 2020/12/20 22:02:54 rillig Exp $ */
+/*  $NetBSD: meta.c,v 1.163 2020/12/20 22:12:36 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -1076,7 +1076,6 @@ meta_oodate(GNode *gn, Boolean oodate)
 FStr dname;
 const char *tname;
 char *p;
-char *cp;
 char *link_src;
 char *move_target;
 static size_t cwdlen = 0;
@@ -1296,13 +1295,15 @@ meta_oodate(GNode *gn, Boolean oodate)
 		 * the src as for 'R'ead
 		 * and the target as for 'W'rite.
 		 */
-		cp = p;		/* save this for a second */
-		/* now get target */
-		if (strsep(, " ") == NULL)
-			continue;
-		CHECK_VALID_META(p);
-		move_target = p;
-		p = cp;
+		{
+			char *cp = p;	/* save this for a second */
+			/* now get target */
+			if (strsep(, " ") == NULL)
+			continue;
+			CHECK_VALID_META(p);
+			move_target = p;
+			p = cp;
+		}
 		/* 'L' and 'M' put single quotes around the args */
 		DEQUOTE(p);
 		DEQUOTE(move_target);
@@ -1487,6 +1488,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 			   fname, lineno);
 		oodate = TRUE;
 		} else {
+		const char *cp;
 		char *cmd = cmdNode->datum;
 		Boolean hasOODATE = FALSE;
 
@@ -1573,7 +1575,7 @@ meta_oodate(GNode *gn, Boolean oodate)
 	}
 } else {
 	if (writeMeta && (metaMissing || (gn->type & OP_META))) {
-	cp = NULL;
+	const char *cp = NULL;
 
 	/* if target is in .CURDIR we do not need a meta file */
 	if (gn->path && (cp = strrchr(gn->path, '/')) && cp > gn->path) {



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 22:02:54 UTC 2020

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

Log Message:
make(1): fix declared variable type in printCMDs

No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/make/meta.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/meta.c
diff -u src/usr.bin/make/meta.c:1.161 src/usr.bin/make/meta.c:1.162
--- src/usr.bin/make/meta.c:1.161	Sun Dec 20 14:32:13 2020
+++ src/usr.bin/make/meta.c	Sun Dec 20 22:02:54 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: meta.c,v 1.161 2020/12/20 14:32:13 rillig Exp $ */
+/*  $NetBSD: meta.c,v 1.162 2020/12/20 22:02:54 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -386,7 +386,7 @@ printCMD(const char *cmd, FILE *fp, GNod
 static void
 printCMDs(GNode *gn, FILE *fp)
 {
-GNodeListNode *ln;
+StringListNode *ln;
 
 for (ln = gn->commands.first; ln != NULL; ln = ln->next)
 	printCMD(ln->datum, fp, gn);



CVS commit: src/etc

2020-12-20 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sun Dec 20 21:30:28 UTC 2020

Modified Files:
src/etc: rc.subr

Log Message:
run_rc_command - don't prefix the rcvar variable name with the dollar sign.

The output without the dollar sign is less confusing as it's actual
valid shell syntax:

  $ /etc/rc.d/foo rcvar
  # food
  food=YES

Brought up on tech-userlevel@ by Rocky Hotas with some LGTMs from
other people and no objections.

We still refer to '$food' in warnings/errors though.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/etc/rc.subr

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/rc.subr
diff -u src/etc/rc.subr:1.105 src/etc/rc.subr:1.106
--- src/etc/rc.subr:1.105	Thu Sep 17 20:29:03 2020
+++ src/etc/rc.subr	Sun Dec 20 21:30:28 2020
@@ -1,4 +1,4 @@
-# $NetBSD: rc.subr,v 1.105 2020/09/17 20:29:03 otis Exp $
+# $NetBSD: rc.subr,v 1.106 2020/12/20 21:30:28 uwe Exp $
 #
 # Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -822,9 +822,9 @@ $command $rc_flags $command_args"
 			echo "# $name"
 			if [ -n "$rcvar" ]; then
 if checkyesno ${rcvar}; then
-	echo "\$${rcvar}=YES"
+	echo "${rcvar}=YES"
 else
-	echo "\$${rcvar}=NO"
+	echo "${rcvar}=NO"
 fi
 			fi
 			;;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 21:07:32 UTC 2020

Modified Files:
src/usr.bin/make: compat.c job.c nonints.h

Log Message:
make(1): omit linear search for command in Compat_RunCommand


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/compat.c
cvs rdiff -u -r1.388 -r1.389 src/usr.bin/make/job.c
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/nonints.h

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/compat.c
diff -u src/usr.bin/make/compat.c:1.215 src/usr.bin/make/compat.c:1.216
--- src/usr.bin/make/compat.c:1.215	Sun Dec 13 19:33:53 2020
+++ src/usr.bin/make/compat.c	Sun Dec 20 21:07:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.215 2020/12/13 19:33:53 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.215 2020/12/13 19:33:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.216 2020/12/20 21:07:32 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -211,13 +211,14 @@ UseShell(const char *cmd MAKE_ATTR_UNUSE
  *
  * Input:
  *	cmdp		Command to execute
- *	gnp		Node from which the command came
+ *	gn		Node from which the command came
+ *	ln		List node that contains the command
  *
  * Results:
  *	0 if the command succeeded, 1 if an error occurred.
  */
 int
-Compat_RunCommand(const char *cmdp, GNode *gn)
+Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
 {
 	char *cmdStart;		/* Start of expanded command */
 	char *bp;
@@ -228,7 +229,6 @@ Compat_RunCommand(const char *cmdp, GNod
 	int status;		/* Description of child's death */
 	pid_t cpid;		/* Child actually found */
 	pid_t retstat;		/* Result of wait */
-	StringListNode *cmdNode; /* Node where current command is located */
 	const char **volatile av; /* Argument vector for thing to exec */
 	char **volatile mav;	/* Copy of the argument vector for freeing */
 	Boolean useShell;	/* TRUE if command should be executed
@@ -239,12 +239,6 @@ Compat_RunCommand(const char *cmdp, GNod
 	errCheck = !(gn->type & OP_IGNORE);
 	doIt = FALSE;
 
-	/* Luckily the commands don't end up in a string pool, otherwise
-	 * this comparison could match too early, in a dependency using "..."
-	 * for delayed commands, run in parallel mode, using the same shell
-	 * command line more than once; see JobPrintCommand.
-	 * TODO: write a unit-test to protect against this potential bug. */
-	cmdNode = Lst_FindDatum(>commands, cmd);
 	(void)Var_Subst(cmd, gn, VARE_WANTRES, );
 	/* TODO: handle errors */
 
@@ -253,7 +247,7 @@ Compat_RunCommand(const char *cmdp, GNod
 		return 0;
 	}
 	cmd = cmdStart;
-	LstNode_Set(cmdNode, cmdStart);
+	LstNode_Set(ln, cmdStart);
 
 	if (gn->type & OP_SAVE_CMDS) {
 		GNode *endNode = Targ_GetEndNode();
@@ -379,7 +373,7 @@ Compat_RunCommand(const char *cmdp, GNod
 
 	/* XXX: Memory management looks suspicious here. */
 	/* XXX: Setting a list item to NULL is unexpected. */
-	LstNode_SetNull(cmdNode);
+	LstNode_SetNull(ln);
 
 #ifdef USE_META
 	if (useMeta) {
@@ -467,7 +461,7 @@ RunCommands(GNode *gn)
 
 	for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
 		const char *cmd = ln->datum;
-		if (Compat_RunCommand(cmd, gn) != 0)
+		if (Compat_RunCommand(cmd, gn, ln) != 0)
 			break;
 	}
 }

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.388 src/usr.bin/make/job.c:1.389
--- src/usr.bin/make/job.c:1.388	Tue Dec 15 21:19:47 2020
+++ src/usr.bin/make/job.c	Sun Dec 20 21:07:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.388 2020/12/15 21:19:47 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.389 2020/12/20 21:07:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.388 2020/12/15 21:19:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.389 2020/12/20 21:07:32 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -890,7 +890,7 @@ JobPrintSpecials(Job *job, ShellWriter *
  * after all other targets have been made.
  */
 static void
-JobPrintCommand(Job *job, ShellWriter *wr, const char *ucmd)
+JobPrintCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
 {
 	Boolean run;
 
@@ -917,7 +917,7 @@ JobPrintCommand(Job *job, ShellWriter *w
 		 * We're not actually executing anything...
 		 * but this one needs to be - use compat mode just for it.
 		 */
-		Compat_RunCommand(ucmd, job->node);
+		Compat_RunCommand(ucmd, job->node, ln);
 		free(xcmdStart);
 		return;
 	}
@@ -1005,7 +1005,7 @@ JobPrintCommands(Job *job)
 			break;
 		}
 
-		JobPrintCommand(job, , 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:51:38 UTC 2020

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

Log Message:
make(1): remove redundant assignment in ApplyModifier_SysV


To generate a diff of this commit:
cvs rdiff -u -r1.754 -r1.755 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.754 src/usr.bin/make/var.c:1.755
--- src/usr.bin/make/var.c:1.754	Sun Dec 20 19:47:34 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 19:51:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.754 2020/12/20 19:47:34 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.755 2020/12/20 19:51:37 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.754 2020/12/20 19:47:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.755 2020/12/20 19:51:37 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3259,7 +3259,6 @@ ApplyModifier_SysV(const char **pp, char
 	if (*p != st->endc || !eqFound)
 		return AMR_UNKNOWN;
 
-	*pp = mod;
 	res = ParseModifierPart(pp, '=', st->eflags, st,
 	, NULL, NULL, NULL);
 	if (res != VPR_OK)



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:47:34 UTC 2020

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: cond-token-string.exp opt-debug-lint.exp
vardebug.exp varmod-edge.exp varmod-indirect.exp varmod-range.exp
varparse-errors.exp varparse-errors.mk

Log Message:
make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such.  This "error message"
also did not influence the exit status in the default mode but only in
-dL mode.  The error message also didn't include any line number
information and was thus rude.


To generate a diff of this commit:
cvs rdiff -u -r1.753 -r1.754 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-token-string.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/opt-debug-lint.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-edge.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-indirect.exp \
src/usr.bin/make/unit-tests/varparse-errors.exp \
src/usr.bin/make/unit-tests/varparse-errors.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-range.exp

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.753 src/usr.bin/make/var.c:1.754
--- src/usr.bin/make/var.c:1.753	Sun Dec 20 19:10:53 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 19:47:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.753 2020/12/20 19:10:53 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.754 2020/12/20 19:47:34 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.753 2020/12/20 19:10:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.754 2020/12/20 19:47:34 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3511,7 +3511,7 @@ ApplySingleModifier(ApplyModifiersState 
 #endif
 
 	if (res == AMR_UNKNOWN) {
-		Error("Unknown modifier '%c'", *mod);
+		Parse_Error(PARSE_FATAL, "Unknown modifier '%c'", *mod);
 		/*
 		 * Guess the end of the current modifier.
 		 * XXX: Skipping the rest of the modifier hides

Index: src/usr.bin/make/unit-tests/cond-token-string.exp
diff -u src/usr.bin/make/unit-tests/cond-token-string.exp:1.3 src/usr.bin/make/unit-tests/cond-token-string.exp:1.4
--- src/usr.bin/make/unit-tests/cond-token-string.exp:1.3	Wed Nov 11 07:10:19 2020
+++ src/usr.bin/make/unit-tests/cond-token-string.exp	Sun Dec 20 19:47:34 2020
@@ -1,4 +1,4 @@
-make: Unknown modifier 'Z'
+make: "cond-token-string.mk" line 9: Unknown modifier 'Z'
 make: "cond-token-string.mk" line 9: Malformed conditional ("" != "${:Uvalue:Z}")
 make: "cond-token-string.mk" line 18: xvalue is not defined.
 make: "cond-token-string.mk" line 24: Malformed conditional (x${:Uvalue} == "")

Index: src/usr.bin/make/unit-tests/opt-debug-lint.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.12 src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.13
--- src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.12	Sun Dec 20 19:10:53 2020
+++ src/usr.bin/make/unit-tests/opt-debug-lint.exp	Sun Dec 20 19:47:34 2020
@@ -2,7 +2,7 @@ make: "opt-debug-lint.mk" line 19: Varia
 make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L"
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P"
-make: Unknown modifier '$'
+make: "opt-debug-lint.mk" line 69: Unknown modifier '$'
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u src/usr.bin/make/unit-tests/vardebug.exp:1.13 src/usr.bin/make/unit-tests/vardebug.exp:1.14
--- src/usr.bin/make/unit-tests/vardebug.exp:1.13	Tue Nov 17 20:27:35 2020
+++ src/usr.bin/make/unit-tests/vardebug.exp	Sun Dec 20 19:47:34 2020
@@ -71,7 +71,7 @@ Var_Parse: ${:Uvariable:unknown} with VA
 Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
 Result of ${:Uvariable} is "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Applying ${:u...} to "variable" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
-make: Unknown modifier 'u'
+make: "vardebug.mk" line 44: Unknown modifier 'u'
 Result of ${:unknown} is error (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown})
 Var_Parse: ${UNDEFINED} with VARE_UNDEFERR|VARE_WANTRES

Index: src/usr.bin/make/unit-tests/varmod-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.9 src/usr.bin/make/unit-tests/varmod-edge.exp:1.10
--- 

CVS commit: src/usr.bin/make/unit-tests

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:37:23 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: Makefile varmod-edge.exp

Log Message:
make(1): include line numbers in output of test varmod-edge.mk

Suppressing the line numbers does not provide much benefit, given that
the test file doesn't change often.


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.253 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-edge.exp

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/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.252 src/usr.bin/make/unit-tests/Makefile:1.253
--- src/usr.bin/make/unit-tests/Makefile:1.252	Sat Dec 19 16:00:17 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun Dec 20 19:37:23 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.252 2020/12/19 16:00:17 rillig Exp $
+# $NetBSD: Makefile,v 1.253 2020/12/20 19:37:23 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -502,7 +502,6 @@ SED_CMDS.var-op-shell+=	\
 	-e 's,^${.SHELL:T}: [ 0-9:]*,,' \
 	-e '/command/s,No such.*,not found,'
 SED_CMDS.vardebug+=	-e 's,${.SHELL},,'
-SED_CMDS.varmod-edge+=	-e 's, line [0-9]*:, line omitted:,'
 SED_CMDS.varmod-gmtime+=	-e 's,Tue Jan 19 03:14:08 2038,,'
 SED_CMDS.varmod-gmtime+=	${:D FreeBSD i386 still has 32-bit time_t. }
 SED_CMDS.varmod-gmtime+=	-e 's,Fri Dec 13 20:45:52 1901,,'

Index: src/usr.bin/make/unit-tests/varmod-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.8 src/usr.bin/make/unit-tests/varmod-edge.exp:1.9
--- src/usr.bin/make/unit-tests/varmod-edge.exp:1.8	Sat Aug  8 13:27:42 2020
+++ src/usr.bin/make/unit-tests/varmod-edge.exp	Sun Dec 20 19:37:23 2020
@@ -1,22 +1,22 @@
-make: "varmod-edge.mk" line omitted: ok M-paren
-make: "varmod-edge.mk" line omitted: ok M-mixed
-make: "varmod-edge.mk" line omitted: ok M-unescape
+make: "varmod-edge.mk" line 166: ok M-paren
+make: "varmod-edge.mk" line 166: ok M-mixed
+make: "varmod-edge.mk" line 166: ok M-unescape
 make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
-make: "varmod-edge.mk" line omitted: ok M-nest-mix
-make: "varmod-edge.mk" line omitted: ok M-nest-brk
-make: "varmod-edge.mk" line omitted: ok M-pat-err
-make: "varmod-edge.mk" line omitted: ok M-bsbs
-make: "varmod-edge.mk" line omitted: ok M-bs1-par
-make: "varmod-edge.mk" line omitted: ok M-bs2-par
-make: "varmod-edge.mk" line omitted: ok M-128
-make: "varmod-edge.mk" line omitted: ok eq-ext
-make: "varmod-edge.mk" line omitted: ok eq-q
-make: "varmod-edge.mk" line omitted: ok eq-bs
+make: "varmod-edge.mk" line 166: ok M-nest-mix
+make: "varmod-edge.mk" line 166: ok M-nest-brk
+make: "varmod-edge.mk" line 166: ok M-pat-err
+make: "varmod-edge.mk" line 166: ok M-bsbs
+make: "varmod-edge.mk" line 166: ok M-bs1-par
+make: "varmod-edge.mk" line 166: ok M-bs2-par
+make: "varmod-edge.mk" line 166: ok M-128
+make: "varmod-edge.mk" line 166: ok eq-ext
+make: "varmod-edge.mk" line 166: ok eq-q
+make: "varmod-edge.mk" line 166: ok eq-bs
 make: Unfinished modifier for INP.eq-esc ('=' missing)
-make: "varmod-edge.mk" line omitted: ok eq-esc
-make: "varmod-edge.mk" line omitted: ok colon
+make: "varmod-edge.mk" line 166: ok eq-esc
+make: "varmod-edge.mk" line 166: ok colon
 make: Unknown modifier ':'
 make: Unknown modifier ':'
-make: "varmod-edge.mk" line omitted: ok colons
+make: "varmod-edge.mk" line 166: ok colons
 ok
 exit status 0



CVS commit: src/sys/dev/pci

2020-12-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Dec 20 19:30:04 UTC 2020

Modified Files:
src/sys/dev/pci: aceride.c

Log Message:
disable (U)DMA for ATAPI on aceride(4), the chip doesn't support it
PR port-sparc64/55540


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/pci/aceride.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/aceride.c
diff -u src/sys/dev/pci/aceride.c:1.37 src/sys/dev/pci/aceride.c:1.38
--- src/sys/dev/pci/aceride.c:1.37	Fri Jul 21 21:01:13 2017
+++ src/sys/dev/pci/aceride.c	Sun Dec 20 19:30:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aceride.c,v 1.37 2017/07/21 21:01:13 nakayama Exp $	*/
+/*	$NetBSD: aceride.c,v 1.38 2020/12/20 19:30:03 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aceride.c,v 1.37 2017/07/21 21:01:13 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aceride.c,v 1.38 2020/12/20 19:30:03 jdolecek Exp $");
 
 #include 
 #include 
@@ -298,6 +298,13 @@ acer_setup_channel(struct ata_channel *c
 		ACER_UDMA_EN(chp->ch_channel, drive) |
 		ACER_UDMA_TIM(chp->ch_channel, drive, 0x7));
 
+		/* (U)DMA doesn't work with ATAPI devices */
+		if (drvp->drive_type == ATA_DRIVET_ATAPI) {
+			s = splbio();
+			drvp->drive_flags &= ~(ATA_DRIVE_DMA|ATA_DRIVE_UDMA);
+			splx(s);
+		}
+
 		/* add timing values, setup DMA if needed */
 		if ((drvp->drive_flags & ATA_DRIVE_DMA) == 0 &&
 		(drvp->drive_flags & ATA_DRIVE_UDMA) == 0) {



CVS commit: src/usr.bin/make/unit-tests

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:29:06 UTC 2020

Modified Files:
src/usr.bin/make/unit-tests: modmisc.exp modmisc.mk varmod-indirect.exp
varmod-indirect.mk

Log Message:
make(1): move tests for indirect modifiers around

The next commit will error out on unknown modifiers and influence the
exit status.  The test modmisc.mk contains both parse time tests and run
time tests.  To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/make/unit-tests/modmisc.exp
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/make/unit-tests/modmisc.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-indirect.exp \
src/usr.bin/make/unit-tests/varmod-indirect.mk

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/unit-tests/modmisc.exp
diff -u src/usr.bin/make/unit-tests/modmisc.exp:1.46 src/usr.bin/make/unit-tests/modmisc.exp:1.47
--- src/usr.bin/make/unit-tests/modmisc.exp:1.46	Sun Aug 23 15:18:43 2020
+++ src/usr.bin/make/unit-tests/modmisc.exp	Sun Dec 20 19:29:06 2020
@@ -1,4 +1,3 @@
-make: Unknown modifier '$'
 path=':/bin:/tmp::/:.:/no/such/dir:.'
 path='/bin:/tmp:/:/no/such/dir'
 path='/bin:/tmp:/:/no/such/dir'

Index: src/usr.bin/make/unit-tests/modmisc.mk
diff -u src/usr.bin/make/unit-tests/modmisc.mk:1.51 src/usr.bin/make/unit-tests/modmisc.mk:1.52
--- src/usr.bin/make/unit-tests/modmisc.mk:1.51	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/modmisc.mk	Sun Dec 20 19:29:06 2020
@@ -1,4 +1,4 @@
-# $NetBSD: modmisc.mk,v 1.51 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: modmisc.mk,v 1.52 2020/12/20 19:29:06 rillig Exp $
 #
 # miscellaneous modifier tests
 
@@ -63,30 +63,3 @@ mod-quote:
 # Cover the bmake_realloc in Str_Words.
 mod-break-many-words:
 	@echo $@: ${UNDEF:U:range=500:[#]}
-
-# To apply a modifier indirectly via another variable, the whole
-# modifier must be put into a single variable expression.
-.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
-.  warning unexpected
-.endif
-
-# Adding another level of indirection (the 2 nested :U expressions) helps.
-.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
-.  warning unexpected
-.endif
-
-# Multiple indirect modifiers can be applied one after another as long as
-# they are separated with colons.
-.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
-.  warning unexpected
-.endif
-
-# An indirect variable that evaluates to the empty string is allowed though.
-# This makes it possible to define conditional modifiers, like this:
-#
-# M.little-endian=	S,1234,4321,
-# M.big-endian=		# none
-.if ${value:L:${:Dempty}S,a,A,} != "vAlue"
-.  warning unexpected
-.endif
-

Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.1 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.1	Tue Dec  1 22:16:36 2020
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Dec 20 19:29:06 2020
@@ -1 +1,2 @@
+make: Unknown modifier '$'
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.1 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.1	Tue Dec  1 22:16:36 2020
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Dec 20 19:29:06 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.1 2020/12/01 22:16:36 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.2 2020/12/20 19:29:06 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -8,6 +8,36 @@
 # TODO: Since when are indirect modifiers supported?
 
 
+# To apply a modifier indirectly via another variable, the whole
+# modifier must be put into a single variable expression.
+.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
+.  warning unexpected
+.endif
+
+
+# Adding another level of indirection (the 2 nested :U expressions) helps.
+.if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
+.  warning unexpected
+.endif
+
+
+# Multiple indirect modifiers can be applied one after another as long as
+# they are separated with colons.
+.if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
+.  warning unexpected
+.endif
+
+
+# An indirect variable that evaluates to the empty string is allowed though.
+# This makes it possible to define conditional modifiers, like this:
+#
+# M.little-endian=	S,1234,4321,
+# M.big-endian=		# none
+.if ${value:L:${:Dempty}S,a,A,} != "vAlue"
+.  warning unexpected
+.endif
+
+
 # The nested variable expression expands to "tu", and this is interpreted as
 # a variable 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:10:54 UTC 2020

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: opt-debug-lint.exp opt-debug-lint.mk

Log Message:
make(1): remove wrong error message for indirect modifier in lint mode


To generate a diff of this commit:
cvs rdiff -u -r1.752 -r1.753 src/usr.bin/make/var.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/opt-debug-lint.exp \
src/usr.bin/make/unit-tests/opt-debug-lint.mk

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.752 src/usr.bin/make/var.c:1.753
--- src/usr.bin/make/var.c:1.752	Sun Dec 20 19:02:28 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 19:10:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.752 2020/12/20 19:02:28 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.753 2020/12/20 19:10:53 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.752 2020/12/20 19:02:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.753 2020/12/20 19:10:53 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3455,12 +3455,6 @@ ApplyModifiersIndirect(ApplyModifiersSta
 	/* TODO: handle errors */
 
 	if (mods.str[0] != '\0' && *p != '\0' && *p != ':' && *p != st->endc) {
-		if (opts.lint)
-			Parse_Error(PARSE_FATAL,
-			"Missing delimiter ':' "
-			"after indirect modifier \"%.*s\"",
-			(int)(p - *pp), *pp);
-
 		FStr_Done();
 		return AMIR_APPLY_MODS;
 	}

Index: src/usr.bin/make/unit-tests/opt-debug-lint.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.11 src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.12
--- src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.11	Mon Oct  5 19:27:48 2020
+++ src/usr.bin/make/unit-tests/opt-debug-lint.exp	Sun Dec 20 19:10:53 2020
@@ -2,7 +2,6 @@ make: "opt-debug-lint.mk" line 19: Varia
 make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L"
 make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P"
-make: "opt-debug-lint.mk" line 67: Missing delimiter ':' after indirect modifier "${:UL}"
 make: Unknown modifier '$'
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
Index: src/usr.bin/make/unit-tests/opt-debug-lint.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.11 src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.12
--- src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.11	Sat Oct 24 08:50:17 2020
+++ src/usr.bin/make/unit-tests/opt-debug-lint.mk	Sun Dec 20 19:10:53 2020
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-lint.mk,v 1.11 2020/10/24 08:50:17 rillig Exp $
+# $NetBSD: opt-debug-lint.mk,v 1.12 2020/12/20 19:10:53 rillig Exp $
 #
 # Tests for the -dL command line option, which runs additional checks
 # to catch common mistakes, such as unclosed variable expressions.
@@ -62,11 +62,20 @@ ${UNDEF}: ${UNDEF}
 .  error
 .endif
 
-# Since 2020-10-03, in lint mode the variable modifier must be separated
-# by colons.  See varparse-mod.mk.
+# Between 2020-10-03 and var.c 1.752 from 2020-12-20, in lint mode the
+# variable modifier had to be separated by colons.  This was wrong though
+# since make always fell back trying to parse the indirect modifier as a
+# SysV modifier.
 .if ${value:${:UL}PL} != "LPL}"		# FIXME: "LPL}" is unexpected here.
 .  error ${value:${:UL}PL}
 .endif
 
+# Typically, an indirect modifier is followed by a colon or the closing
+# brace.  This one isn't, therefore make falls back to parsing it as the SysV
+# modifier ":lue=lid".
+.if ${value:L:${:Ulue}=${:Ulid}} != "valid"
+.  error
+.endif
+
 all:
 	@:;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 19:02:28 UTC 2020

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

Log Message:
make(1): document that indirect modifiers fall back to SysV modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.751 -r1.752 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.751 src/usr.bin/make/var.c:1.752
--- src/usr.bin/make/var.c:1.751	Sun Dec 20 18:23:24 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 19:02:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.751 2020/12/20 18:23:24 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.752 2020/12/20 19:02:28 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.751 2020/12/20 18:23:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.752 2020/12/20 19:02:28 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3420,13 +3420,30 @@ static char *ApplyModifiers(const char *
 			VarExprFlags *, GNode *, VarEvalFlags, void **);
 
 typedef enum ApplyModifiersIndirectResult {
+	/* The indirect modifiers have been applied successfully. */
 	AMIR_CONTINUE,
+	/* Fall back to the SysV modifier. */
 	AMIR_APPLY_MODS,
+	/* Error out. */
 	AMIR_OUT
 } ApplyModifiersIndirectResult;
 
-/* While expanding a variable expression, expand and apply indirect
- * modifiers such as in ${VAR:${M_indirect}}. */
+/*
+ * While expanding a variable expression, expand and apply indirect modifiers,
+ * such as in ${VAR:${M_indirect}}.
+ *
+ * All indirect modifiers of a group must come from a single variable
+ * expression.  ${VAR:${M1}} is valid but ${VAR:${M1}${M2}} is not.
+ *
+ * Multiple groups of indirect modifiers can be chained by separating them
+ * with colons.  ${VAR:${M1}:${M2}} contains 2 indirect modifiers.
+ *
+ * If the variable expression is not followed by st->endc or ':', fall
+ * back to trying the SysV modifier, such as in ${VAR:${FROM}=${TO}}.
+ *
+ * The expression ${VAR:${M1}${M2}} is not treated as an indirect
+ * modifier, and it is neither a SysV modifier but a parse error.
+ */
 static ApplyModifiersIndirectResult
 ApplyModifiersIndirect(ApplyModifiersState *st, const char **pp,
 		   char **inout_val, void **inout_freeIt)
@@ -3437,11 +3454,6 @@ ApplyModifiersIndirect(ApplyModifiersSta
 	(void)Var_Parse(, st->ctxt, st->eflags, );
 	/* TODO: handle errors */
 
-	/*
-	 * If we have not parsed up to st->endc or ':', we are not
-	 * interested.  This means the expression ${VAR:${M1}${M2}}
-	 * is not accepted, but ${VAR:${M1}:${M2}} is.
-	 */
 	if (mods.str[0] != '\0' && *p != '\0' && *p != ':' && *p != st->endc) {
 		if (opts.lint)
 			Parse_Error(PARSE_FATAL,
@@ -3450,9 +3462,6 @@ ApplyModifiersIndirect(ApplyModifiersSta
 			(int)(p - *pp), *pp);
 
 		FStr_Done();
-		/* XXX: apply_mods doesn't sound like "not interested". */
-		/* XXX: Why is the indirect modifier parsed once more by
-		 * apply_mods?  Try *pp = p here. */
 		return AMIR_APPLY_MODS;
 	}
 
@@ -3606,8 +3615,9 @@ ApplyModifiers(
 			if (amir == AMIR_CONTINUE)
 continue;
 			if (amir == AMIR_OUT)
-goto out;
+break;
 		}
+
 		st.newVal = var_Error;	/* default value, in case of errors */
 		mod = p;
 
@@ -3618,7 +3628,7 @@ ApplyModifiers(
 		if (res == AMR_BAD)
 			goto bad_modifier;
 	}
-out:
+
 	*pp = p;
 	assert(val != NULL);	/* Use var_Error or varUndefined instead. */
 	*exprFlags = st.exprFlags;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 18:23:24 UTC 2020

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

Log Message:
make(1): remove redundant const declarations for parameters


To generate a diff of this commit:
cvs rdiff -u -r1.507 -r1.508 src/usr.bin/make/parse.c
cvs rdiff -u -r1.750 -r1.751 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/parse.c
diff -u src/usr.bin/make/parse.c:1.507 src/usr.bin/make/parse.c:1.508
--- src/usr.bin/make/parse.c:1.507	Sun Dec 20 14:52:16 2020
+++ src/usr.bin/make/parse.c	Sun Dec 20 18:23:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.508 2020/12/20 18:23:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.508 2020/12/20 18:23:24 rillig Exp $");
 
 /* types and constants */
 
@@ -2724,7 +2724,7 @@ ParseRawLine(IFile *curFile, char **out_
  * with a single space.
  */
 static void
-UnescapeBackslash(char *const line, char *start)
+UnescapeBackslash(char *line, char *start)
 {
 	char *src = start;
 	char *dst = start;

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.750 src/usr.bin/make/var.c:1.751
--- src/usr.bin/make/var.c:1.750	Sun Dec 20 18:13:50 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 18:23:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.750 2020/12/20 18:13:50 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.751 2020/12/20 18:23: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.750 2020/12/20 18:13:50 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.751 2020/12/20 18:23:24 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3488,9 +3488,9 @@ ApplyModifiersIndirect(ApplyModifiersSta
 }
 
 static ApplyModifierResult
-ApplySingleModifier(ApplyModifiersState *const st, const char *const mod,
-		char const endc, const char **pp, char *val,
-		char **out_val, void **const inout_freeIt)
+ApplySingleModifier(ApplyModifiersState *st, const char *mod, char endc,
+		const char **pp, char *val, char **out_val,
+		void **inout_freeIt)
 {
 	ApplyModifierResult res;
 	const char *p = *pp;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 18:13:50 UTC 2020

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

Log Message:
make(1): extract ApplySingleModifier from ApplyModifiers


To generate a diff of this commit:
cvs rdiff -u -r1.749 -r1.750 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.749 src/usr.bin/make/var.c:1.750
--- src/usr.bin/make/var.c:1.749	Sun Dec 20 17:22:10 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 18:13:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.749 2020/12/20 17:22:10 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.750 2020/12/20 18:13:50 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.749 2020/12/20 17:22:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.750 2020/12/20 18:13:50 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3487,6 +3487,78 @@ ApplyModifiersIndirect(ApplyModifiersSta
 	return AMIR_CONTINUE;
 }
 
+static ApplyModifierResult
+ApplySingleModifier(ApplyModifiersState *const st, const char *const mod,
+		char const endc, const char **pp, char *val,
+		char **out_val, void **const inout_freeIt)
+{
+	ApplyModifierResult res;
+	const char *p = *pp;
+
+	if (DEBUG(VAR))
+		LogBeforeApply(st, mod, endc, val);
+
+	res = ApplyModifier(, val, st);
+
+#ifdef SYSVVARSUB
+	if (res == AMR_UNKNOWN) {
+		assert(p == mod);
+		res = ApplyModifier_SysV(, val, st);
+	}
+#endif
+
+	if (res == AMR_UNKNOWN) {
+		Error("Unknown modifier '%c'", *mod);
+		/*
+		 * Guess the end of the current modifier.
+		 * XXX: Skipping the rest of the modifier hides
+		 * errors and leads to wrong results.
+		 * Parsing should rather stop here.
+		 */
+		for (p++; *p != ':' && *p != st->endc && *p != '\0'; p++)
+			continue;
+		st->newVal = var_Error;
+	}
+	if (res == AMR_CLEANUP || res == AMR_BAD) {
+		*out_val = val;
+		*pp = p;
+		return res;
+	}
+
+	if (DEBUG(VAR))
+		LogAfterApply(st, p, mod);
+
+	if (st->newVal != val) {
+		if (*inout_freeIt != NULL) {
+			assert(*inout_freeIt == val);
+			free(*inout_freeIt);
+			*inout_freeIt = NULL;
+		}
+		val = st->newVal;
+		if (val != var_Error && val != varUndefined)
+			*inout_freeIt = val;
+	}
+	if (*p == '\0' && st->endc != '\0') {
+		Error(
+		"Unclosed variable specification (expecting '%c') "
+		"for \"%s\" (value \"%s\") modifier %c",
+		st->endc, st->var->name.str, val, *mod);
+	} else if (*p == ':') {
+		p++;
+	} else if (opts.lint && *p != '\0' && *p != endc) {
+		Parse_Error(PARSE_FATAL,
+		"Missing delimiter ':' after modifier \"%.*s\"",
+		(int)(p - mod), mod);
+		/*
+		 * TODO: propagate parse error to the enclosing
+		 * expression
+		 */
+	}
+	*pp = p;
+	*out_val = val;
+	return AMR_OK;
+}
+
 /* Apply any modifiers (such as :Mpattern or :@var@loop@ or :Q or ::=value). */
 static char *
 ApplyModifiers(
@@ -3510,7 +3582,6 @@ ApplyModifiers(
 	};
 	const char *p;
 	const char *mod;
-	ApplyModifierResult res;
 
 	assert(startc == '(' || startc == '{' || startc == '\0');
 	assert(endc == ')' || endc == '}' || endc == '\0');
@@ -3526,6 +3597,7 @@ ApplyModifiers(
 	}
 
 	while (*p != '\0' && *p != endc) {
+		ApplyModifierResult res;
 
 		if (*p == '$') {
 			ApplyModifiersIndirectResult amir;
@@ -3539,64 +3611,12 @@ ApplyModifiers(
 		st.newVal = var_Error;	/* default value, in case of errors */
 		mod = p;
 
-		if (DEBUG(VAR))
-			LogBeforeApply(, mod, endc, val);
-
-		res = ApplyModifier(, val, );
-
-#ifdef SYSVVARSUB
-		if (res == AMR_UNKNOWN) {
-			assert(p == mod);
-			res = ApplyModifier_SysV(, val, );
-		}
-#endif
-
-		if (res == AMR_UNKNOWN) {
-			Error("Unknown modifier '%c'", *mod);
-			/*
-			 * Guess the end of the current modifier.
-			 * XXX: Skipping the rest of the modifier hides
-			 * errors and leads to wrong results.
-			 * Parsing should rather stop here.
-			 */
-			for (p++; *p != ':' && *p != st.endc && *p != '\0'; p++)
-continue;
-			st.newVal = var_Error;
-		}
+		res = ApplySingleModifier(, mod, endc, , val, ,
+		inout_freeIt);
 		if (res == AMR_CLEANUP)
 			goto cleanup;
 		if (res == AMR_BAD)
 			goto bad_modifier;
-
-		if (DEBUG(VAR))
-			LogAfterApply(, p, mod);
-
-		if (st.newVal != val) {
-			if (*inout_freeIt != NULL) {
-assert(*inout_freeIt == val);
-free(*inout_freeIt);
-*inout_freeIt = NULL;
-			}
-			val = st.newVal;
-			if (val != var_Error && val != varUndefined)
-*inout_freeIt = val;
-		}
-		if (*p == '\0' && st.endc != '\0') {
-			Error(
-			"Unclosed variable specification (expecting '%c') "
-			"for \"%s\" (value \"%s\") modifier %c",
-			st.endc, st.var->name.str, val, *mod);
-		} else if (*p == ':') {
-			p++;
-		} else if (opts.lint && *p != '\0' && *p != endc) {
-			Parse_Error(PARSE_FATAL,
-			"Missing 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 17:22:11 UTC 2020

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

Log Message:
make(1): turn ApplyModifiersState.val into a local variable

This reduces the scope and makes it more obvious at which places this
variable can be changed and how the memory management is done.


To generate a diff of this commit:
cvs rdiff -u -r1.748 -r1.749 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.748 src/usr.bin/make/var.c:1.749
--- src/usr.bin/make/var.c:1.748	Sun Dec 20 15:31:29 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 17:22:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.748 2020/12/20 15:31:29 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.749 2020/12/20 17:22:10 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.748 2020/12/20 15:31:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.749 2020/12/20 17:22:10 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1927,11 +1927,6 @@ typedef struct ApplyModifiersState {
 	GNode *const ctxt;
 	const VarEvalFlags eflags;
 	/*
-	 * The old value of the expression, before applying the modifier,
-	 * never NULL.
-	 */
-	char *val;
-	/*
 	 * The new value of the expression, after applying the modifier,
 	 * never NULL.
 	 */
@@ -2201,7 +2196,7 @@ TryParseChar(const char **pp, int base, 
 
 /* :@var@...${var}...@ */
 static ApplyModifierResult
-ApplyModifier_Loop(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Loop(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	struct ModifyWord_LoopArgs args;
 	char prev_sep;
@@ -2230,7 +2225,7 @@ ApplyModifier_Loop(const char **pp, Appl
 	args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 	prev_sep = st->sep;
 	st->sep = ' ';		/* XXX: should be st->sep for consistency */
-	st->newVal = ModifyWords(st->val, ModifyWord_Loop, ,
+	st->newVal = ModifyWords(val, ModifyWord_Loop, ,
 	st->oneBigWord, st->sep);
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2242,7 +2237,7 @@ ApplyModifier_Loop(const char **pp, Appl
 
 /* :Ddefined or :Uundefined */
 static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Defined(const char **pp, char *val, ApplyModifiersState *st)
 {
 	Buffer buf;
 	const char *p;
@@ -2293,7 +2288,7 @@ ApplyModifier_Defined(const char **pp, A
 	if (eflags & VARE_WANTRES) {
 		st->newVal = Buf_Destroy(, FALSE);
 	} else {
-		st->newVal = st->val;
+		st->newVal = val;
 		Buf_Destroy(, TRUE);
 	}
 	return AMR_OK;
@@ -2330,7 +2325,7 @@ TryParseTime(const char **pp, time_t *ou
 
 /* :gmtime */
 static ApplyModifierResult
-ApplyModifier_Gmtime(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Gmtime(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	time_t utc;
 
@@ -2350,13 +2345,14 @@ ApplyModifier_Gmtime(const char **pp, Ap
 		utc = 0;
 		*pp = mod + 6;
 	}
-	st->newVal = VarStrftime(st->val, TRUE, utc);
+	st->newVal = VarStrftime(val, TRUE, utc);
 	return AMR_OK;
 }
 
 /* :localtime */
 static ApplyModifierResult
-ApplyModifier_Localtime(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Localtime(const char **pp, const char *val,
+			ApplyModifiersState *st)
 {
 	time_t utc;
 
@@ -2376,18 +2372,18 @@ ApplyModifier_Localtime(const char **pp,
 		utc = 0;
 		*pp = mod + 9;
 	}
-	st->newVal = VarStrftime(st->val, FALSE, utc);
+	st->newVal = VarStrftime(val, FALSE, utc);
 	return AMR_OK;
 }
 
 /* :hash */
 static ApplyModifierResult
-ApplyModifier_Hash(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Hash(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	if (!ModMatch(*pp, "hash", st->endc))
 		return AMR_UNKNOWN;
 
-	st->newVal = VarHash(st->val);
+	st->newVal = VarHash(val);
 	*pp += 4;
 	return AMR_OK;
 }
@@ -2448,7 +2444,7 @@ ApplyModifier_ShellCommand(const char **
 /* The :range modifier generates an integer sequence as long as the words.
  * The :range=7 modifier generates an integer sequence from 1 to 7. */
 static ApplyModifierResult
-ApplyModifier_Range(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Range(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	size_t n;
 	Buffer buf;
@@ -2472,7 +2468,7 @@ ApplyModifier_Range(const char **pp, App
 	}
 
 	if (n == 0) {
-		Words words = Str_Words(st->val, FALSE);
+		Words words = Str_Words(val, FALSE);
 		n = words.len;
 		Words_Free(words);
 	}
@@ -2493,7 +2489,7 @@ ApplyModifier_Range(const char **pp, App
 
 /* :Mpattern or :Npattern */
 static ApplyModifierResult
-ApplyModifier_Match(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Match(const char **pp, const char *val, ApplyModifiersState *st)
 {
 	

CVS commit: src/sys

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 16:38:26 UTC 2020

Modified Files:
src/sys/arch/m68k/include: pmap_coldfire.h
src/sys/arch/mips/include: pmap.h
src/sys/arch/mips/mips: pmap_machdep.c
src/sys/arch/powerpc/booke: booke_pmap.c
src/sys/arch/powerpc/include/booke: pmap.h
src/sys/arch/riscv/include: pmap.h
src/sys/arch/riscv/riscv: trap.c
src/sys/uvm: uvm_page.h
src/sys/uvm/pmap: pmap.c pmap.h vmpagemd.h

Log Message:
Support __HAVE_PMAP_PV_TRACK in sys/uvm/pmap based pmaps (aka common pmap)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/m68k/include/pmap_coldfire.h
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/mips/include/pmap.h
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/mips/mips/pmap_machdep.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/booke/booke_pmap.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/powerpc/include/booke/pmap.h
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/riscv/include/pmap.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/riscv/riscv/trap.c
cvs rdiff -u -r1.108 -r1.109 src/sys/uvm/uvm_page.h
cvs rdiff -u -r1.57 -r1.58 src/sys/uvm/pmap/pmap.c
cvs rdiff -u -r1.17 -r1.18 src/sys/uvm/pmap/pmap.h
cvs rdiff -u -r1.16 -r1.17 src/sys/uvm/pmap/vmpagemd.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/m68k/include/pmap_coldfire.h
diff -u src/sys/arch/m68k/include/pmap_coldfire.h:1.3 src/sys/arch/m68k/include/pmap_coldfire.h:1.4
--- src/sys/arch/m68k/include/pmap_coldfire.h:1.3	Fri Aug  7 07:19:45 2020
+++ src/sys/arch/m68k/include/pmap_coldfire.h	Sun Dec 20 16:38:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_coldfire.h,v 1.3 2020/08/07 07:19:45 skrll Exp $	*/
+/*	$NetBSD: pmap_coldfire.h,v 1.4 2020/12/20 16:38:25 skrll Exp $	*/
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -92,7 +92,7 @@ vaddr_t	pmap_kvptefill(vaddr_t, vaddr_t,
 #endif
 #endif
 
-void	pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
+void	pmap_md_page_syncicache(struct vm_page_md *, const kcpuset_t *);
 vaddr_t	pmap_bootstrap(vaddr_t, vaddr_t, phys_ram_seg_t *, size_t);
 bool	pmap_extract(struct pmap *, vaddr_t, paddr_t *);
 
@@ -114,7 +114,7 @@ vtophys(vaddr_t va)
  * Virtual Cache Alias helper routines.  Not a problem for Booke CPUs.
  */
 static inline bool
-pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
+pmap_md_vca_add(struct vm_page_md *mdpg, vaddr_t va, pt_entry_t *nptep)
 {
 	return false;
 }
@@ -126,7 +126,7 @@ pmap_md_vca_remove(struct vm_page *pg, v
 }
 
 static inline void
-pmap_md_vca_clean(struct vm_page *pg, vaddr_t va, int op)
+pmap_md_vca_clean(struct vm_page_md *mdpg, vaddr_t va, int op)
 {
 }
 

Index: src/sys/arch/mips/include/pmap.h
diff -u src/sys/arch/mips/include/pmap.h:1.74 src/sys/arch/mips/include/pmap.h:1.75
--- src/sys/arch/mips/include/pmap.h:1.74	Mon Aug 17 03:19:35 2020
+++ src/sys/arch/mips/include/pmap.h	Sun Dec 20 16:38:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.74 2020/08/17 03:19:35 mrg Exp $	*/
+/*	$NetBSD: pmap.h,v 1.75 2020/12/20 16:38:25 skrll Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,6 +93,7 @@ typedef uint32_t pt_entry_t;
 #define	KERNEL_PID			0
 
 #if defined(__PMAP_PRIVATE)
+struct vm_page_md;
 
 #include 
 #include 
@@ -122,9 +123,9 @@ typedef uint32_t pt_entry_t;
 void	pmap_md_init(void);
 void	pmap_md_icache_sync_all(void);
 void	pmap_md_icache_sync_range_index(vaddr_t, vsize_t);
-void	pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
-bool	pmap_md_vca_add(struct vm_page *, vaddr_t, pt_entry_t *);
-void	pmap_md_vca_clean(struct vm_page *, int);
+void	pmap_md_page_syncicache(struct vm_page_md *, const kcpuset_t *);
+bool	pmap_md_vca_add(struct vm_page_md *, vaddr_t, pt_entry_t *);
+void	pmap_md_vca_clean(struct vm_page_md *, int);
 void	pmap_md_vca_remove(struct vm_page *, vaddr_t, bool, bool);
 bool	pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
 bool	pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
@@ -178,6 +179,7 @@ struct tlbmask {
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -270,5 +272,13 @@ int sbmips_cca_for_pa(paddr_t);
 #define	PMAP_CCA_FOR_PA(pa)	sbmips_cca_for_pa(pa)
 #endif
 
+#ifdef __HAVE_PMAP_PV_TRACK
+struct pmap_page {
+struct vm_page_md   pp_md;
+};
+
+#define PMAP_PAGE_TO_MD(ppage)  (&((ppage)->pp_md))
+#endif
+
 #endif	/* _KERNEL */
 #endif	/* _MIPS_PMAP_H_ */

Index: src/sys/arch/mips/mips/pmap_machdep.c
diff -u src/sys/arch/mips/mips/pmap_machdep.c:1.32 src/sys/arch/mips/mips/pmap_machdep.c:1.33
--- src/sys/arch/mips/mips/pmap_machdep.c:1.32	Sun Dec 20 15:59:28 2020
+++ src/sys/arch/mips/mips/pmap_machdep.c	Sun Dec 20 16:38:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.c,v 1.32 2020/12/20 15:59:28 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.c,v 1.33 2020/12/20 16:38:25 skrll Exp $	*/
 
 /*-
  * 

CVS commit: src/sys/arch/mips/mips

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 15:59:28 UTC 2020

Modified Files:
src/sys/arch/mips/mips: pmap_machdep.c

Log Message:
Remove bogus KASSERT - can't assert a spin mutex is !mutex_owned.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/mips/mips/pmap_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/mips/pmap_machdep.c
diff -u src/sys/arch/mips/mips/pmap_machdep.c:1.31 src/sys/arch/mips/mips/pmap_machdep.c:1.32
--- src/sys/arch/mips/mips/pmap_machdep.c:1.31	Sun Dec 20 12:27:20 2020
+++ src/sys/arch/mips/mips/pmap_machdep.c	Sun Dec 20 15:59:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.c,v 1.31 2020/12/20 12:27:20 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.c,v 1.32 2020/12/20 15:59:28 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.31 2020/12/20 12:27:20 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.32 2020/12/20 15:59:28 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -1025,7 +1025,6 @@ pmap_md_vca_remove(struct vm_page *pg, v
 		return;
 
 	KASSERT(kpreempt_disabled());
-	KASSERT(!VM_PAGEMD_PVLIST_LOCKED_P(mdpg));
 	KASSERT((va & PAGE_MASK) == 0);
 
 	/*



CVS commit: src/sys/uvm

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 15:50:44 UTC 2020

Modified Files:
src/sys/uvm: uvm_page.h

Log Message:
Remove VM_MD_TO_PAGE that was accidentally committed in 1.106.  It's going
to be readded with the code that uses it


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/uvm/uvm_page.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.107 src/sys/uvm/uvm_page.h:1.108
--- src/sys/uvm/uvm_page.h:1.107	Wed Oct  7 17:51:50 2020
+++ src/sys/uvm/uvm_page.h	Sun Dec 20 15:50:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.h,v 1.107 2020/10/07 17:51:50 chs Exp $	*/
+/*	$NetBSD: uvm_page.h,v 1.108 2020/12/20 15:50:44 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -406,7 +406,6 @@ int uvm_direct_process(struct vm_page **
 
 #ifdef __HAVE_VM_PAGE_MD
 #define	VM_PAGE_TO_MD(pg)	(&(pg)->mdpage)
-#define	VM_MD_TO_PAGE(md)	(container_of((md), struct vm_page, mdpage))
 #endif
 
 /*



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 15:31:29 UTC 2020

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

Log Message:
make(1): use FStr for memory management in Var_SetWithFlags


To generate a diff of this commit:
cvs rdiff -u -r1.747 -r1.748 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.747 src/usr.bin/make/var.c:1.748
--- src/usr.bin/make/var.c:1.747	Sun Dec 20 15:26:40 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 15:31:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.747 2020/12/20 15:26:40 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.748 2020/12/20 15:31:29 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.747 2020/12/20 15:26:40 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.748 2020/12/20 15:31:29 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -949,27 +949,25 @@ Var_SetWithFlags(const char *name, const
 		 VarSetFlags flags)
 {
 	const char *unexpanded_name = name;
-	char *name_freeIt = NULL;
+	FStr varname = FStr_InitRefer(name);
 
 	assert(val != NULL);
 
-	if (strchr(name, '$') != NULL) {
-		(void)Var_Subst(name, ctxt, VARE_WANTRES, _freeIt);
+	if (strchr(varname.str, '$') != NULL) {
+		char *expanded;
+		(void)Var_Subst(varname.str, ctxt, VARE_WANTRES, );
 		/* TODO: handle errors */
-		name = name_freeIt;
+		varname = FStr_InitOwn(expanded);
 	}
 
-	if (name[0] == '\0') {
+	if (varname.str[0] == '\0') {
 		DEBUG2(VAR, "Var_Set(\"%s\", \"%s\", ...) "
 			"name expands to empty string - ignored\n",
 		unexpanded_name, val);
-		free(name_freeIt);
-		return;
-	}
-
-	SetVar(name, val, ctxt, flags);
+	} else
+		SetVar(varname.str, val, ctxt, flags);
 
-	free(name_freeIt);
+	FStr_Done();
 }
 
 /*



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 15:26:40 UTC 2020

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

Log Message:
make(1): extract SetVar from Var_SetWithFlags

SetVar contains the part that is not concerned about memory management
and expansion of the variable name.


To generate a diff of this commit:
cvs rdiff -u -r1.746 -r1.747 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.746 src/usr.bin/make/var.c:1.747
--- src/usr.bin/make/var.c:1.746	Sun Dec 20 15:04:29 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 15:26:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.746 2020/12/20 15:04:29 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.747 2020/12/20 15:26:40 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.746 2020/12/20 15:04:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.747 2020/12/20 15:26:40 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -866,38 +866,19 @@ Var_UnExport(Boolean isEnv, const char *
 	FStr_Done();
 }
 
-/* See Var_Set for documentation. */
-void
-Var_SetWithFlags(const char *name, const char *val, GNode *ctxt,
-		 VarSetFlags flags)
+/* Set the variable to the value; the name is not expanded. */
+static void
+SetVar(const char *name, const char *val, GNode *ctxt, VarSetFlags flags)
 {
-	const char *unexpanded_name = name;
-	char *name_freeIt = NULL;
 	Var *v;
 
-	assert(val != NULL);
-
-	if (strchr(name, '$') != NULL) {
-		(void)Var_Subst(name, ctxt, VARE_WANTRES, _freeIt);
-		/* TODO: handle errors */
-		name = name_freeIt;
-	}
-
-	if (name[0] == '\0') {
-		DEBUG2(VAR, "Var_Set(\"%s\", \"%s\", ...) "
-			"name expands to empty string - ignored\n",
-		unexpanded_name, val);
-		free(name_freeIt);
-		return;
-	}
-
 	if (ctxt == VAR_GLOBAL) {
 		v = VarFind(name, VAR_CMDLINE, FALSE);
 		if (v != NULL) {
 			if (v->flags & VAR_FROM_CMD) {
 DEBUG3(VAR, "%s:%s = %s ignored!\n",
 ctxt->name, name, val);
-goto out;
+return;
 			}
 			VarFreeEnv(v, TRUE);
 		}
@@ -924,7 +905,7 @@ Var_SetWithFlags(const char *name, const
 		if ((v->flags & VAR_READONLY) && !(flags & VAR_SET_READONLY)) {
 			DEBUG3(VAR, "%s:%s = %s ignored (read-only)\n",
 			ctxt->name, name, val);
-			goto out;
+			return;
 		}
 		Buf_Empty(>val);
 		Buf_AddStr(>val, val);
@@ -958,12 +939,39 @@ Var_SetWithFlags(const char *name, const
 	if (name[0] == '.' && strcmp(name, MAKE_SAVE_DOLLARS) == 0)
 		save_dollars = ParseBoolean(val, save_dollars);
 
-out:
-	free(name_freeIt);
 	if (v != NULL)
 		VarFreeEnv(v, TRUE);
 }
 
+/* See Var_Set for documentation. */
+void
+Var_SetWithFlags(const char *name, const char *val, GNode *ctxt,
+		 VarSetFlags flags)
+{
+	const char *unexpanded_name = name;
+	char *name_freeIt = NULL;
+
+	assert(val != NULL);
+
+	if (strchr(name, '$') != NULL) {
+		(void)Var_Subst(name, ctxt, VARE_WANTRES, _freeIt);
+		/* TODO: handle errors */
+		name = name_freeIt;
+	}
+
+	if (name[0] == '\0') {
+		DEBUG2(VAR, "Var_Set(\"%s\", \"%s\", ...) "
+			"name expands to empty string - ignored\n",
+		unexpanded_name, val);
+		free(name_freeIt);
+		return;
+	}
+
+	SetVar(name, val, ctxt, flags);
+
+	free(name_freeIt);
+}
+
 /*
  * Set the variable name to the value val in the given context.
  *
@@ -1077,17 +1085,18 @@ Var_Append(const char *name, const char 
 Boolean
 Var_Exists(const char *name, GNode *ctxt)
 {
-	char *name_freeIt = NULL;
+	FStr varname = FStr_InitRefer(name);
 	Var *v;
 
-	if (strchr(name, '$') != NULL) {
-		(void)Var_Subst(name, ctxt, VARE_WANTRES, _freeIt);
+	if (strchr(varname.str, '$') != NULL) {
+		char *expanded;
+		(void)Var_Subst(varname.str, ctxt, VARE_WANTRES, );
 		/* TODO: handle errors */
-		name = name_freeIt;
+		varname = FStr_InitOwn(expanded);
 	}
 
-	v = VarFind(name, ctxt, TRUE);
-	free(name_freeIt);
+	v = VarFind(varname.str, ctxt, TRUE);
+	FStr_Done();
 	if (v == NULL)
 		return FALSE;
 



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 15:04:29 UTC 2020

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

Log Message:
make(1): fix memory leak in Var_Delete (since yesterday)

The memory leak had been introduced in var.c 1.736 from 2020-12-19
20:47:24.


To generate a diff of this commit:
cvs rdiff -u -r1.745 -r1.746 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.745 src/usr.bin/make/var.c:1.746
--- src/usr.bin/make/var.c:1.745	Sun Dec 20 14:32:13 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 15:04:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.745 2020/12/20 14:32:13 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.746 2020/12/20 15:04:29 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.745 2020/12/20 14:32:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.746 2020/12/20 15:04:29 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -498,15 +498,18 @@ Var_DeleteVar(const char *varname, GNode
 void
 Var_Delete(const char *name, GNode *ctxt)
 {
-	char *name_freeIt = NULL;
+	FStr varname = FStr_InitRefer(name);
 
-	if (strchr(name, '$') != NULL) {
-		(void)Var_Subst(name, VAR_GLOBAL, VARE_WANTRES, _freeIt);
+	if (strchr(varname.str, '$') != NULL) {
+		char *expanded;
+		(void)Var_Subst(varname.str, VAR_GLOBAL, VARE_WANTRES,
+		);
 		/* TODO: handle errors */
-		name = name_freeIt;
+		varname = FStr_InitOwn(expanded);
 	}
 
-	Var_DeleteVar(name, ctxt);
+	Var_DeleteVar(varname.str, ctxt);
+	FStr_Done();
 }
 
 /*



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 14:52:16 UTC 2020

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

Log Message:
make(1): clean up memory handling in VarAssign_EvalShell


To generate a diff of this commit:
cvs rdiff -u -r1.506 -r1.507 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.506 src/usr.bin/make/parse.c:1.507
--- src/usr.bin/make/parse.c:1.506	Sun Dec 20 14:48:35 2020
+++ src/usr.bin/make/parse.c	Sun Dec 20 14:52:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $");
 
 /* types and constants */
 
@@ -1962,27 +1962,27 @@ static void
 VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt,
 		FStr *out_avalue)
 {
-	const char *cmd, *errfmt;
+	FStr cmd;
+	const char *errfmt;
 	char *cmdOut;
-	void *cmd_freeIt = NULL;
 
-	cmd = uvalue;
-	if (strchr(cmd, '$') != NULL) {
-		char *ecmd;
-		(void)Var_Subst(cmd, VAR_CMDLINE, VARE_WANTRES | VARE_UNDEFERR,
-		);
+	cmd = FStr_InitRefer(uvalue);
+	if (strchr(cmd.str, '$') != NULL) {
+		char *expanded;
+		(void)Var_Subst(cmd.str, VAR_CMDLINE,
+		VARE_WANTRES | VARE_UNDEFERR, );
 		/* TODO: handle errors */
-		cmd = cmd_freeIt = ecmd;
+		cmd = FStr_InitOwn(expanded);
 	}
 
-	cmdOut = Cmd_Exec(cmd, );
+	cmdOut = Cmd_Exec(cmd.str, );
 	Var_Set(name, cmdOut, ctxt);
 	*out_avalue = FStr_InitOwn(cmdOut);
 
 	if (errfmt != NULL)
 		Parse_Error(PARSE_WARNING, errfmt, cmd);
 
-	free(cmd_freeIt);
+	FStr_Done();
 }
 
 /* Perform a variable assignment.



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 14:48:35 UTC 2020

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

Log Message:
make(1): clean up memory handling in Parse_DoVar


To generate a diff of this commit:
cvs rdiff -u -r1.505 -r1.506 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.505 src/usr.bin/make/parse.c:1.506
--- src/usr.bin/make/parse.c:1.505	Sun Dec 20 14:32:13 2020
+++ src/usr.bin/make/parse.c	Sun Dec 20 14:48:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.505 2020/12/20 14:32:13 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.505 2020/12/20 14:32:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $");
 
 /* types and constants */
 
@@ -1925,7 +1925,7 @@ VarCheckSyntax(VarAssignOp type, const c
 
 static void
 VarAssign_EvalSubst(const char *name, const char *uvalue, GNode *ctxt,
-		const char **out_avalue, void **out_avalue_freeIt)
+		FStr *out_avalue)
 {
 	const char *avalue;
 	char *evalue;
@@ -1955,13 +1955,12 @@ VarAssign_EvalSubst(const char *name, co
 	avalue = evalue;
 	Var_Set(name, avalue, ctxt);
 
-	*out_avalue = avalue;
-	*out_avalue_freeIt = evalue;
+	*out_avalue = (FStr){ avalue, evalue };
 }
 
 static void
 VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt,
-		const char **out_avalue, void **out_avalue_freeIt)
+		FStr *out_avalue)
 {
 	const char *cmd, *errfmt;
 	char *cmdOut;
@@ -1978,7 +1977,7 @@ VarAssign_EvalShell(const char *name, co
 
 	cmdOut = Cmd_Exec(cmd, );
 	Var_Set(name, cmdOut, ctxt);
-	*out_avalue = *out_avalue_freeIt = cmdOut;
+	*out_avalue = FStr_InitOwn(cmdOut);
 
 	if (errfmt != NULL)
 		Parse_Error(PARSE_WARNING, errfmt, cmd);
@@ -1996,31 +1995,25 @@ VarAssign_EvalShell(const char *name, co
  * skipped if the operator is '?=' and the variable already exists. */
 static Boolean
 VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue,
-	   GNode *ctxt, const char **out_avalue, void **out_avalue_freeIt)
+	   GNode *ctxt, FStr *out_TRUE_avalue)
 {
-	const char *avalue = uvalue;
-	void *avalue_freeIt = NULL;
+	FStr avalue = FStr_InitRefer(uvalue);
 
 	if (op == VAR_APPEND)
 		Var_Append(name, uvalue, ctxt);
 	else if (op == VAR_SUBST)
-		VarAssign_EvalSubst(name, uvalue, ctxt, ,
-		_freeIt);
+		VarAssign_EvalSubst(name, uvalue, ctxt, );
 	else if (op == VAR_SHELL)
-		VarAssign_EvalShell(name, uvalue, ctxt, ,
-		_freeIt);
+		VarAssign_EvalShell(name, uvalue, ctxt, );
 	else {
-		if (op == VAR_DEFAULT && Var_Exists(name, ctxt)) {
-			*out_avalue_freeIt = NULL;
+		if (op == VAR_DEFAULT && Var_Exists(name, ctxt))
 			return FALSE;
-		}
 
 		/* Normal assignment -- just do it. */
 		Var_Set(name, uvalue, ctxt);
 	}
 
-	*out_avalue = avalue;
-	*out_avalue_freeIt = avalue_freeIt;
+	*out_TRUE_avalue = avalue;
 	return TRUE;
 }
 
@@ -2047,15 +2040,14 @@ VarAssignSpecial(const char *name, const
 void
 Parse_DoVar(VarAssign *var, GNode *ctxt)
 {
-	const char *avalue;	/* actual value (maybe expanded) */
-	void *avalue_freeIt;
+	FStr avalue;	/* actual value (maybe expanded) */
 
 	VarCheckSyntax(var->op, var->value, ctxt);
-	if (VarAssign_Eval(var->varname, var->op, var->value, ctxt,
-	, _freeIt))
-		VarAssignSpecial(var->varname, avalue);
+	if (VarAssign_Eval(var->varname, var->op, var->value, ctxt, )) {
+		VarAssignSpecial(var->varname, avalue.str);
+		FStr_Done();
+	}
 
-	free(avalue_freeIt);
 	free(var->varname);
 }
 



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 14:39:46 UTC 2020

Modified Files:
src/usr.bin/make: main.c nonints.h

Log Message:
make(1): remove constant parameter from MakeMode


To generate a diff of this commit:
cvs rdiff -u -r1.499 -r1.500 src/usr.bin/make/main.c
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/make/nonints.h

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/main.c
diff -u src/usr.bin/make/main.c:1.499 src/usr.bin/make/main.c:1.500
--- src/usr.bin/make/main.c:1.499	Sun Dec 20 14:32:13 2020
+++ src/usr.bin/make/main.c	Sun Dec 20 14:39:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.500 2020/12/20 14:39:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.500 2020/12/20 14:39:46 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -807,33 +807,32 @@ siginfo(int signo MAKE_ATTR_UNUSED)
 }
 #endif
 
-/*
- * Allow makefiles some control over the mode we run in.
- */
-void
-MakeMode(const char *mode)
+/* Allow makefiles some control over the mode we run in. */
+static void
+MakeMode(void)
 {
-	char *mode_freeIt = NULL;
+	FStr mode = FStr_InitRefer(NULL);
 
-	if (mode == NULL) {
+	if (mode.str == NULL) {
+		char *expanded;
 		(void)Var_Subst("${" MAKE_MODE ":tl}",
-		VAR_GLOBAL, VARE_WANTRES, _freeIt);
+		VAR_GLOBAL, VARE_WANTRES, );
 		/* TODO: handle errors */
-		mode = mode_freeIt;
+		mode = FStr_InitOwn(expanded);
 	}
 
-	if (mode[0] != '\0') {
-		if (strstr(mode, "compat")) {
+	if (mode.str[0] != '\0') {
+		if (strstr(mode.str, "compat")) {
 			opts.compatMake = TRUE;
 			forceJobs = FALSE;
 		}
 #if USE_META
-		if (strstr(mode, "meta"))
-			meta_mode_init(mode);
+		if (strstr(mode.str, "meta"))
+			meta_mode_init(mode.str);
 #endif
 	}
 
-	free(mode_freeIt);
+	FStr_Done();
 }
 
 static void
@@ -1546,7 +1545,7 @@ main_PrepareMaking(void)
 	if (enterFlagObj)
 		printf("%s: Entering directory `%s'\n", progname, objdir);
 
-	MakeMode(NULL);
+	MakeMode();
 
 	{
 		FStr makeflags = Var_Value(MAKEFLAGS, VAR_GLOBAL);

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.178 src/usr.bin/make/nonints.h:1.179
--- src/usr.bin/make/nonints.h:1.178	Sun Dec 20 14:32:13 2020
+++ src/usr.bin/make/nonints.h	Sun Dec 20 14:39:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.178 2020/12/20 14:32:13 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.179 2020/12/20 14:39:46 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,6 @@ void JobReapChild(pid_t, int, Boolean);
 
 /* main.c */
 void Main_ParseArgLine(const char *);
-void MakeMode(const char *);
 char *Cmd_Exec(const char *, const char **);
 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 14:32:14 UTC 2020

Modified Files:
src/usr.bin/make: cond.c main.c meta.c nonints.h parse.c trace.c var.c

Log Message:
make(1): change return type of Var_Value to FStr


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 src/usr.bin/make/cond.c
cvs rdiff -u -r1.498 -r1.499 src/usr.bin/make/main.c
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/make/meta.c
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.504 -r1.505 src/usr.bin/make/parse.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/trace.c
cvs rdiff -u -r1.744 -r1.745 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/cond.c
diff -u src/usr.bin/make/cond.c:1.229 src/usr.bin/make/cond.c:1.230
--- src/usr.bin/make/cond.c:1.229	Sun Dec 20 13:38:43 2020
+++ src/usr.bin/make/cond.c	Sun Dec 20 14:32:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.230 2020/12/20 14:32:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.230 2020/12/20 14:32:13 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -286,9 +286,9 @@ ParseFuncArg(const char **pp, Boolean do
 static Boolean
 FuncDefined(size_t argLen MAKE_ATTR_UNUSED, const char *arg)
 {
-	void *freeIt;
-	Boolean result = Var_Value(arg, VAR_CMDLINE, ) != NULL;
-	bmake_free(freeIt);
+	FStr value = Var_Value(arg, VAR_CMDLINE);
+	Boolean result = value.str != NULL;
+	FStr_Done();
 	return result;
 }
 

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.498 src/usr.bin/make/main.c:1.499
--- src/usr.bin/make/main.c:1.498	Sun Dec 13 20:14:48 2020
+++ src/usr.bin/make/main.c	Sun Dec 20 14:32:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.498 2020/12/13 20:14:48 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.498 2020/12/13 20:14:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.499 2020/12/20 14:32:13 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -690,10 +690,9 @@ Main_ParseArgLine(const char *line)
 		return;
 
 	{
-		void *freeIt;
-		const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, );
-		buf = str_concat3(argv0, " ", line);
-		free(freeIt);
+		FStr argv0 = Var_Value(".MAKE", VAR_GLOBAL);
+		buf = str_concat3(argv0.str, " ", line);
+		FStr_Done();
 	}
 
 	words = Str_Words(buf, TRUE);
@@ -751,29 +750,27 @@ Main_SetObjdir(Boolean writable, const c
 static Boolean
 SetVarObjdir(Boolean writable, const char *var, const char *suffix)
 {
-	void *path_freeIt;
-	const char *path = Var_Value(var, VAR_CMDLINE, _freeIt);
-	const char *xpath;
-	char *xpath_freeIt;
+	FStr path = Var_Value(var, VAR_CMDLINE);
+	FStr xpath;
 
-	if (path == NULL || path[0] == '\0') {
-		bmake_free(path_freeIt);
+	if (path.str == NULL || path.str[0] == '\0') {
+		FStr_Done();
 		return FALSE;
 	}
 
 	/* expand variable substitutions */
-	xpath = path;
-	xpath_freeIt = NULL;
-	if (strchr(path, '$') != 0) {
-		(void)Var_Subst(path, VAR_GLOBAL, VARE_WANTRES, _freeIt);
+	xpath = FStr_InitRefer(path.str);
+	if (strchr(path.str, '$') != 0) {
+		char *expanded;
+		(void)Var_Subst(path.str, VAR_GLOBAL, VARE_WANTRES, );
 		/* TODO: handle errors */
-		xpath = xpath_freeIt;
+		xpath = FStr_InitOwn(expanded);
 	}
 
-	(void)Main_SetObjdir(writable, "%s%s", xpath, suffix);
+	(void)Main_SetObjdir(writable, "%s%s", xpath.str, suffix);
 
-	bmake_free(xpath_freeIt);
-	bmake_free(path_freeIt);
+	FStr_Done();
+	FStr_Done();
 	return TRUE;
 }
 
@@ -859,10 +856,9 @@ PrintVar(const char *varname, Boolean ex
 		bmake_free(evalue);
 
 	} else {
-		void *freeIt;
-		const char *value = Var_Value(varname, VAR_GLOBAL, );
-		printf("%s\n", value ? value : "");
-		bmake_free(freeIt);
+		FStr value = Var_Value(varname, VAR_GLOBAL);
+		printf("%s\n", value.str != NULL ? value.str : "");
+		FStr_Done();
 	}
 }
 
@@ -1047,21 +1043,20 @@ static void
 HandlePWD(const struct stat *curdir_st)
 {
 	char *pwd;
-	void *prefix_freeIt, *makeobjdir_freeIt;
-	const char *makeobjdir;
+	FStr prefix, makeobjdir;
 	struct stat pwd_st;
 
 	if (ignorePWD || (pwd = getenv("PWD")) == NULL)
 		return;
 
-	if (Var_Value("MAKEOBJDIRPREFIX", VAR_CMDLINE, _freeIt) !=
-	NULL) {
-		bmake_free(prefix_freeIt);
+	prefix = Var_Value("MAKEOBJDIRPREFIX", VAR_CMDLINE);
+	if (prefix.str != NULL) {
+		FStr_Done();

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 13:50:10 UTC 2020

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

Log Message:
make(1): use FStr in VarNew


To generate a diff of this commit:
cvs rdiff -u -r1.743 -r1.744 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.743 src/usr.bin/make/var.c:1.744
--- src/usr.bin/make/var.c:1.743	Sun Dec 20 13:38:43 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 13:50:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.743 2020/12/20 13:38:43 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.744 2020/12/20 13:50:10 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.743 2020/12/20 13:38:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.744 2020/12/20 13:50:10 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -301,12 +301,11 @@ static VarExportedMode var_exportedVars 
 
 
 static Var *
-VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags)
+VarNew(FStr name, const char *value, VarFlags flags)
 {
 	size_t value_len = strlen(value);
 	Var *var = bmake_malloc(sizeof *var);
-	var->name.str = name;
-	var->name.freeIt = name_freeIt;
+	var->name = name;
 	Buf_InitSize(>val, value_len + 1);
 	Buf_AddBytes(>val, value, value_len);
 	var->flags = flags;
@@ -416,7 +415,7 @@ VarFind(const char *name, GNode *ctxt, B
 
 		if ((env = getenv(name)) != NULL) {
 			char *varname = bmake_strdup(name);
-			return VarNew(varname, varname, env, VAR_FROM_ENV);
+			return VarNew(FStr_InitOwn(varname), env, VAR_FROM_ENV);
 		}
 
 		if (opts.checkEnvFirst && ctxt != VAR_GLOBAL) {
@@ -460,7 +459,7 @@ static void
 VarAdd(const char *name, const char *val, GNode *ctxt, VarSetFlags flags)
 {
 	HashEntry *he = HashTable_CreateEntry(>vars, name, NULL);
-	Var *v = VarNew(he->key /* aliased */, NULL, val,
+	Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), val,
 	flags & VAR_SET_READONLY ? VAR_READONLY : VAR_NONE);
 	HashEntry_Set(he, v);
 	if (!(ctxt->flags & INTERNAL))
@@ -3933,7 +3932,7 @@ ParseVarnameLong(
 		 * is still undefined, Var_Parse will return an empty string
 		 * instead of the actually computed value.
 		 */
-		v = VarNew(varname, varname, "", VAR_NONE);
+		v = VarNew(FStr_InitOwn(varname), "", VAR_NONE);
 		*out_TRUE_exprFlags = VEF_UNDEF;
 	} else
 		free(varname);



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 13:46:27 UTC 2020

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

Log Message:
make(1): eliminate libName_freeIt from Arch_ParseArchive


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/usr.bin/make/arch.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/arch.c
diff -u src/usr.bin/make/arch.c:1.190 src/usr.bin/make/arch.c:1.191
--- src/usr.bin/make/arch.c:1.190	Sun Dec 20 13:38:43 2020
+++ src/usr.bin/make/arch.c	Sun Dec 20 13:46:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.191 2020/12/20 13:46:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -125,7 +125,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.191 2020/12/20 13:46:27 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -186,18 +186,17 @@ Arch_ParseArchive(char **pp, GNodeList *
 {
 	char *cp;		/* Pointer into line */
 	GNode *gn;		/* New node */
-	char *libName;		/* Library-part of specification */
-	char *libName_freeIt = NULL;
+	MFStr libName;		/* Library-part of specification */
 	char *memName;		/* Member-part of specification */
 	char saveChar;		/* Ending delimiter of member-name */
 	Boolean expandLibName;	/* Whether the parsed libName contains
  * variable expressions that need to be
  * expanded */
 
-	libName = *pp;
+	libName = MFStr_InitRefer(*pp);
 	expandLibName = FALSE;
 
-	for (cp = libName; *cp != '(' && *cp != '\0';) {
+	for (cp = libName.str; *cp != '(' && *cp != '\0';) {
 		if (*cp == '$') {
 			/* Expand nested variable expressions. */
 			/* XXX: This code can probably be shortened. */
@@ -222,10 +221,11 @@ Arch_ParseArchive(char **pp, GNodeList *
 
 	*cp++ = '\0';
 	if (expandLibName) {
-		(void)Var_Subst(libName, ctxt, VARE_WANTRES | VARE_UNDEFERR,
-);
+		char *expanded;
+		(void)Var_Subst(libName.str, ctxt,
+		VARE_WANTRES | VARE_UNDEFERR, );
 		/* TODO: handle errors */
-		libName_freeIt = libName;
+		libName = MFStr_InitOwn(expanded);
 	}
 
 
@@ -314,7 +314,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 			 * Now form an archive spec and recurse to deal with
 			 * nested variables and multi-word variable values.
 			 */
-			fullName = str_concat4(libName, "(", memName, ")");
+			fullName = str_concat4(libName.str, "(", memName, ")");
 			p = fullName;
 
 			if (strchr(memName, '$') != NULL &&
@@ -344,7 +344,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 
 			while (!Lst_IsEmpty()) {
 char *member = Lst_Dequeue();
-char *fullname = str_concat4(libName, "(",
+char *fullname = str_concat4(libName.str, "(",
 			 member, ")");
 free(member);
 
@@ -357,7 +357,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 			Lst_Done();
 
 		} else {
-			char *fullname = str_concat4(libName, "(", memName,
+			char *fullname = str_concat4(libName.str, "(", memName,
 		 ")");
 			gn = Targ_GetNode(fullname);
 			free(fullname);
@@ -378,7 +378,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 		*cp = saveChar;
 	}
 
-	free(libName_freeIt);
+	MFStr_Done();
 
 	cp++;			/* skip the ')' */
 	/* We promised that pp would be set up at the next non-space. */



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 13:38:43 UTC 2020

Modified Files:
src/usr.bin/make: arch.c cond.c nonints.h parse.c suff.c var.c

Log Message:
make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/usr.bin/make/arch.c
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/make/cond.c
cvs rdiff -u -r1.176 -r1.177 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.503 -r1.504 src/usr.bin/make/parse.c
cvs rdiff -u -r1.331 -r1.332 src/usr.bin/make/suff.c
cvs rdiff -u -r1.742 -r1.743 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/arch.c
diff -u src/usr.bin/make/arch.c:1.189 src/usr.bin/make/arch.c:1.190
--- src/usr.bin/make/arch.c:1.189	Fri Dec 18 15:47:34 2020
+++ src/usr.bin/make/arch.c	Sun Dec 20 13:38:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.189 2020/12/18 15:47:34 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -125,7 +125,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.189 2020/12/18 15:47:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.190 2020/12/20 13:38:43 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -202,17 +202,15 @@ Arch_ParseArchive(char **pp, GNodeList *
 			/* Expand nested variable expressions. */
 			/* XXX: This code can probably be shortened. */
 			const char *nested_p = cp;
-			void *result_freeIt;
-			const char *result;
+			FStr result;
 			Boolean isError;
 
 			/* XXX: is expanded twice: once here and once below */
 			(void)Var_Parse(_p, ctxt,
-	VARE_WANTRES | VARE_UNDEFERR,
-	, _freeIt);
+	VARE_WANTRES | VARE_UNDEFERR, );
 			/* TODO: handle errors */
-			isError = result == var_Error;
-			free(result_freeIt);
+			isError = result.str == var_Error;
+			FStr_Done();
 			if (isError)
 return FALSE;
 
@@ -246,17 +244,16 @@ Arch_ParseArchive(char **pp, GNodeList *
 			if (*cp == '$') {
 /* Expand nested variable expressions. */
 /* XXX: This code can probably be shortened. */
-void *freeIt;
-const char *result;
+FStr result;
 Boolean isError;
 const char *nested_p = cp;
 
 (void)Var_Parse(_p, ctxt,
 		VARE_WANTRES | VARE_UNDEFERR,
-		, );
+		);
 /* TODO: handle errors */
-isError = result == var_Error;
-free(freeIt);
+isError = result.str == var_Error;
+FStr_Done();
 
 if (isError)
 	return FALSE;

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.228 src/usr.bin/make/cond.c:1.229
--- src/usr.bin/make/cond.c:1.228	Sun Dec 20 13:03:48 2020
+++ src/usr.bin/make/cond.c	Sun Dec 20 13:38:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.228 2020/12/20 13:03:48 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.228 2020/12/20 13:03:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.229 2020/12/20 13:38:43 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -247,16 +247,14 @@ ParseFuncArg(const char **pp, Boolean do
 			 * so we don't need to do it. Nor do we return an
 			 * error, though perhaps we should.
 			 */
-			void *nestedVal_freeIt;
 			VarEvalFlags eflags = doEval
 			? VARE_WANTRES | VARE_UNDEFERR
 			: VARE_NONE;
-			const char *nestedVal;
-			(void)Var_Parse(, VAR_CMDLINE, eflags,
-	, _freeIt);
+			FStr nestedVal;
+			(void)Var_Parse(, VAR_CMDLINE, eflags, );
 			/* TODO: handle errors */
-			Buf_AddStr(, nestedVal);
-			free(nestedVal_freeIt);
+			Buf_AddStr(, nestedVal.str);
+			FStr_Done();
 			continue;
 		}
 		if (ch == '(')
@@ -451,7 +449,7 @@ CondParser_String(CondParser *par, Boole
 			nested_p = par->p;
 			atStart = nested_p == start;
 			parseResult = Var_Parse(_p, VAR_CMDLINE, eflags,
-		, );
+			);
 			/* TODO: handle errors */
 			if (str.str == var_Error) {
 if (parseResult & VPR_ANY_MSG)
@@ -693,8 +691,7 @@ static size_t
 ParseEmptyArg(const char **pp, Boolean doEval,
 	  const char *func MAKE_ATTR_UNUSED, char **out_arg)
 {
-	void *val_freeIt;
-	const char *val;
+	FStr val;
 	size_t magic_res;
 
 	/* We do all the work here and return the result as the length */
@@ -702,12 +699,12 @@ ParseEmptyArg(const char **pp, Boolean d
 
 	(*pp)--;		/* Make (*pp)[1] point to the '('. */
 	(void)Var_Parse(pp, VAR_CMDLINE, doEval ? VARE_WANTRES : VARE_NONE,
-			, _freeIt);
+	);
 	/* TODO: handle errors */
 	/* If successful, *pp points beyond the closing ')' now. */
 
-	if (val == var_Error) {
-		free(val_freeIt);
+	if 

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 13:03:48 UTC 2020

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

Log Message:
make(1): clean up memory handling in CondParser_String


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/make/cond.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/cond.c
diff -u src/usr.bin/make/cond.c:1.227 src/usr.bin/make/cond.c:1.228
--- src/usr.bin/make/cond.c:1.227	Sun Dec 20 12:46:49 2020
+++ src/usr.bin/make/cond.c	Sun Dec 20 13:03:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.227 2020/12/20 12:46:49 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.228 2020/12/20 13:03:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.227 2020/12/20 12:46:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.228 2020/12/20 13:03:48 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -394,12 +394,10 @@ is_separator(char ch)
 /* coverity:[+alloc : arg-*4] */
 static void
 CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS,
-		  const char **out_str, void **out_str_freeIt,
-		  Boolean *out_quoted)
+		  FStr *out_str, Boolean *out_quoted)
 {
 	Buffer buf;
-	const char *str;
-	void *str_freeIt;
+	FStr str;
 	Boolean atStart;
 	const char *nested_p;
 	Boolean quoted;
@@ -408,14 +406,13 @@ CondParser_String(CondParser *par, Boole
 	VarParseResult parseResult;
 
 	Buf_Init();
-	str = NULL;
-	str_freeIt = NULL;
+	str = FStr_InitRefer(NULL);
 	*out_quoted = quoted = par->p[0] == '"';
 	start = par->p;
 	if (quoted)
 		par->p++;
 
-	while (par->p[0] != '\0' && str == NULL) {
+	while (par->p[0] != '\0' && str.str == NULL) {
 		switch (par->p[0]) {
 		case '\\':
 			par->p++;
@@ -454,26 +451,22 @@ CondParser_String(CondParser *par, Boole
 			nested_p = par->p;
 			atStart = nested_p == start;
 			parseResult = Var_Parse(_p, VAR_CMDLINE, eflags,
-		, _freeIt);
+		, );
 			/* TODO: handle errors */
-			if (str == var_Error) {
+			if (str.str == var_Error) {
 if (parseResult & VPR_ANY_MSG)
 	par->printedError = TRUE;
-if (str_freeIt != NULL) {
-	/*
-	 * XXX: Can there be any situation
-	 * in which a returned var_Error
-	 * requires freeIt?
-	 */
-	free(str_freeIt);
-	str_freeIt = NULL;
-}
+/*
+ * XXX: Can there be any situation in which
+ * a returned var_Error requires freeIt?
+ */
+FStr_Done();
 /*
  * Even if !doEval, we still report syntax
  * errors, which is what getting var_Error
  * back with !doEval means.
  */
-str = NULL;
+str = FStr_InitRefer(NULL);
 goto cleanup;
 			}
 			par->p = nested_p;
@@ -487,12 +480,9 @@ CondParser_String(CondParser *par, Boole
 			if (atStart && is_separator(par->p[0]))
 goto cleanup;
 
-			Buf_AddStr(, str);
-			if (str_freeIt != NULL) {
-free(str_freeIt);
-str_freeIt = NULL;
-			}
-			str = NULL;	/* not finished yet */
+			Buf_AddStr(, str.str);
+			FStr_Done();
+			str = FStr_InitRefer(NULL); /* not finished yet */
 			continue;
 		default:
 			if (strictLHS && !quoted && *start != '$' &&
@@ -501,7 +491,7 @@ CondParser_String(CondParser *par, Boole
  * The left-hand side must be quoted,
  * a variable reference or a number.
  */
-str = NULL;
+str = FStr_InitRefer(NULL);
 goto cleanup;
 			}
 			Buf_AddByte(, par->p[0]);
@@ -510,15 +500,10 @@ CondParser_String(CondParser *par, Boole
 		}
 	}
 got_str:
-	{
-		char *bufstr = Buf_GetAll(, NULL);
-		str = bufstr;
-		str_freeIt = bufstr;
-	}
+	str = FStr_InitOwn(Buf_GetAll(, NULL));
 cleanup:
 	Buf_Destroy(, FALSE);
 	*out_str = str;
-	*out_str_freeIt = str_freeIt;
 }
 
 struct If {
@@ -644,17 +629,16 @@ static Token
 CondParser_Comparison(CondParser *par, Boolean doEval)
 {
 	Token t = TOK_ERROR;
-	const char *lhs, *op, *rhs;
-	void *lhs_freeIt, *rhs_freeIt;
+	FStr lhs, rhs;
+	const char *op;
 	Boolean lhsQuoted, rhsQuoted;
 
 	/*
 	 * Parse the variable spec and skip over it, saving its
 	 * value in lhs.
 	 */
-	CondParser_String(par, doEval, lhsStrict,
-	, _freeIt, );
-	if (lhs == NULL)
+	CondParser_String(par, doEval, lhsStrict, , );
+	if (lhs.str == NULL)
 		goto done_lhs;
 
 	CondParser_SkipWhitespace(par);
@@ -672,7 +656,7 @@ CondParser_Comparison(CondParser *par, B
 		break;
 	default:
 		/* Unknown operator, compare against an empty string or 0. */
-		t = ToToken(doEval && EvalNotEmpty(par, lhs, lhsQuoted));
+		t = ToToken(doEval && EvalNotEmpty(par, lhs.str, lhsQuoted));
 		goto done_lhs;
 	}
 
@@ -685,8 +669,8 @@ CondParser_Comparison(CondParser *par, B
 		goto done_lhs;
 	}
 
-	CondParser_String(par, doEval, FALSE, , _freeIt, );
-	if (rhs == NULL)
+	CondParser_String(par, doEval, FALSE, , );

CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 12:53:35 UTC 2020

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

Log Message:
make(1): export FStr and MFStr

These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.741 -r1.742 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.175 src/usr.bin/make/nonints.h:1.176
--- src/usr.bin/make/nonints.h:1.175	Sat Dec 19 20:47:24 2020
+++ src/usr.bin/make/nonints.h	Sun Dec 20 12:53:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.175 2020/12/19 20:47:24 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.176 2020/12/20 12:53:34 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -164,12 +164,65 @@ void Parse_MainName(GNodeList *);
 int Parse_GetFatals(void);
 
 /* str.c */
+
+/* A read-only string that may need to be freed after use. */
+typedef struct FStr {
+	const char *str;
+	void *freeIt;
+} FStr;
+
+/* A modifiable string that may need to be freed after use. */
+typedef struct MFStr {
+	char *str;
+	void *freeIt;
+} MFStr;
+
 typedef struct Words {
 	char **words;
 	size_t len;
 	void *freeIt;
 } Words;
 
+/* Return a string that is the sole owner of str. */
+MAKE_INLINE FStr
+FStr_InitOwn(char *str)
+{
+	return (FStr){ str, str };
+}
+
+/* Return a string that refers to the shared str. */
+MAKE_INLINE FStr
+FStr_InitRefer(const char *str)
+{
+	return (FStr){ str, NULL };
+}
+
+MAKE_INLINE void
+FStr_Done(FStr *fstr)
+{
+	free(fstr->freeIt);
+}
+
+/* Return a string that is the sole owner of str. */
+MAKE_INLINE MFStr
+MFStr_InitOwn(char *str)
+{
+	return (MFStr){ str, str };
+}
+
+/* Return a string that refers to the shared str. */
+MAKE_INLINE MFStr
+MFStr_InitRefer(char *str)
+{
+	return (MFStr){ str, NULL };
+}
+
+MAKE_INLINE void
+MFStr_Done(MFStr *mfstr)
+{
+	free(mfstr->freeIt);
+}
+
 Words Str_Words(const char *, Boolean);
 MAKE_INLINE void
 Words_Free(Words w)

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.741 src/usr.bin/make/var.c:1.742
--- src/usr.bin/make/var.c:1.741	Sun Dec 20 11:38:51 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 12:53:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.741 2020/12/20 11:38:51 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,13 +131,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.741 2020/12/20 11:38:51 rillig Exp $");
-
-/* A string that may need to be freed after use. */
-typedef struct FStr {
-	const char *str;
-	void *freeIt;
-} FStr;
+MAKE_RCSID("$NetBSD: var.c,v 1.742 2020/12/20 12:53:34 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -305,25 +299,6 @@ ENUM_FLAGS_RTTI_6(VarFlags,
 
 static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE;
 
-/* Return an FStr that is the sole owner of str. */
-static FStr
-FStr_InitOwn(char *str)
-{
-	return (FStr){ str, str };
-}
-
-/* Return an FStr that refers to the shared str. */
-static FStr
-FStr_InitRefer(const char *str)
-{
-	return (FStr){ str, NULL };
-}
-
-static void
-FStr_Done(FStr *fstr)
-{
-	free(fstr->freeIt);
-}
 
 static Var *
 VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags)



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 12:46:49 UTC 2020

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

Log Message:
make(1): clean up memory handling in CondParser_String


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/make/cond.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/cond.c
diff -u src/usr.bin/make/cond.c:1.226 src/usr.bin/make/cond.c:1.227
--- src/usr.bin/make/cond.c:1.226	Mon Dec 14 22:17:11 2020
+++ src/usr.bin/make/cond.c	Sun Dec 20 12:46:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.226 2020/12/14 22:17:11 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.227 2020/12/20 12:46:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.226 2020/12/14 22:17:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.227 2020/12/20 12:46:49 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -392,12 +392,14 @@ is_separator(char ch)
  *	Sets out_freeIt.
  */
 /* coverity:[+alloc : arg-*4] */
-static const char *
+static void
 CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS,
-		  Boolean *out_quoted, void **out_freeIt)
+		  const char **out_str, void **out_str_freeIt,
+		  Boolean *out_quoted)
 {
 	Buffer buf;
 	const char *str;
+	void *str_freeIt;
 	Boolean atStart;
 	const char *nested_p;
 	Boolean quoted;
@@ -407,11 +409,12 @@ CondParser_String(CondParser *par, Boole
 
 	Buf_Init();
 	str = NULL;
-	*out_freeIt = NULL;
+	str_freeIt = NULL;
 	*out_quoted = quoted = par->p[0] == '"';
 	start = par->p;
 	if (quoted)
 		par->p++;
+
 	while (par->p[0] != '\0' && str == NULL) {
 		switch (par->p[0]) {
 		case '\\':
@@ -451,20 +454,19 @@ CondParser_String(CondParser *par, Boole
 			nested_p = par->p;
 			atStart = nested_p == start;
 			parseResult = Var_Parse(_p, VAR_CMDLINE, eflags,
-		,
-		out_freeIt);
+		, _freeIt);
 			/* TODO: handle errors */
 			if (str == var_Error) {
 if (parseResult & VPR_ANY_MSG)
 	par->printedError = TRUE;
-if (*out_freeIt != NULL) {
+if (str_freeIt != NULL) {
 	/*
 	 * XXX: Can there be any situation
 	 * in which a returned var_Error
 	 * requires freeIt?
 	 */
-	free(*out_freeIt);
-	*out_freeIt = NULL;
+	free(str_freeIt);
+	str_freeIt = NULL;
 }
 /*
  * Even if !doEval, we still report syntax
@@ -486,9 +488,9 @@ CondParser_String(CondParser *par, Boole
 goto cleanup;
 
 			Buf_AddStr(, str);
-			if (*out_freeIt != NULL) {
-free(*out_freeIt);
-*out_freeIt = NULL;
+			if (str_freeIt != NULL) {
+free(str_freeIt);
+str_freeIt = NULL;
 			}
 			str = NULL;	/* not finished yet */
 			continue;
@@ -508,11 +510,15 @@ CondParser_String(CondParser *par, Boole
 		}
 	}
 got_str:
-	*out_freeIt = Buf_GetAll(, NULL);
-	str = *out_freeIt;
+	{
+		char *bufstr = Buf_GetAll(, NULL);
+		str = bufstr;
+		str_freeIt = bufstr;
+	}
 cleanup:
 	Buf_Destroy(, FALSE);
-	return str;
+	*out_str = str;
+	*out_str_freeIt = str_freeIt;
 }
 
 struct If {
@@ -646,8 +652,8 @@ CondParser_Comparison(CondParser *par, B
 	 * Parse the variable spec and skip over it, saving its
 	 * value in lhs.
 	 */
-	lhs = CondParser_String(par, doEval, lhsStrict, ,
-_freeIt);
+	CondParser_String(par, doEval, lhsStrict,
+	, _freeIt, );
 	if (lhs == NULL)
 		goto done_lhs;
 
@@ -679,7 +685,7 @@ CondParser_Comparison(CondParser *par, B
 		goto done_lhs;
 	}
 
-	rhs = CondParser_String(par, doEval, FALSE, , _freeIt);
+	CondParser_String(par, doEval, FALSE, , _freeIt, );
 	if (rhs == NULL)
 		goto done_rhs;
 



CVS commit: src/sys/arch/mips/mips

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 12:27:20 UTC 2020

Modified Files:
src/sys/arch/mips/mips: pmap_machdep.c

Log Message:
Remove old part of comment


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/mips/mips/pmap_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/mips/pmap_machdep.c
diff -u src/sys/arch/mips/mips/pmap_machdep.c:1.30 src/sys/arch/mips/mips/pmap_machdep.c:1.31
--- src/sys/arch/mips/mips/pmap_machdep.c:1.30	Thu Sep 10 17:26:38 2020
+++ src/sys/arch/mips/mips/pmap_machdep.c	Sun Dec 20 12:27:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.c,v 1.30 2020/09/10 17:26:38 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.c,v 1.31 2020/12/20 12:27:20 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.30 2020/09/10 17:26:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.31 2020/12/20 12:27:20 skrll Exp $");
 
 /*
  *	Manages physical address maps.
@@ -333,7 +333,6 @@ pmap_md_ok_to_steal_p(const uvm_physseg_
 
 /*
  *	Bootstrap the system enough to run with virtual memory.
- *	firstaddr is the first unused kseg0 address (not page aligned).
  */
 void
 pmap_bootstrap(void)



CVS commit: src/sys/arch/sparc64/sparc64

2020-12-20 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Sun Dec 20 11:58:58 UTC 2020

Modified Files:
src/sys/arch/sparc64/sparc64: locore.s

Log Message:
sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


To generate a diff of this commit:
cvs rdiff -u -r1.423 -r1.424 src/sys/arch/sparc64/sparc64/locore.s

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc64/sparc64/locore.s
diff -u src/sys/arch/sparc64/sparc64/locore.s:1.423 src/sys/arch/sparc64/sparc64/locore.s:1.424
--- src/sys/arch/sparc64/sparc64/locore.s:1.423	Wed Jan  8 20:59:20 2020
+++ src/sys/arch/sparc64/sparc64/locore.s	Sun Dec 20 11:58:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.423 2020/01/08 20:59:20 skrll Exp $	*/
+/*	$NetBSD: locore.s,v 1.424 2020/12/20 11:58:58 palle Exp $	*/
 
 /*
  * Copyright (c) 2006-2010 Matthew R. Green
@@ -3343,6 +3343,8 @@ sun4v_tl1_ptbl_miss:
 	bgeu,pt	%xcc, 1f
 	 nop
 
+	/* We had a miss inside rtf_user_fault_start/rtf_user_fault_end block (FILL)
+	
 	/* Fixup %cwp. */
 	rdpr	%cwp, %g1
 	inc	%g1



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 11:38:51 UTC 2020

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

Log Message:
make(1): document memory handling in ApplyModifiers


To generate a diff of this commit:
cvs rdiff -u -r1.740 -r1.741 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.740 src/usr.bin/make/var.c:1.741
--- src/usr.bin/make/var.c:1.740	Sun Dec 20 10:59:21 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 11:38:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.740 2020/12/20 10:59:21 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.741 2020/12/20 11:38:51 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.740 2020/12/20 10:59:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.741 2020/12/20 11:38:51 rillig Exp $");
 
 /* A string that may need to be freed after use. */
 typedef struct FStr {
@@ -3596,7 +3596,8 @@ ApplyModifiers(
 
 		if (st.newVal != st.val) {
 			if (*inout_freeIt != NULL) {
-free(st.val);
+assert(*inout_freeIt == st.val);
+free(*inout_freeIt);
 *inout_freeIt = NULL;
 			}
 			st.val = st.newVal;



CVS commit: src/sys/uvm

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 11:11:34 UTC 2020

Modified Files:
src/sys/uvm: uvm_page.c

Log Message:
Some KNF.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.249 -r1.250 src/sys/uvm/uvm_page.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.249 src/sys/uvm/uvm_page.c:1.250
--- src/sys/uvm/uvm_page.c:1.249	Sun Oct 18 18:31:31 2020
+++ src/sys/uvm/uvm_page.c	Sun Dec 20 11:11:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $	*/
+/*	$NetBSD: uvm_page.c,v 1.250 2020/12/20 11:11:34 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.250 2020/12/20 11:11:34 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvm.h"
@@ -560,7 +560,7 @@ uvm_pageboot_alloc(vsize_t size)
 	addr = pmap_steal_memory(size, _space_start,
 	_space_end);
 
-	return(addr);
+	return addr;
 
 #else /* !PMAP_STEAL_MEMORY */
 
@@ -604,7 +604,7 @@ uvm_pageboot_alloc(vsize_t size)
 		pmap_kenter_pa(vaddr, paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	}
 	pmap_update(pmap_kernel());
-	return(addr);
+	return addr;
 #endif	/* PMAP_STEAL_MEMORY */
 }
 



CVS commit: src/usr.bin/make

2020-12-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Dec 20 10:59:22 UTC 2020

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

Log Message:
make(1): replace freeIt with FStr in EvalUndefined

Previously, the parameter out_freeIt was not guaranteed to be
initialized in every case, at least when looking only at EvalUndefined.
This contradicted the variable name.

Replace the two parameters with a single FStr to ensure that these
variables are always initialized together.


To generate a diff of this commit:
cvs rdiff -u -r1.739 -r1.740 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.739 src/usr.bin/make/var.c:1.740
--- src/usr.bin/make/var.c:1.739	Sun Dec 20 00:57:29 2020
+++ src/usr.bin/make/var.c	Sun Dec 20 10:59:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.739 2020/12/20 00:57:29 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.740 2020/12/20 10:59:21 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.739 2020/12/20 00:57:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.740 2020/12/20 10:59:21 rillig Exp $");
 
 /* A string that may need to be freed after use. */
 typedef struct FStr {
@@ -3846,13 +3846,11 @@ FindLocalLegacyVar(const char *varname, 
 static VarParseResult
 EvalUndefined(Boolean dynamic, const char *start, const char *p, char *varname,
 	  VarEvalFlags eflags,
-	  const char **out_val, void **out_freeIt)
+	  FStr *out_val)
 {
 	if (dynamic) {
-		char *pstr = bmake_strsedup(start, p);
+		*out_val = FStr_InitOwn(bmake_strsedup(start, p));
 		free(varname);
-		*out_val = pstr;
-		*out_freeIt = pstr;
 		return VPR_OK;
 	}
 
@@ -3860,18 +3858,18 @@ EvalUndefined(Boolean dynamic, const cha
 		Parse_Error(PARSE_FATAL,
 		"Variable \"%s\" is undefined", varname);
 		free(varname);
-		*out_val = var_Error;
+		*out_val = FStr_InitRefer(var_Error);
 		return VPR_UNDEF_MSG;
 	}
 
 	if (eflags & VARE_UNDEFERR) {
 		free(varname);
-		*out_val = var_Error;
+		*out_val = FStr_InitRefer(var_Error);
 		return VPR_UNDEF_SILENT;
 	}
 
 	free(varname);
-	*out_val = varUndefined;
+	*out_val = FStr_InitRefer(varUndefined);
 	return VPR_OK;
 }
 
@@ -3888,8 +3886,7 @@ ParseVarnameLong(
 
 	const char **out_FALSE_pp,
 	VarParseResult *out_FALSE_res,
-	const char **out_FALSE_val,
-	void **out_FALSE_freeIt,
+	FStr *out_FALSE_val,
 
 	char *out_TRUE_endc,
 	const char **out_TRUE_p,
@@ -3920,7 +3917,7 @@ ParseVarnameLong(
 		Parse_Error(PARSE_FATAL, "Unclosed variable \"%s\"", varname);
 		free(varname);
 		*out_FALSE_pp = p;
-		*out_FALSE_val = var_Error;
+		*out_FALSE_val = FStr_InitRefer(var_Error);
 		*out_FALSE_res = VPR_PARSE_MSG;
 		return FALSE;
 	}
@@ -3947,7 +3944,7 @@ ParseVarnameLong(
 			p++;	/* skip endc */
 			*out_FALSE_pp = p;
 			*out_FALSE_res = EvalUndefined(dynamic, start, p,
-			varname, eflags, out_FALSE_val, out_FALSE_freeIt);
+			varname, eflags, out_FALSE_val);
 			return FALSE;
 		}
 
@@ -4079,11 +4076,15 @@ Var_Parse(const char **pp, GNode *ctxt, 
 		p++;
 	} else {
 		VarParseResult res;
+		FStr fval;
 		if (!ParseVarnameLong(p, startc, ctxt, eflags,
-		pp, , out_val, out_val_freeIt,
+		pp, , ,
 		, , , , ,
-		, ))
+		, )) {
+			*out_val = fval.str;
+			*out_val_freeIt = fval.freeIt;
 			return res;
+		}
 	}
 
 	if (v->flags & VAR_IN_USE)



CVS commit: src/sys/arch/arm/arm32

2020-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 20 10:34:33 UTC 2020

Modified Files:
src/sys/arch/arm/arm32: bus_dma.c

Log Message:
style fix


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/arm/arm32/bus_dma.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/arm32/bus_dma.c
diff -u src/sys/arch/arm/arm32/bus_dma.c:1.127 src/sys/arch/arm/arm32/bus_dma.c:1.128
--- src/sys/arch/arm/arm32/bus_dma.c:1.127	Sat Dec 19 23:22:18 2020
+++ src/sys/arch/arm/arm32/bus_dma.c	Sun Dec 20 10:34:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.127 2020/12/19 23:22:18 jmcneill Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.128 2020/12/20 10:34:33 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2020 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include "opt_cputypes.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.127 2020/12/19 23:22:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.128 2020/12/20 10:34:33 jmcneill Exp $");
 
 #include 
 
@@ -1196,7 +1196,7 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dm
 		return;
 	}
 
-#if !defined( ARM_MMU_EXTENDED)
+#if !defined(ARM_MMU_EXTENDED)
 	/*
 	 * If the mapping belongs to a non-kernel vmspace, and the
 	 * vmspace has not been active since the last time a full



CVS commit: src/sbin/atactl

2020-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 20 10:19:30 UTC 2020

Modified Files:
src/sbin/atactl: atactl.c

Log Message:
Managment -> Management


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sbin/atactl/atactl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/atactl/atactl.c
diff -u src/sbin/atactl/atactl.c:1.84 src/sbin/atactl/atactl.c:1.85
--- src/sbin/atactl/atactl.c:1.84	Mon Dec  7 10:36:19 2020
+++ src/sbin/atactl/atactl.c	Sun Dec 20 10:19:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $	*/
+/*	$NetBSD: atactl.c,v 1.85 2020/12/20 10:19:30 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: atactl.c,v 1.84 2020/12/07 10:36:19 mrg Exp $");
+__RCSID("$NetBSD: atactl.c,v 1.85 2020/12/20 10:19:30 jmcneill Exp $");
 #endif
 
 
@@ -306,7 +306,7 @@ static const struct bitinfo ata_sata_cap
 static const struct bitinfo ata_sata_feat[] = {
 	{ SATA_NONZERO_OFFSETS, "Non-zero Offset DMA" },
 	{ SATA_DMA_SETUP_AUTO, "DMA Setup Auto Activate" },
-	{ SATA_DRIVE_PWR_MGMT, "Device-Initiated Interface Power Managment" },
+	{ SATA_DRIVE_PWR_MGMT, "Device-Initiated Interface Power Management" },
 	{ SATA_IN_ORDER_DATA, "In-order Data Delivery" },
 	{ SATA_SW_STTNGS_PRS, "Software Settings Preservation" },
 	{ 0, NULL },



CVS commit: src/sys/arch/sparc64/dev

2020-12-20 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Sun Dec 20 09:08:15 UTC 2020

Modified Files:
src/sys/arch/sparc64/dev: pcf8591_envctrl.c

Log Message:
For the E250:
  set fans to medium speed when attaching and full speed when detaching.
  remove unused PS fan definition.
In general:
  return early from attach if the device isn't present.
  handle errors from sysmon during attach so that detach doesn't crash.
  try to handle errors when acquiring the iic bus during detach.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/sparc64/dev/pcf8591_envctrl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc64/dev/pcf8591_envctrl.c
diff -u src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.14 src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.15
--- src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.14	Mon Dec  7 13:24:15 2020
+++ src/sys/arch/sparc64/dev/pcf8591_envctrl.c	Sun Dec 20 09:08:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcf8591_envctrl.c,v 1.14 2020/12/07 13:24:15 jdc Exp $	*/
+/*	$NetBSD: pcf8591_envctrl.c,v 1.15 2020/12/20 09:08:15 jdc Exp $	*/
 /*	$OpenBSD: pcf8591_envctrl.c,v 1.6 2007/10/25 21:17:20 kettenis Exp $ */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.14 2020/12/07 13:24:15 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.15 2020/12/20 09:08:15 jdc Exp $");
 
 #include 
 #include 
@@ -55,7 +55,6 @@ __KERNEL_RCSID(0, "$NetBSD: pcf8591_envc
 
 #define PCF8591_TEMP_SENS	0x00
 #define PCF8591_CPU_FAN_CTRL	0x01
-#define PCF8591_PS_FAN_CTRL	0x02
 
 struct ecadc_channel {
 	u_int		chan_num;
@@ -89,6 +88,7 @@ static int	ecadc_detach(device_t, int);
 static void	ecadc_refresh(struct sysmon_envsys *, envsys_data_t *);
 static void	ecadc_get_limits(struct sysmon_envsys *, envsys_data_t *,
 			sysmon_envsys_lim_t *, u_int32_t *);
+static int	ecadc_set_fan_speed(struct ecadc_softc *, u_int8_t, u_int8_t);
 static void	ecadc_timeout(void *);
 static void	ecadc_fan_adjust(void *);
 
@@ -205,6 +205,21 @@ ecadc_attach(device_t parent, device_t s
 		sc->sc_nchan++;
 	}
 
+	sc->sc_tag = ia->ia_tag;
+	sc->sc_addr = ia->ia_addr;
+
+	iic_acquire_bus(sc->sc_tag, 0);
+
+	/* Try a read now, so we can fail if this component isn't present */
+	if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr,
+	NULL, 0, junk, sc->sc_nchan + 1, 0)) {
+		aprint_normal(": read failed\n");
+		iic_release_bus(sc->sc_tag, 0);
+		return;
+	}
+
+	iic_release_bus(sc->sc_tag, 0);
+
 	/*
 	 * Fan speed changing information is missing from OFW
 	 * The E250 CPU fan is connected to the sensor at addr 0x4a, channel 1
@@ -214,7 +229,6 @@ ecadc_attach(device_t parent, device_t s
 	XLATE_MAX) > 0) {
 		sc->sc_channels[sc->sc_nchan].chan_num = 1;
 		sc->sc_channels[sc->sc_nchan].chan_type = PCF8591_CPU_FAN_CTRL;
-		sc->sc_channels[sc->sc_nchan].chan_speed = 0;
 		sensor = >sc_channels[sc->sc_nchan].chan_sensor;
 		sensor->units = ENVSYS_INTEGER;
 		sensor->flags = ENVSYS_FMONNOTSUPP;
@@ -225,26 +239,17 @@ ecadc_attach(device_t parent, device_t s
 		"added CPUFAN sensor (chan %d) with cpu-fan xlate\n",
 		device_xname(sc->sc_dev),
 		sc->sc_channels[sc->sc_nchan].chan_num);
-		sc->sc_nchan++;
 
-		sc->sc_hastimer = 1;
-	}
+		/* Set the fan to medium speed */
+		sc->sc_channels[sc->sc_nchan].chan_speed =
+		(sc->sc_cpu_fan_spd[0]+sc->sc_cpu_fan_spd[XLATE_MAX])/2;
+		ecadc_set_fan_speed(sc, sc->sc_channels[sc->sc_nchan].chan_num,
+		sc->sc_channels[sc->sc_nchan].chan_speed);
 
-	sc->sc_tag = ia->ia_tag;
-	sc->sc_addr = ia->ia_addr;
-
-	iic_acquire_bus(sc->sc_tag, 0);
-
-	/* Try a read now, so we can fail if this component isn't present */
-	if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr,
-	NULL, 0, junk, sc->sc_nchan + 1, 0)) {
-		aprint_normal(": read failed\n");
-		iic_release_bus(sc->sc_tag, 0);
-		return;
+		sc->sc_nchan++;
+		sc->sc_hastimer = 1;
 	}
 
-	iic_release_bus(sc->sc_tag, 0);
-
 	/* Hook us into the sysmon_envsys subsystem */
 	sc->sc_sme = sysmon_envsys_create();
 	sc->sc_sme->sme_name = device_xname(self);
@@ -280,6 +285,8 @@ static int
 ecadc_detach(device_t self, int flags)
 {
 	struct ecadc_softc *sc = device_private(self);
+	int c, i;
+
 	if (sc->sc_hastimer) {
 		callout_halt(>sc_timer, NULL);
 		callout_destroy(>sc_timer);
@@ -288,6 +295,23 @@ ecadc_detach(device_t self, int flags)
 	if (sc->sc_sme != NULL)
 		sysmon_envsys_unregister(sc->sc_sme);
 
+	for (i = 0; i < sc->sc_nchan; i++) {
+		struct ecadc_channel *chp = >sc_channels[i];
+
+		if (chp->chan_type == PCF8591_CPU_FAN_CTRL) {
+			/* Loop in case the bus is busy */
+			for (c = 0; c < 5; c++) {
+chp->chan_speed = sc->sc_cpu_fan_spd[0];
+if (!ecadc_set_fan_speed(sc, chp->chan_num,
+chp->chan_speed))
+	return 0;
+delay(1);
+			}
+			aprint_error_dev(sc->sc_dev,
+			"cannot set fan speed (chan %d)\n", 

CVS commit: src/sys/arch/aarch64/aarch64

2020-12-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 20 08:26:33 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c

Log Message:
Improve the English in the previous comment fix.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/aarch64/aarch64/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.98 src/sys/arch/aarch64/aarch64/pmap.c:1.99
--- src/sys/arch/aarch64/aarch64/pmap.c:1.98	Sat Dec 19 09:02:32 2020
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Dec 20 08:26:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.98 2020/12/19 09:02:32 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.99 2020/12/20 08:26:32 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.98 2020/12/19 09:02:32 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.99 2020/12/20 08:26:32 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -632,7 +632,7 @@ pmap_alloc_pdp(struct pmap *pm, struct v
 		PMAP_COUNT(pdp_alloc);
 		PMAP_PAGE_INIT(VM_PAGE_TO_PP(pg));
 	} else {
-		/* uvm_pageboot_alloc() returns direct mapping address */
+		/* uvm_pageboot_alloc() returns a direct mapping address */
 		pg = NULL;
 		pa = AARCH64_KVA_TO_PA(
 		uvm_pageboot_alloc(Ln_TABLE_SIZE));