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

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:58:19 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: directive-for-escape.exp
directive-for-escape.mk

Log Message:
make: improve comments in test for expansions in .for loops


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-for-escape.exp \
src/usr.bin/make/unit-tests/directive-for-escape.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/directive-for-escape.exp
diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.6 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.7
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.6	Mon Jan 25 19:05:39 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Mon Feb 15 07:58:19 2021
@@ -37,19 +37,19 @@ make: "directive-for-escape.mk" line 55:
 For: end for 1
 For: loop body:
 .  info ${:Ubegin<${UNDEF:Ufallback:N{{{>end}
-make: "directive-for-escape.mk" line 66: beginend
+make: "directive-for-escape.mk" line 67: beginend
 For: end for 1
 For: loop body:
 .  info ${:U\$}
-make: "directive-for-escape.mk" line 74: $
+make: "directive-for-escape.mk" line 75: $
 For: end for 1
 For: loop body:
 .  info ${NUMBERS} ${:Ureplaced}
-make: "directive-for-escape.mk" line 82: one two three replaced
+make: "directive-for-escape.mk" line 83: one two three replaced
 For: end for 1
 For: loop body:
 .  info ${:Ureplaced}
-make: "directive-for-escape.mk" line 92: replaced
+make: "directive-for-escape.mk" line 93: replaced
 For: end for 1
 For: loop body:
 .  info .$$i: ${:Uinner}
@@ -62,14 +62,14 @@ For: loop body:
 .  info . $${i2}: ${i2}
 .  info . $${i,}: ${i,}
 .  info .  adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
-make: "directive-for-escape.mk" line 100: .$i: inner
-make: "directive-for-escape.mk" line 101: .  ${i}: inner
-make: "directive-for-escape.mk" line 102: .   ${i:M*}: inner
-make: "directive-for-escape.mk" line 103: .  $(i): inner
-make: "directive-for-escape.mk" line 104: .   $(i:M*): inner
-make: "directive-for-escape.mk" line 105: . ${i${:U}}: outer
-make: "directive-for-escape.mk" line 106: .${i\}}: inner}
-make: "directive-for-escape.mk" line 107: . ${i2}: two
-make: "directive-for-escape.mk" line 108: . ${i,}: comma
-make: "directive-for-escape.mk" line 109: .  adjacent: innerinnerinnerinner
+make: "directive-for-escape.mk" line 101: .$i: inner
+make: "directive-for-escape.mk" line 102: .  ${i}: inner
+make: "directive-for-escape.mk" line 103: .   ${i:M*}: inner
+make: "directive-for-escape.mk" line 104: .  $(i): inner
+make: "directive-for-escape.mk" line 105: .   $(i:M*): inner
+make: "directive-for-escape.mk" line 106: . ${i${:U}}: outer
+make: "directive-for-escape.mk" line 107: .${i\}}: inner}
+make: "directive-for-escape.mk" line 108: . ${i2}: two
+make: "directive-for-escape.mk" line 109: . ${i,}: comma
+make: "directive-for-escape.mk" line 110: .  adjacent: innerinnerinnerinner
 exit status 0
Index: src/usr.bin/make/unit-tests/directive-for-escape.mk
diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.6 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.7
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.6	Mon Jan 25 19:05:39 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk	Mon Feb 15 07:58:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.6 2021/01/25 19:05:39 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.7 2021/02/15 07:58:19 rillig Exp $
 #
 # Test escaping of special characters in the iteration values of a .for loop.
 # These values get expanded later using the :U variable modifier, and this
@@ -7,8 +7,8 @@
 
 .MAKEFLAGS: -df
 
-# Even though the .for loops takes quotes into account when splitting the
-# string into words, the quotes don't need to be balances, as of 2020-12-31.
+# Even though the .for loops take quotes into account when splitting the
+# string into words, the quotes don't need to be balanced, as of 2020-12-31.
 # This could be considered a bug.
 ASCII=	!"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~
 
@@ -33,7 +33,7 @@ ASCII.2020-12-31=	!"\\\#$$%&'()*+,-./0-9
 #
 # XXX: It is unexpected that the variable V gets expanded in the loop body.
 # The double '$$' should prevent exactly this.  Probably nobody was
-# adventurous enough to use literal dollar signs in the values for a .for
+# adventurous enough to use literal dollar signs in the values of a .for
 # loop.
 V=		value
 VALUES=		$$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier)
@@ -43,14 +43,14 @@ VALUES=		$$ $${V} $${V:=-with-modifier} 
 
 # Try to cover the code for nested '{}' in for_var_len, without success.
 #
-# The value of VALUES is not meant to be a variable expression.  Instead, it
-# is meant to represent dollar, lbrace, "UNDEF:U", 

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:42:35 UTC 2021

Modified Files:
src/usr.bin/make: test-variants.sh

Log Message:
make: fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/test-variants.sh

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/test-variants.sh
diff -u src/usr.bin/make/test-variants.sh:1.8 src/usr.bin/make/test-variants.sh:1.9
--- src/usr.bin/make/test-variants.sh:1.8	Mon Dec  7 22:27:56 2020
+++ src/usr.bin/make/test-variants.sh	Mon Feb 15 07:42:35 2021
@@ -1,9 +1,9 @@
 #! /bin/sh
-# $NetBSD: test-variants.sh,v 1.8 2020/12/07 22:27:56 rillig Exp $
+# $NetBSD: test-variants.sh,v 1.9 2021/02/15 07:42:35 rillig Exp $
 #
 # Build several variants of make and run the tests on them.
 #
-# The output of this test suite must be inspected manuelly to see the
+# The output of this test suite must be inspected manually to see the
 # interesting details.  The main purpose is to list the available build
 # options.
 



CVS commit: src/usr.bin/xlint/lint1

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:40:18 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: remove redundant comment

That comment was useful when there was no function is_null_pointer.
Back then, the code for testing a null pointer was written in-line,
which made it really hard to see what's going on.  This is no longer the
case.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.206 src/usr.bin/xlint/lint1/tree.c:1.207
--- src/usr.bin/xlint/lint1/tree.c:1.206	Mon Feb 15 07:36:40 2021
+++ src/usr.bin/xlint/lint1/tree.c	Mon Feb 15 07:40:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.206 2021/02/15 07:36:40 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.207 2021/02/15 07:40:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.206 2021/02/15 07:36:40 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.207 2021/02/15 07:40:18 rillig Exp $");
 #endif
 
 #include 
@@ -1049,7 +1049,6 @@ typeok_colon(const mod_t *mp,
 	if (lt == UNION && rt == UNION && ltp->t_str == rtp->t_str)
 		return true;
 
-	/* combination of any pointer and null pointer is ok */
 	if (lt == PTR && is_null_pointer(rn))
 		return true;
 	if (rt == PTR && is_null_pointer(ln))



CVS commit: src/usr.bin/xlint/lint1

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:36:40 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: extract typeok_colon_pointer from typeok_colon

The subtype information is now only accessed if both operands are
actually pointers.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/usr.bin/xlint/lint1/tree.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/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.205 src/usr.bin/xlint/lint1/tree.c:1.206
--- src/usr.bin/xlint/lint1/tree.c:1.205	Thu Feb  4 06:54:59 2021
+++ src/usr.bin/xlint/lint1/tree.c	Mon Feb 15 07:36:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.205 2021/02/04 06:54:59 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.206 2021/02/15 07:36:40 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.205 2021/02/04 06:54:59 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.206 2021/02/15 07:36:40 rillig Exp $");
 #endif
 
 #include 
@@ -1008,13 +1008,36 @@ typeok_quest(tspec_t lt, const tnode_t *
 	return true;
 }
 
+static void
+typeok_colon_pointer(const mod_t *mp,
+		 const tnode_t *ln, const type_t *ltp,
+		 const tnode_t *rn, const type_t *rtp)
+{
+	type_t *lstp = ltp->t_subt;
+	type_t *rstp = rtp->t_subt;
+	tspec_t lst = lstp->t_tspec;
+	tspec_t rst = rstp->t_tspec;
+
+	if ((lst == VOID && rst == FUNC) || (lst == FUNC && rst == VOID)) {
+		/* (void *)0 handled above */
+		if (sflag)
+			/* ANSI C forbids conv. of %s to %s, op %s */
+			warning(305, "function pointer", "'void *'",
+			mp->m_name);
+		return;
+	}
+
+	if (eqptrtype(lstp, rstp, true))
+		return;
+	if (!eqtype(lstp, rstp, true, false, NULL))
+		warn_incompatible_pointers(mp, ltp, rtp);
+}
+
 static bool
 typeok_colon(const mod_t *mp,
 	 const tnode_t *ln, const type_t *ltp, tspec_t lt,
 	 const tnode_t *rn, const type_t *rtp, tspec_t rt)
 {
-	type_t *lstp, *rstp;
-	tspec_t lst, rst;
 
 	if (is_arithmetic(lt) && is_arithmetic(rt))
 		return true;
@@ -1026,11 +1049,6 @@ typeok_colon(const mod_t *mp,
 	if (lt == UNION && rt == UNION && ltp->t_str == rtp->t_str)
 		return true;
 
-	lstp = lt == PTR ? ltp->t_subt : NULL;
-	rstp = rt == PTR ? rtp->t_subt : NULL;
-	lst = lstp != NULL ? lstp->t_tspec : NOTSPEC;
-	rst = rstp != NULL ? rstp->t_tspec : NOTSPEC;
-
 	/* combination of any pointer and null pointer is ok */
 	if (lt == PTR && is_null_pointer(rn))
 		return true;
@@ -1053,21 +1071,8 @@ typeok_colon(const mod_t *mp,
 		return true;
 	}
 
-	if (lt == PTR && rt == PTR && ((lst == VOID && rst == FUNC) ||
-   (lst == FUNC && rst == VOID))) {
-		/* (void *)0 handled above */
-		if (sflag)
-			/* ANSI C forbids conv. of %s to %s, op %s */
-			warning(305, "function pointer", "'void *'",
-			mp->m_name);
-		return true;
-	}
-
-	if (rt == PTR && lt == PTR) {
-		if (eqptrtype(lstp, rstp, true))
-			return true;
-		if (!eqtype(lstp, rstp, true, false, NULL))
-			warn_incompatible_pointers(mp, ltp, rtp);
+	if (lt == PTR && rt == PTR) {
+		typeok_colon_pointer(mp, ln, ltp, rn, rtp);
 		return true;
 	}
 



CVS commit: src/tests/usr.bin/xlint/lint1

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:18:20 UTC 2021

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_124.c

Log Message:
tests/lint: fix comments in test for message 124


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_124.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_124.c
diff -u src/tests/usr.bin/xlint/lint1/msg_124.c:1.6 src/tests/usr.bin/xlint/lint1/msg_124.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_124.c:1.6	Sun Jan 24 11:21:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_124.c	Mon Feb 15 07:18:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_124.c,v 1.6 2021/01/24 11:21:58 rillig Exp $	*/
+/*	$NetBSD: msg_124.c,v 1.7 2021/02/15 07:18:20 rillig Exp $	*/
 # 3 "msg_124.c"
 
 // Test for message: illegal pointer combination, op %s [124]
@@ -35,11 +35,11 @@ compare_pointers(const void *vp, const c
 	ok(vp == (void *)0);
 	ok(cp == (void *)0);
 	ok(ip == (void *)0);
-	ok(fp == (void *)0);	/* wrong 124 before 2021-01-25 */
+	ok(fp == (void *)0);	/* wrong 274 before 2021-01-25 */
 	ok((void *)0 == vp);
 	ok((void *)0 == cp);
 	ok((void *)0 == ip);
-	ok((void *)0 == fp);	/* wrong 124 before 2021-01-25 */
+	ok((void *)0 == fp);	/* wrong 274 before 2021-01-25 */
 	ok(vp == 0);
 	ok(cp == 0);
 	ok(ip == 0);



CVS commit: src/tests/lib/libcurses

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 07:06:27 UTC 2021

Modified Files:
src/tests/lib/libcurses/director: testlang_conf.l testlang_parse.y
src/tests/lib/libcurses/slave: commands.c

Log Message:
tests/libcurses: fix error handling for non-system errors

These errors are unrelated to errno.  The scanf family of functions also
does not set errno.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libcurses/director/testlang_conf.l
cvs rdiff -u -r1.47 -r1.48 src/tests/lib/libcurses/director/testlang_parse.y
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libcurses/slave/commands.c

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

Modified files:

Index: src/tests/lib/libcurses/director/testlang_conf.l
diff -u src/tests/lib/libcurses/director/testlang_conf.l:1.20 src/tests/lib/libcurses/director/testlang_conf.l:1.21
--- src/tests/lib/libcurses/director/testlang_conf.l:1.20	Sat Feb 13 08:14:46 2021
+++ src/tests/lib/libcurses/director/testlang_conf.l	Mon Feb 15 07:06:27 2021
@@ -1,5 +1,5 @@
 %{
-/*	$NetBSD: testlang_conf.l,v 1.20 2021/02/13 08:14:46 rillig Exp $ 	*/
+/*	$NetBSD: testlang_conf.l,v 1.21 2021/02/15 07:06:27 rillig Exp $ 	*/
 
 /*-
  * Copyright 2009 Brett Lymn 
@@ -223,7 +223,7 @@ include		BEGIN(incl);
 			yyterminate();
 
 		if (--include_ptr < 0)
-			err(2, "Include stack underflow");
+			errx(2, "Include stack underflow");
 
 		free(cur_file);
 		cur_file = include_files[include_ptr];
@@ -260,7 +260,7 @@ include		BEGIN(incl);
 			unsigned long val;
 
 			if (sscanf(yytext, "%lx", ) != 1)
-err(1, "Bad hex conversion");
+errx(1, "Bad hex conversion");
 
 			asprintf(, "%ld", val);
 			return numeric;

Index: src/tests/lib/libcurses/director/testlang_parse.y
diff -u src/tests/lib/libcurses/director/testlang_parse.y:1.47 src/tests/lib/libcurses/director/testlang_parse.y:1.48
--- src/tests/lib/libcurses/director/testlang_parse.y:1.47	Sat Feb 13 08:43:03 2021
+++ src/tests/lib/libcurses/director/testlang_parse.y	Mon Feb 15 07:06:27 2021
@@ -1,5 +1,5 @@
 %{
-/*	$NetBSD: testlang_parse.y,v 1.47 2021/02/13 08:43:03 rillig Exp $	*/
+/*	$NetBSD: testlang_parse.y,v 1.48 2021/02/15 07:06:27 rillig Exp $	*/
 
 /*-
  * Copyright 2009 Brett Lymn 
@@ -501,10 +501,10 @@ get_numeric_var(const char *var)
 	int i;
 
 	if ((i = find_var_index(var)) < 0)
-		err(1, "Variable %s is undefined", var);
+		errx(1, "Variable %s is undefined", var);
 
 	if (vars[i].type != data_number)
-		err(1, "Variable %s is not a numeric type", var);
+		errx(1, "Variable %s is not a numeric type", var);
 
 	return vars[i].value;
 }
@@ -591,7 +591,7 @@ add_to_vals(data_enum_t argtype, void *a
 
 	case data_var:
 		if ((i = find_var_index((char *) arg)) < 0)
-			err(1, "%s:%zu: Variable %s is undefined",
+			errx(1, "%s:%zu: Variable %s is undefined",
 			cur_file, line, (const char *) arg);
 
 		switch (vars[i].type) {
@@ -603,7 +603,8 @@ add_to_vals(data_enum_t argtype, void *a
 			break;
 
 		default:
-			err(1, "%s:%zu: Variable %s has invalid type for cchar",
+			errx(1,
+			"%s:%zu: Variable %s has invalid type for cchar",
 			cur_file, line, (const char *) arg);
 			break;
 
@@ -611,7 +612,7 @@ add_to_vals(data_enum_t argtype, void *a
 		break;
 
 	default:
-		err(1, "%s:%zu: Internal error: Unhandled type for vals array",
+		errx(1, "%s:%zu: Internal error: Unhandled type for vals array",
 		cur_file, line);
 
 		/* if we get here without a value then tidy up */
@@ -670,7 +671,7 @@ set_cchar(char *name, void *attributes)
 	attr_t attribs;
 
 	if (nvals >= CURSES_CCHAR_MAX)
-		err(1, "%s:%zu: %s: too many characters in complex char type",
+		errx(1, "%s:%zu: %s: too many characters in complex char type",
 		cur_file, line, __func__);
 
 	i = find_var_index(name);
@@ -678,7 +679,8 @@ set_cchar(char *name, void *attributes)
 		i = assign_var(name);
 
 	if (sscanf((char *) attributes, "%d", ) != 1)
-		err(1, "%s:%zu: %s: conversion of attributes to integer failed",
+		errx(1,
+		"%s:%zu: %s: conversion of attributes to integer failed",
 		cur_file, line, __func__);
 
 	vars[i].type = data_cchar;
@@ -826,7 +828,7 @@ assign_rets(data_enum_t ret_type, void *
 			   cur.data_len);
 		} else if (ret_type == data_ref) {
 			if ((cur.data_index = find_var_index(ret)) < 0)
-err(1, "Undefined variable reference");
+errx(1, "Undefined variable reference");
 		}
 	} else {
 		cur.data_index = find_var_index(ret);
@@ -902,18 +904,18 @@ compare_streams(const char *filename, bo
 	if (filename[0] != '/') {
 		if (strlcpy(check_file, check_path, sizeof(check_file))
 		>= sizeof(check_file))
-			err(2, "CHECK_PATH too long");
+			errx(2, "CHECK_PATH too long");
 
 		if (strlcat(check_file, "/", sizeof(check_file))
 		>= sizeof(check_file))
-			err(2, "Could not append / to check file path");
+			errx(2, "Could not append / to check file path");
 	} else {
 		

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb 15 06:46:01 UTC 2021

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

Log Message:
make: clean up code and comments around ModifyWord

In ModifyWords, there is no "passed string" anymore since that function
now directly operates on the expression value.

While here, improve the documentation of ModifyWordsCallback and rename
it to ModifyWordProc, focusing on its purpose instead of where it is
used.


To generate a diff of this commit:
cvs rdiff -u -r1.821 -r1.822 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.821 src/usr.bin/make/var.c:1.822
--- src/usr.bin/make/var.c:1.821	Sun Feb 14 22:48:17 2021
+++ src/usr.bin/make/var.c	Mon Feb 15 06:46:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.822 2021/02/15 06:46:01 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.822 2021/02/15 06:46:01 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1298,10 +1298,10 @@ SepBuf_DoneData(SepBuf *buf)
  * and typically adds a modification of this word to the buffer. It may also
  * do nothing or add several words.
  *
- * For example, in ${:Ua b c:M*2}, the callback is called 3 times, once for
- * each word of "a b c".
+ * For example, when evaluating the modifier ':M*b' in ${:Ua b c:M*b}, the
+ * callback is called 3 times, once for "a", "b" and "c".
  */
-typedef void (*ModifyWordsCallback)(const char *word, SepBuf *buf, void *data);
+typedef void (*ModifyWordProc)(const char *word, SepBuf *buf, void *data);
 
 
 /*
@@ -2324,16 +2324,12 @@ TryParseChar(const char **pp, int base, 
 }
 
 /*
- * Modify each of the words of the passed string using the given function.
- *
- * Input:
- *	str		String whose words should be modified
- *	modifyWord	Function that modifies a single word
- *	modifyWord_args Custom arguments for modifyWord
+ * Modify each word of the expression using the given function and place the
+ * result back in the expression.
  */
 static void
 ModifyWords(ApplyModifiersState *st,
-	ModifyWordsCallback modifyWord, void *modifyWord_args,
+	ModifyWordProc modifyWord, void *modifyWord_args,
 	Boolean oneBigWord)
 {
 	SepBuf result;
@@ -2667,7 +2663,7 @@ ApplyModifier_Match(const char **pp, App
 	Boolean needSubst = FALSE;
 	const char *endpat;
 	char *pattern;
-	ModifyWordsCallback callback;
+	ModifyWordProc modifyWord;
 
 	/*
 	 * In the loop below, ignore ':' unless we are at (or back to) the
@@ -2730,8 +2726,8 @@ ApplyModifier_Match(const char **pp, App
 	DEBUG3(VAR, "Pattern[%s] for [%s] is [%s]\n",
 	st->var->name.str, st->value.str, pattern);
 
-	callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
-	ModifyWords(st, callback, pattern, st->oneBigWord);
+	modifyWord = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
+	ModifyWords(st, modifyWord, pattern, st->oneBigWord);
 	free(pattern);
 	return AMR_OK;
 }
@@ -3359,7 +3355,7 @@ ApplyModifier_Remember(const char **pp, 
  */
 static ApplyModifierResult
 ApplyModifier_WordFunc(const char **pp, ApplyModifiersState *st,
-		   ModifyWordsCallback modifyWord)
+		   ModifyWordProc modifyWord)
 {
 	char delim = (*pp)[1];
 	if (delim != st->endc && delim != ':')



CVS commit: src/sys/netinet

2021-02-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Feb 15 03:41:01 UTC 2021

Modified Files:
src/sys/netinet: ip_flow.c

Log Message:
Fix build failure for options GATEWAY.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/netinet/ip_flow.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/netinet/ip_flow.c
diff -u src/sys/netinet/ip_flow.c:1.83 src/sys/netinet/ip_flow.c:1.84
--- src/sys/netinet/ip_flow.c:1.83	Sun Feb 14 20:58:35 2021
+++ src/sys/netinet/ip_flow.c	Mon Feb 15 03:41:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $	*/
+/*	$NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -231,7 +231,7 @@ ipflow_fastforward(struct mbuf *m)
 	 * IP header with no option and valid version and length
 	 */
 	ip = mtod(m, struct ip *);
-	if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT) {
+	if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT)) {
 		memcpy(_store, mtod(m, const void *), sizeof(ip_store));
 		ip = _store;
 	}



CVS commit: src/sys/sys

2021-02-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 15 00:44:09 UTC 2021

Modified Files:
src/sys/sys: mbuf.h

Log Message:
remove _ prefix from args


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/sys/sys/mbuf.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/sys/mbuf.h
diff -u src/sys/sys/mbuf.h:1.228 src/sys/sys/mbuf.h:1.229
--- src/sys/sys/mbuf.h:1.228	Sun Feb 14 15:58:35 2021
+++ src/sys/sys/mbuf.h	Sun Feb 14 19:44:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.h,v 1.228 2021/02/14 20:58:35 christos Exp $	*/
+/*	$NetBSD: mbuf.h,v 1.229 2021/02/15 00:44:09 christos Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -844,14 +844,14 @@ m_copy_rcvif(struct mbuf *m, const struc
 }
 
 static __inline int
-m_get_aligned_hdr(struct mbuf **_m, int _align, size_t _hlen, bool _linkhdr)
+m_get_aligned_hdr(struct mbuf **m, int align, size_t hlen, bool linkhdr)
 {
-	if (POINTER_ALIGNED_P(mtod(*_m, void *), _align) == 0)
-		*_m = m_copyup(*_m, _hlen, 
-		  _linkhdr ? (max_linkhdr + _align) & ~_align : 0);
-	else if (__predict_false((*_m)->m_len < _hlen))
-		*_m = m_pullup(*_m, _hlen);
-	return *_m == NULL;
+	if (POINTER_ALIGNED_P(mtod(*m, void *), align) == 0)
+		*m = m_copyup(*m, hlen, 
+		  linkhdr ? (max_linkhdr + align) & ~align : 0);
+	else if (__predict_false((*m)->m_len < hlen))
+		*m = m_pullup(*m, hlen);
+	return *m == NULL;
 }
 
 void m_print(const struct mbuf *, const char *, void (*)(const char *, ...)



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 22:48:17 UTC 2021

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

Log Message:
make: clean up memory management in evaluation of expressions

The condition "st->newValue.str != val" in ApplySingleModifier made the
memory management look more complicated than it really was.  Freeing an
object based on another object's value is harder to understand than
necessary.

To fix this, the "current value" of the expression is now stored in
ApplyModifiersState, and it gets updated in-place by the ApplyModifier
functions.  This reduces the number of parameters for the ApplyModifier
functions.

Accessing the current value of the expression is now more verbose than
before (st->value.str instead of the simple val).  To compensate for
this verbosity, ApplyModifiersIndirect is now much easier to understand
since there is no extra "current value" floating around.

There is still room for improvement.  In ApplyModifiers, passing an FStr
in and returning another (or possibly the same) makes it difficult to
understand memory management.  Adding a separate Expr type that outlives
the ApplyModifiersState will make this easier, in a follow-up commit.


To generate a diff of this commit:
cvs rdiff -u -r1.820 -r1.821 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.820 src/usr.bin/make/var.c:1.821
--- src/usr.bin/make/var.c:1.820	Sun Feb 14 21:54:42 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 22:48:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.820 2021/02/14 21:54:42 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.820 2021/02/14 21:54:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1934,9 +1934,9 @@ VarStrftime(const char *fmt, Boolean zul
 /*
  * The ApplyModifier functions take an expression that is being evaluated.
  * Their task is to apply a single modifier to the expression.
- * To do this, they parse the modifier and its parameters from pp and apply
- * the parsed modifier to the current value of the expression, generating a
- * new value from it.
+ * To do this, they parse the modifier and its parameters from pp, apply
+ * the parsed modifier to the current value of the expression and finally
+ * update the value of the expression.
  *
  * The modifier typically lasts until the next ':', or a closing '}' or ')'
  * (taken from st->endc), or the end of the string (parse error).
@@ -1983,8 +1983,9 @@ VarStrftime(const char *fmt, Boolean zul
  * during parsing though.
  *
  * Evaluating the modifier usually takes the current value of the variable
- * expression from st->val, or the variable name from st->var->name and stores
- * the result in st->newValue.
+ * expression from st->value, or the variable name from st->var->name and
+ * stores the result back in st->value via Expr_SetValueOwn or
+ * Expr_SetValueRefer.
  *
  * If evaluating fails (as of 2020-08-23), an error message is printed using
  * Error.  This function has no side-effects, it really just prints the error
@@ -1995,7 +1996,7 @@ VarStrftime(const char *fmt, Boolean zul
  * Housekeeping
  *
  * Some modifiers such as :D and :U turn undefined expressions into defined
- * expressions (see VEF_UNDEF, VEF_DEF).
+ * expressions (see Expr_Define).
  *
  * Some modifiers need to free some memory.
  */
@@ -2027,11 +2028,8 @@ typedef struct ApplyModifiersState {
 	Var *const var;
 	GNode *const scope;
 	const VarEvalFlags eflags;
-	/*
-	 * The new value of the expression, after applying the modifier,
-	 * never NULL.
-	 */
-	FStr newValue;
+	/* The value of the expression, never NULL. */
+	FStr value;
 	/* Word separator in expansions (see the :ts modifier). */
 	char sep;
 	/*
@@ -2055,13 +2053,15 @@ Expr_Define(Expr *expr)
 static void
 Expr_SetValueOwn(Expr *expr, char *value)
 {
-	expr->newValue = FStr_InitOwn(value);
+	FStr_Done(>value);
+	expr->value = FStr_InitOwn(value);
 }
 
 static void
 Expr_SetValueRefer(Expr *expr, const char *value)
 {
-	expr->newValue = FStr_InitRefer(value);
+	FStr_Done(>value);
+	expr->value = FStr_InitRefer(value);
 }
 
 typedef enum ApplyModifierResult {
@@ -2332,7 +2332,7 @@ TryParseChar(const char **pp, int base, 
  *	modifyWord_args Custom arguments for modifyWord
  */
 static void
-ModifyWords(ApplyModifiersState *st, const char *str,
+ModifyWords(ApplyModifiersState *st,
 	ModifyWordsCallback modifyWord, void *modifyWord_args,
 	Boolean oneBigWord)
 {
@@ -2342,16 +2342,16 @@ ModifyWords(ApplyModifiersState *st, con
 
 	if (oneBigWord) {
 		SepBuf_Init(, st->sep);
-		modifyWord(str, , modifyWord_args);
+		

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 21:54:42 UTC 2021

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

Log Message:
make: reduce redundant code around ModifyWords

The result of ModifyWords had been passed to Expr_SetValueOwn in all
cases.  The last argument to ModifyWords had always been st->sep.


To generate a diff of this commit:
cvs rdiff -u -r1.819 -r1.820 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.819 src/usr.bin/make/var.c:1.820
--- src/usr.bin/make/var.c:1.819	Sun Feb 14 20:22:30 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 21:54:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.819 2021/02/14 20:22:30 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.820 2021/02/14 21:54:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.819 2021/02/14 20:22:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.820 2021/02/14 21:54:42 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1783,50 +1783,6 @@ ModifyWord_Realpath(const char *word, Se
 	SepBuf_AddStr(buf, word);
 }
 
-/*
- * Modify each of the words of the passed string using the given function.
- *
- * Input:
- *	str		String whose words should be modified
- *	modifyWord	Function that modifies a single word
- *	modifyWord_args Custom arguments for modifyWord
- *
- * Results:
- *	A string of all the words modified appropriately.
- */
-static char *
-ModifyWords(const char *str,
-	ModifyWordsCallback modifyWord, void *modifyWord_args,
-	Boolean oneBigWord, char sep)
-{
-	SepBuf result;
-	Words words;
-	size_t i;
-
-	if (oneBigWord) {
-		SepBuf_Init(, sep);
-		modifyWord(str, , modifyWord_args);
-		return SepBuf_DoneData();
-	}
-
-	SepBuf_Init(, sep);
-
-	words = Str_Words(str, FALSE);
-
-	DEBUG2(VAR, "ModifyWords: split \"%s\" into %u words\n",
-	str, (unsigned)words.len);
-
-	for (i = 0; i < words.len; i++) {
-		modifyWord(words.words[i], , modifyWord_args);
-		if (result.buf.len > 0)
-			SepBuf_Sep();
-	}
-
-	Words_Free(words);
-
-	return SepBuf_DoneData();
-}
-
 
 static char *
 Words_JoinFree(Words words)
@@ -2367,6 +2323,48 @@ TryParseChar(const char **pp, int base, 
 	return TRUE;
 }
 
+/*
+ * Modify each of the words of the passed string using the given function.
+ *
+ * Input:
+ *	str		String whose words should be modified
+ *	modifyWord	Function that modifies a single word
+ *	modifyWord_args Custom arguments for modifyWord
+ */
+static void
+ModifyWords(ApplyModifiersState *st, const char *str,
+	ModifyWordsCallback modifyWord, void *modifyWord_args,
+	Boolean oneBigWord)
+{
+	SepBuf result;
+	Words words;
+	size_t i;
+
+	if (oneBigWord) {
+		SepBuf_Init(, st->sep);
+		modifyWord(str, , modifyWord_args);
+		goto done;
+	}
+
+	SepBuf_Init(, st->sep);
+
+	words = Str_Words(str, FALSE);
+
+	DEBUG2(VAR, "ModifyWords: split \"%s\" into %u words\n",
+	str, (unsigned)words.len);
+
+	for (i = 0; i < words.len; i++) {
+		modifyWord(words.words[i], , modifyWord_args);
+		if (result.buf.len > 0)
+			SepBuf_Sep();
+	}
+
+	Words_Free(words);
+
+done:
+	Expr_SetValueOwn(st, SepBuf_DoneData());
+}
+
 /* :@var@...${var}...@ */
 static ApplyModifierResult
 ApplyModifier_Loop(const char **pp, const char *val, ApplyModifiersState *st)
@@ -2396,8 +2394,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 */
-	Expr_SetValueOwn(st,
-	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
+	ModifyWords(st, val, ModifyWord_Loop, , st->oneBigWord);
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
 	/*
@@ -2736,8 +2733,7 @@ ApplyModifier_Match(const char **pp, con
 	st->var->name.str, val, pattern);
 
 	callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
-	Expr_SetValueOwn(st,
-	ModifyWords(val, callback, pattern, st->oneBigWord, st->sep));
+	ModifyWords(st, val, callback, pattern, st->oneBigWord);
 	free(pattern);
 	return AMR_OK;
 }
@@ -2796,8 +2792,7 @@ ApplyModifier_Subst(const char **pp, con
 			break;
 	}
 
-	Expr_SetValueOwn(st,
-	ModifyWords(val, ModifyWord_Subst, , oneBigWord, st->sep));
+	ModifyWords(st, val, ModifyWord_Subst, , oneBigWord);
 
 	free(lhs);
 	free(rhs);
@@ -2860,9 +2855,9 @@ ApplyModifier_Regex(const char **pp, con
 	args.nsub = args.re.re_nsub + 1;
 	if (args.nsub > 10)
 		args.nsub = 10;
-	Expr_SetValueOwn(st,
-	ModifyWords(val, ModifyWord_SubstRegex, ,
-		oneBigWord, st->sep));
+
+	ModifyWords(st, val, ModifyWord_SubstRegex, , oneBigWord);
+
 	regfree();
 	free(args.replace);
 	return AMR_OK;
@@ -2956,8 +2951,7 @@ ApplyModifier_ToSep(const char **pp, con
 	}
 
 ok:
-	

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 21:32:58 UTC 2021

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

Log Message:
make: clean up FStr and MFStr memory in cleanup mode


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.202 src/usr.bin/make/nonints.h:1.203
--- src/usr.bin/make/nonints.h:1.202	Fri Feb  5 05:15:12 2021
+++ src/usr.bin/make/nonints.h	Sun Feb 14 21:32:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.202 2021/02/05 05:15:12 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.203 2021/02/14 21:32:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -204,6 +204,10 @@ MAKE_INLINE void
 FStr_Done(FStr *fstr)
 {
 	free(fstr->freeIt);
+#ifdef CLEANUP
+	fstr->str = NULL;
+	fstr->freeIt = NULL;
+#endif
 }
 
 /* Return a string that is the sole owner of str. */
@@ -224,6 +228,10 @@ MAKE_INLINE void
 MFStr_Done(MFStr *mfstr)
 {
 	free(mfstr->freeIt);
+#ifdef CLEANUP
+	mfstr->str = NULL;
+	mfstr->freeIt = NULL;
+#endif
 }
 
 Words Str_Words(const char *, Boolean);



CVS commit: src/sys

2021-02-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb 14 20:58:35 UTC 2021

Modified Files:
src/sys/net: if_arp.h if_bridge.c
src/sys/netinet: icmp_private.h if_arp.c igmp_var.h in_l2tp.c ip_flow.c
ip_input.c ip_private.h tcp_input.c tcp_private.h udp_private.h
udp_usrreq.c
src/sys/netinet6: icmp6.c in6_l2tp.c ip6_flow.c ip6_input.c
ip6_private.h udp6_usrreq.c
src/sys/sys: mbuf.h param.h

Log Message:
- centralize header align and pullup into a single inline function
- use a single macro to align pointers and expose the alignment, instead
  of hard-coding 3 in 1/2 the macros.
- fix an issue in the ipv6 lt2p where it was aligning for ipv4 and pulling
  for ipv6.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/net/if_arp.h
cvs rdiff -u -r1.177 -r1.178 src/sys/net/if_bridge.c
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/icmp_private.h \
src/sys/netinet/ip_private.h src/sys/netinet/tcp_private.h \
src/sys/netinet/udp_private.h
cvs rdiff -u -r1.301 -r1.302 src/sys/netinet/if_arp.c
cvs rdiff -u -r1.25 -r1.26 src/sys/netinet/igmp_var.h
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.82 -r1.83 src/sys/netinet/ip_flow.c
cvs rdiff -u -r1.397 -r1.398 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.424 -r1.425 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.259 -r1.260 src/sys/netinet/udp_usrreq.c
cvs rdiff -u -r1.247 -r1.248 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.40 -r1.41 src/sys/netinet6/ip6_flow.c
cvs rdiff -u -r1.222 -r1.223 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet6/ip6_private.h
cvs rdiff -u -r1.148 -r1.149 src/sys/netinet6/udp6_usrreq.c
cvs rdiff -u -r1.227 -r1.228 src/sys/sys/mbuf.h
cvs rdiff -u -r1.684 -r1.685 src/sys/sys/param.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/net/if_arp.h
diff -u src/sys/net/if_arp.h:1.39 src/sys/net/if_arp.h:1.40
--- src/sys/net/if_arp.h:1.39	Sun Feb 14 14:47:16 2021
+++ src/sys/net/if_arp.h	Sun Feb 14 15:58:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.39 2021/02/14 19:47:16 roy Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.40 2021/02/14 20:58:34 christos Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,6 +72,7 @@ struct	arphdr {
 	uint8_t  ar_tpa[];	/* target protocol address */
 #endif
 };
+#define	ARP_HDR_ALIGNMENT	3
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)

Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.177 src/sys/net/if_bridge.c:1.178
--- src/sys/net/if_bridge.c:1.177	Mon Nov  2 07:14:59 2020
+++ src/sys/net/if_bridge.c	Sun Feb 14 15:58:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.177 2020/11/02 12:14:59 roy Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.177 2020/11/02 12:14:59 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.178 2021/02/14 20:58:34 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2806,18 +2806,10 @@ bridge_ip_checkbasic(struct mbuf **mp)
 	if (*mp == NULL)
 		return -1;
 
-	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct ip),
-			(max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			ip_statinc(IP_STAT_TOOSMALL);
-			goto bad;
-		}
-	} else if (__predict_false(m->m_len < sizeof (struct ip))) {
-		if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
-			ip_statinc(IP_STAT_TOOSMALL);
-			goto bad;
-		}
+	if (m_get_aligned_hdr(, IP_HDR_ALIGNMENT, sizeof(*ip), true) != 0) {
+		/* XXXJRT new stat, please */
+		ip_statinc(IP_STAT_TOOSMALL);
+		goto bad;
 	}
 	ip = mtod(m, struct ip *);
 	if (ip == NULL) goto bad;
@@ -2908,22 +2900,12 @@ bridge_ip6_checkbasic(struct mbuf **mp)
 	 * it.  Otherwise, if it is aligned, make sure the entire base
 	 * IPv6 header is in the first mbuf of the chain.
 	 */
-	if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
+	if (m_get_aligned_hdr(, IP6_HDR_ALIGNMENT, sizeof(*ip6), true) != 0) {
 		struct ifnet *inifp = m_get_rcvif_NOMPSAFE(m);
-		if ((m = m_copyup(m, sizeof(struct ip6_hdr),
-		  (max_linkhdr + 3) & ~3)) == NULL) {
-			/* XXXJRT new stat, please */
-			ip6_statinc(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(inifp, ifs6_in_hdrerr);
-			goto bad;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
-		struct ifnet *inifp = m_get_rcvif_NOMPSAFE(m);
-		if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
-			ip6_statinc(IP6_STAT_TOOSMALL);
-			in6_ifstat_inc(inifp, ifs6_in_hdrerr);
-			goto bad;
-		}
+		/* XXXJRT new stat, please */
+		ip6_statinc(IP6_STAT_TOOSMALL);
+		in6_ifstat_inc(inifp, ifs6_in_hdrerr);
+		goto bad;
 	}
 
 	ip6 = mtod(m, struct ip6_hdr *);

Index: src/sys/netinet/icmp_private.h
diff -u 

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

2021-02-14 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Sun Feb 14 20:30:31 UTC 2021

Modified Files:
src/sys/arch/sparc64/doc: TODO

Log Message:
sun4v: update TODO with status of verified systems(T2000, T5 and qemu)


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/sparc64/doc/TODO

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/doc/TODO
diff -u src/sys/arch/sparc64/doc/TODO:1.32 src/sys/arch/sparc64/doc/TODO:1.33
--- src/sys/arch/sparc64/doc/TODO:1.32	Sun Jan 31 19:08:05 2021
+++ src/sys/arch/sparc64/doc/TODO	Sun Feb 14 20:30:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: TODO,v 1.32 2021/01/31 19:08:05 palle Exp $ */
+/* $NetBSD: TODO,v 1.33 2021/02/14 20:30:31 palle Exp $ */
 
 Things to be done:
 
@@ -11,7 +11,7 @@ sun4u:
 - GENERIC.UP kernel hangs on v445 (missing interrupt?)
 
 sun4v:
- - current status:
+ - current status (verified on T5 ldom with 2 VCPU and 4GB):
  The kernel boots and starts userland.
 	 During the execution of the sysinst process, a sub-process crashes.
 	 The crash happens when a call to sysctl from /bin/sh causes a mmu trap.
@@ -27,6 +27,7 @@ sun4v:
 	 may end up with a mmu fault again if the stack address is not present in the mmu, so
 	 perhaps spilling to the physical address of the stack will work.
 	 Time will show if this is correct...
+	 Status on T2000 ldom with 8 VCPU and 4GB is that is crashes in /sbin/init doing an access() call where %o0 is corrupted (zero)
 - 64-bit kernel support
 - 32-bit kernel support
 - libkvm
@@ -48,6 +49,6 @@ sun4v:
 - vbus.c: handle prom_getprop() memory leaks
 - locore.s: rft_user (sun4v specific manaul fill) - seems to work, but is it good enough (compared to openbsds rft_user?
  - platforms tested so far:
- -- qemu sun4v/niagara - crash in init process relaed to fork (stack?)
+ -- qemu sun4v/niagara - reaches the point where the kernel needs to mount a root fs
  -- T2000 - mmu fault somewhere
  -- T5 - stickcmpr is not properly initialized ???



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 20:22:30 UTC 2021

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

Log Message:
make: print error about failed shell command before overwriting variable

Memory management of the value of variable expressions is currently more
complicated than necessary.  It is the responsibility of ApplyModifiers,
even though conceptually the value belongs to an expression, so it
should rather be in Expr.  Right now, this is an alias for
ApplyModifiersState, but that will change soon.

When that is done, there will no longer be a "current value" and a "new
value", only a single "value" of an expression.  At that point, before
Expr_SetValueOwn will overwrite the old value with the output of the
shell command, the error message needs to refer to the latter.


To generate a diff of this commit:
cvs rdiff -u -r1.818 -r1.819 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.818 src/usr.bin/make/var.c:1.819
--- src/usr.bin/make/var.c:1.818	Sun Feb 14 18:59:36 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 20:22:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.818 2021/02/14 18:59:36 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.819 2021/02/14 20:22:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.818 2021/02/14 18:59:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.819 2021/02/14 20:22:30 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3463,9 +3463,10 @@ ApplyModifier_SunShell(const char **pp, 
 	if (p[1] == 'h' && (p[2] == st->endc || p[2] == ':')) {
 		if (st->eflags & VARE_WANTRES) {
 			const char *errfmt;
-			Expr_SetValueOwn(st, Cmd_Exec(val, ));
+			char *output = Cmd_Exec(val, );
 			if (errfmt != NULL)
 Error(errfmt, val);
+			Expr_SetValueOwn(st, output);
 		} else
 			Expr_SetValueRefer(st, "");
 		*pp = p + 2;



CVS commit: src

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 20:16:18 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile varmod-shell.mk
Added Files:
src/usr.bin/make/unit-tests: varmod-sun-shell.exp varmod-sun-shell.mk

Log Message:
make: add test for the variable modifier ':sh'


To generate a diff of this commit:
cvs rdiff -u -r1.1017 -r1.1018 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.270 -r1.271 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-shell.mk
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/varmod-sun-shell.exp \
src/usr.bin/make/unit-tests/varmod-sun-shell.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1017 src/distrib/sets/lists/tests/mi:1.1018
--- src/distrib/sets/lists/tests/mi:1.1017	Sat Feb 13 06:29:45 2021
+++ src/distrib/sets/lists/tests/mi	Sun Feb 14 20:16:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1017 2021/02/13 06:29:45 rillig Exp $
+# $NetBSD: mi,v 1.1018 2021/02/14 20:16:17 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5473,6 +5473,8 @@
 ./usr/tests/usr.bin/make/unit-tests/varmod-subst-regex.mk			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-subst.exptests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-subst.mktests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-sun-shell.exp			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-sun-shell.mktests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-sysv.exptests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-sysv.mktests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-tail.exptests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.270 src/usr.bin/make/unit-tests/Makefile:1.271
--- src/usr.bin/make/unit-tests/Makefile:1.270	Sun Feb 14 13:24:45 2021
+++ src/usr.bin/make/unit-tests/Makefile	Sun Feb 14 20:16:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.270 2021/02/14 13:24:45 rillig Exp $
+# $NetBSD: Makefile,v 1.271 2021/02/14 20:16:17 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -362,6 +362,7 @@ TESTS+=		varmod-select-words
 TESTS+=		varmod-shell
 TESTS+=		varmod-subst
 TESTS+=		varmod-subst-regex
+TESTS+=		varmod-sun-shell
 TESTS+=		varmod-sysv
 TESTS+=		varmod-tail
 TESTS+=		varmod-to-abs

Index: src/usr.bin/make/unit-tests/varmod-shell.mk
diff -u src/usr.bin/make/unit-tests/varmod-shell.mk:1.5 src/usr.bin/make/unit-tests/varmod-shell.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-shell.mk:1.5	Tue Nov 17 20:11:02 2020
+++ src/usr.bin/make/unit-tests/varmod-shell.mk	Sun Feb 14 20:16:17 2021
@@ -1,15 +1,13 @@
-# $NetBSD: varmod-shell.mk,v 1.5 2020/11/17 20:11:02 rillig Exp $
+# $NetBSD: varmod-shell.mk,v 1.6 2021/02/14 20:16:17 rillig Exp $
 #
-# Tests for the :sh variable modifier, which runs the shell command
-# given by the variable value and returns its output.
+# Tests for the ':!cmd!' variable modifier, which runs the shell command
+# given by the variable modifier and returns its output.
 #
 # This modifier has been added on 2000-04-29.
 #
 # See also:
 #	ApplyModifier_ShellCommand
 
-# TODO: Implementation
-
 # The command to be run is enclosed between exclamation marks.
 # The previous value of the expression is irrelevant for this modifier.
 # The :!cmd! modifier turns an undefined expression into a defined one.
@@ -32,4 +30,3 @@
 .endif
 
 all:
-	@:;

Added files:

Index: src/usr.bin/make/unit-tests/varmod-sun-shell.exp
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-sun-shell.exp:1.1
--- /dev/null	Sun Feb 14 20:16:18 2021
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.exp	Sun Feb 14 20:16:17 2021
@@ -0,0 +1,2 @@
+make: "echo word; false" returned non-zero status
+exit status 0
Index: src/usr.bin/make/unit-tests/varmod-sun-shell.mk
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-sun-shell.mk:1.1
--- /dev/null	Sun Feb 14 20:16:18 2021
+++ src/usr.bin/make/unit-tests/varmod-sun-shell.mk	Sun Feb 14 20:16:17 2021
@@ -0,0 +1,21 @@
+# $NetBSD: varmod-sun-shell.mk,v 1.1 2021/02/14 20:16:17 rillig Exp $
+#
+# Tests for the :sh variable modifier, which runs the shell command
+# given by the variable value and returns its output.
+#
+# This modifier has been added on 1996-05-29.
+#
+# See also:
+#	ApplyModifier_SunShell
+
+.if ${echo word:L:sh} != "word"
+.  error
+.endif
+
+# If the command exits with non-zero, an error message is printed.
+# XXX: Processing continues as usual though.
+.if ${echo word; false:L:sh} != "word"
+.  error
+.endif
+
+all:



CVS commit: src/sys

2021-02-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Feb 14 19:47:17 UTC 2021

Modified Files:
src/sys/net: if_arp.h
src/sys/netinet: if_arp.c

Log Message:
if_arp: Just KASSERT that arphrd is aligned

While here improve readability of checking ARP IEEE1394 matches interface.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_arp.h
cvs rdiff -u -r1.300 -r1.301 src/sys/netinet/if_arp.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/net/if_arp.h
diff -u src/sys/net/if_arp.h:1.38 src/sys/net/if_arp.h:1.39
--- src/sys/net/if_arp.h:1.38	Sat Feb 13 07:57:09 2021
+++ src/sys/net/if_arp.h	Sun Feb 14 19:47:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.38 2021/02/13 07:57:09 roy Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.39 2021/02/14 19:47:16 roy Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,14 +72,6 @@ struct	arphdr {
 	uint8_t  ar_tpa[];	/* target protocol address */
 #endif
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ARP_HDR_ALIGNED_P(ah)	1
-#else
-#define	ARP_HDR_ALIGNED_P(ah)	vaddr_t) (ah)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct arphdr) == 8);
-#endif
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.300 src/sys/netinet/if_arp.c:1.301
--- src/sys/netinet/if_arp.c:1.300	Sat Feb 13 13:00:16 2021
+++ src/sys/netinet/if_arp.c	Sun Feb 14 19:47:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.300 2021/02/13 13:00:16 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.301 2021/02/14 19:47:17 roy Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.300 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.301 2021/02/14 19:47:17 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -133,6 +133,12 @@ __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
 
+#ifdef __NO_STRICT_ALIGNMENT
+#define	ARP_HDR_ALIGNED_P(ar)	1
+#else
+#define	ARP_HDR_ALIGNED_P(ar)	vaddr_t) (ar)) & 1) == 0)
+#endif
+
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;
@@ -684,10 +690,11 @@ arpintr(void)
 	struct arphdr *ar;
 	int s;
 	int arplen;
+	struct ifnet *rcvif;
+	bool badhrd;
 
 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	for (;;) {
-		struct ifnet *rcvif;
 
 		IFQ_LOCK();
 		IF_DEQUEUE(, m);
@@ -700,15 +707,12 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		/* Enforce alignment */
-		if (ARP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-			if ((m = m_copyup(m, sizeof(*ar), 0)) == NULL)
-goto badlen;
-		} else if (__predict_false(m->m_len < sizeof(*ar))) {
+		if (__predict_false(m->m_len < sizeof(*ar))) {
 			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
 goto badlen;
 		}
 		ar = mtod(m, struct arphdr *);
+		KASSERT(ARP_HDR_ALIGNED_P(ar));
 
 		rcvif = m_get_rcvif(m, );
 		if (__predict_false(rcvif == NULL)) {
@@ -720,27 +724,20 @@ arpintr(void)
 		 * We don't want non-IEEE1394 ARP packets on IEEE1394
 		 * interfaces, and vice versa. Our life depends on that.
 		 */
-		switch (rcvif->if_type) {
-		case IFT_IEEE1394:
-			if (ntohs(ar->ar_hrd) != ARPHRD_IEEE1394) {
-m_put_rcvif(rcvif, );
-ARP_STATINC(ARP_STAT_RCVBADPROTO);
-goto free;
-			}
-			break;
-		default:
-			if (ntohs(ar->ar_hrd) == ARPHRD_IEEE1394) {
-m_put_rcvif(rcvif, );
-ARP_STATINC(ARP_STAT_RCVBADPROTO);
-goto free;
-			}
-			break;
-		}
+		if (ntohs(ar->ar_hrd) == ARPHRD_IEEE1394)
+			badhrd = rcvif->if_type != IFT_IEEE1394;
+		else
+			badhrd = rcvif->if_type == IFT_IEEE1394;
 
 		m_put_rcvif(rcvif, );
 
+		if (badhrd) {
+			ARP_STATINC(ARP_STAT_RCVBADPROTO);
+			goto free;
+		}
+
 		arplen = sizeof(*ar) + 2 * ar->ar_hln + 2 * ar->ar_pln;
-		if (m->m_len < arplen) {
+		if (__predict_false(m->m_len < arplen)) {
 			if ((m = m_pullup(m, arplen)) == NULL)
 goto badlen;
 			ar = mtod(m, struct arphdr *);



CVS commit: src/sys/net

2021-02-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Feb 14 19:35:38 UTC 2021

Modified Files:
src/sys/net: if_ether.h if_ethersubr.c

Log Message:
if_ether: revert prior alignment checks

Apparently not needed as our drivers ensure this.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/net/if_ether.h
cvs rdiff -u -r1.291 -r1.292 src/sys/net/if_ethersubr.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/net/if_ether.h
diff -u src/sys/net/if_ether.h:1.85 src/sys/net/if_ether.h:1.86
--- src/sys/net/if_ether.h:1.85	Sat Feb 13 07:28:04 2021
+++ src/sys/net/if_ether.h	Sun Feb 14 19:35:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.85 2021/02/13 07:28:04 roy Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.86 2021/02/14 19:35:37 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -89,15 +89,6 @@ struct ether_header {
 	uint8_t  ether_shost[ETHER_ADDR_LEN];
 	uint16_t ether_type;
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ETHER_HDR_ALIGNED_P(eh)	1
-#else
-#define	ETHER_HDR_ALIGNED_P(eh)	vaddr_t) (eh)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct ether_addr) == 6);
-__CTASSERT(sizeof(struct ether_header) == 14);
-#endif
 
 #include 
 

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.291 src/sys/net/if_ethersubr.c:1.292
--- src/sys/net/if_ethersubr.c:1.291	Sat Feb 13 13:00:16 2021
+++ src/sys/net/if_ethersubr.c	Sun Feb 14 19:35:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.292 2021/02/14 19:35:37 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.292 2021/02/14 19:35:37 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -164,6 +164,9 @@ extern u_char	aarp_org_code[3];
 #include 
 #endif
 
+CTASSERT(sizeof(struct ether_addr) == 6);
+CTASSERT(sizeof(struct ether_header) == 14);
+
 #ifdef DIAGNOSTIC
 static struct timeval bigpktppslim_last;
 static int bigpktppslim = 2;	/* XXX */
@@ -653,11 +656,7 @@ ether_input(struct ifnet *ifp, struct mb
 	m_claimm(m, >ec_rx_mowner);
 #endif
 
-	/* Enforce alignement */
-	if (ETHER_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(*eh), 0)) == NULL)
-			goto dropped;
-	} else if (__predict_false(m->m_len < sizeof(*eh))) {
+	if (__predict_false(m->m_len < sizeof(*eh))) {
 		if ((m = m_pullup(m, sizeof(*eh))) == NULL)
 			goto dropped;
 	}



CVS commit: src/sys/net

2021-02-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Feb 14 19:33:29 UTC 2021

Modified Files:
src/sys/net: if_gre.c if_gre.h

Log Message:
if_gre: Remove alignment checks in favour copying to stack

Makes the code a lot simpler, idea from dyoung@


To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/sys/net/if_gre.c
cvs rdiff -u -r1.48 -r1.49 src/sys/net/if_gre.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/net/if_gre.c
diff -u src/sys/net/if_gre.c:1.179 src/sys/net/if_gre.c:1.180
--- src/sys/net/if_gre.c:1.179	Sat Feb 13 13:00:16 2021
+++ src/sys/net/if_gre.c	Sun Feb 14 19:33:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $ */
+/*	$NetBSD: if_gre.c,v 1.180 2021/02/14 19:33:29 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.180 2021/02/14 19:33:29 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -142,6 +142,8 @@ int gre_debug = 0;
 #define	GRE_DPRINTF(__sc, __fmt, ...)	do { } while (/*CONSTCOND*/0)
 #endif /* GRE_DEBUG */
 
+CTASSERT(sizeof(struct gre_h) == 4);
+
 int ip_gre_ttl = GRE_TTL;
 
 static u_int gre_count;
@@ -374,7 +376,7 @@ gre_receive(struct socket *so, void *arg
 {
 	struct gre_softc *sc = (struct gre_softc *)arg;
 	int rc;
-	const struct gre_h *gh;
+	struct gre_h gh;
 	struct mbuf *m;
 
 	GRE_DPRINTF(sc, "enter\n");
@@ -396,24 +398,16 @@ gre_receive(struct socket *so, void *arg
 		return;
 	}
 
-	/* Enforce alignment */
-	if (GRE_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct gre_h), 0)) == NULL) {
-			/* XXXJRT new stat, please */
-			GRE_DPRINTF(sc, "m_copyup failed\n");
-			sc->sc_pullup_ev.ev_count++;
-			return;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct gre_h))) {
-		if ((m = m_pullup(m, sizeof(struct gre_h))) == NULL) {
+	if (__predict_false(m->m_len < sizeof(gh))) {
+		if ((m = m_pullup(m, sizeof(gh))) == NULL) {
 			GRE_DPRINTF(sc, "m_pullup failed\n");
 			sc->sc_pullup_ev.ev_count++;
 			return;
 		}
 	}
-	gh = mtod(m, const struct gre_h *);
+	memcpy(, mtod(m, void *), sizeof(gh));
 
-	if (gre_input(sc, m, gh) == 0) {
+	if (gre_input(sc, m, ) == 0) {
 		sc->sc_unsupp_ev.ev_count++;
 		GRE_DPRINTF(sc, "dropping unsupported\n");
 		m_freem(m);
@@ -898,7 +892,7 @@ gre_output(struct ifnet *ifp, struct mbu
 {
 	int error = 0;
 	struct gre_softc *sc = ifp->if_softc;
-	struct gre_h *gh;
+	struct gre_h gh = { .flags = 0 };
 	uint16_t etype = 0;
 
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
@@ -950,17 +944,15 @@ gre_output(struct ifnet *ifp, struct mbu
 	}
 #endif
 
-	M_PREPEND(m, sizeof(*gh), M_DONTWAIT);
+	M_PREPEND(m, sizeof(gh), M_DONTWAIT);
 	if (m == NULL) {
 		IF_DROP(>if_snd);
 		error = ENOBUFS;
 		goto end;
 	}
 
-	gh = mtod(m, struct gre_h *);
-	KASSERT(GRE_HDR_ALIGNED_P(gh));
-	gh->flags = 0;
-	gh->ptype = etype;
+	gh.ptype = etype;
+	memcpy(mtod(m, void *), , sizeof(gh));
 	/* XXX Need to handle IP ToS.  Look at how I handle IP TTL. */
 
 	if_statadd2(ifp, if_opackets, 1, if_obytes, m->m_pkthdr.len);

Index: src/sys/net/if_gre.h
diff -u src/sys/net/if_gre.h:1.48 src/sys/net/if_gre.h:1.49
--- src/sys/net/if_gre.h:1.48	Fri Feb 12 19:57:49 2021
+++ src/sys/net/if_gre.h	Sun Feb 14 19:33:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.h,v 1.48 2021/02/12 19:57:49 roy Exp $ */
+/*	$NetBSD: if_gre.h,v 1.49 2021/02/14 19:33:29 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -131,15 +131,6 @@ struct gre_h {
 Present if (rt_pres == 1)
  */
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	GRE_HDR_ALIGNED_P(gh)	1
-#else
-#define	GRE_HDR_ALIGNED_P(gh)	vaddr_t) (gh)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct gre_h) == 4);
-#endif
-
 #define GRE_CP		0x8000  /* Checksum Present */
 #define GRE_RP		0x4000  /* Routing Present */
 #define GRE_KP		0x2000  /* Key Present */



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 18:59:36 UTC 2021

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

Log Message:
make: clean up ValidShortVarname

The switch statement was hard to read, especially the "break" that
needed a comment since it was effectively a "continue".


To generate a diff of this commit:
cvs rdiff -u -r1.817 -r1.818 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.817 src/usr.bin/make/var.c:1.818
--- src/usr.bin/make/var.c:1.817	Sun Feb 14 18:55:51 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 18:59:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.817 2021/02/14 18:55:51 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.818 2021/02/14 18:59:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.817 2021/02/14 18:55:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.818 2021/02/14 18:59:36 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3894,16 +3894,9 @@ ParseVarname(const char **pp, char start
 static VarParseResult
 ValidShortVarname(char varname, const char *start)
 {
-	switch (varname) {
-	case '\0':
-	case ')':
-	case '}':
-	case ':':
-	case '$':
-		break;		/* and continue below */
-	default:
+	if (varname != '$' && varname != ':' && varname != '}' &&
+	varname != ')' && varname != '\0')
 		return VPR_OK;
-	}
 
 	if (!opts.strict)
 		return VPR_ERR;	/* XXX: Missing error message */



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 18:55:51 UTC 2021

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

Log Message:
make: clean up ParseVarnameShort

Single-character short variable expressions such as $V neither have a
starting character nor an ending character.  The only interesting
character forms the complete variable name.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.816 -r1.817 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.816 src/usr.bin/make/var.c:1.817
--- src/usr.bin/make/var.c:1.816	Sun Feb 14 18:21:31 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 18:55:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.816 2021/02/14 18:21:31 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.817 2021/02/14 18:55:51 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.816 2021/02/14 18:21:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.817 2021/02/14 18:55:51 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3921,11 +3921,11 @@ ValidShortVarname(char varname, const ch
 }
 
 /*
- * Parse a single-character variable name such as $V or $@.
+ * Parse a single-character variable name such as in $V or $@.
  * Return whether to continue parsing.
  */
 static Boolean
-ParseVarnameShort(char startc, const char **pp, GNode *scope,
+ParseVarnameShort(char varname, const char **pp, GNode *scope,
 		  VarEvalFlags eflags,
 		  VarParseResult *out_FALSE_res, const char **out_FALSE_val,
 		  Var **out_TRUE_var)
@@ -3934,28 +3934,22 @@ ParseVarnameShort(char startc, const cha
 	Var *v;
 	VarParseResult vpr;
 
-	/*
-	 * If it's not bounded by braces of some sort, life is much simpler.
-	 * We just need to check for the first character and return the
-	 * value if it exists.
-	 */
-
-	vpr = ValidShortVarname(startc, *pp);
+	vpr = ValidShortVarname(varname, *pp);
 	if (vpr != VPR_OK) {
 		(*pp)++;
-		*out_FALSE_val = var_Error;
 		*out_FALSE_res = vpr;
+		*out_FALSE_val = var_Error;
 		return FALSE;
 	}
 
-	name[0] = startc;
+	name[0] = varname;
 	name[1] = '\0';
 	v = VarFind(name, scope, TRUE);
 	if (v == NULL) {
 		const char *val;
 		*pp += 2;
 
-		val = UndefinedShortVarValue(startc, scope);
+		val = UndefinedShortVarValue(varname, scope);
 		if (val == NULL)
 			val = eflags & VARE_UNDEFERR ? var_Error : varUndefined;
 



CVS commit: src/etc

2021-02-14 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sun Feb 14 18:45:44 UTC 2021

Modified Files:
src/etc: Makefile.params

Log Message:
Add KERNEL_DIR to /etc/release

"Sure, why not" from xtos!


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/etc/Makefile.params

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

Modified files:

Index: src/etc/Makefile.params
diff -u src/etc/Makefile.params:1.21 src/etc/Makefile.params:1.22
--- src/etc/Makefile.params:1.21	Fri Nov 22 13:30:19 2019
+++ src/etc/Makefile.params	Sun Feb 14 18:45:44 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.params,v 1.21 2019/11/22 13:30:19 martin Exp $
+#	$NetBSD: Makefile.params,v 1.22 2021/02/14 18:45:44 pgoyette Exp $
 #
 # Makefile fragment for printing build parameters.
 #
@@ -49,8 +49,8 @@ RELEASEVARS=	DISTRIBVER EXTERNAL_TOOLCHA
 .if ${MKREPRO:Uno} != "yes"
 RELEASEVARS+= 	BSDOBJDIR BSDSRCDIR BUILDID BUILDINFO BUILDSEED \
 		DESTDIR KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR MAKE \
-		MAKECONF MAKEFLAGS MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
-		NBUILDJOBS NETBSDSRCDIR OBJMACHINE OBJMACHINE_ARCH \
+		KERNEL_DIR MAKECONF MAKEFLAGS MAKEOBJDIR MAKEOBJDIRPREFIX \
+		MAKEVERBOSE NBUILDJOBS NETBSDSRCDIR OBJMACHINE OBJMACHINE_ARCH \
 		RELEASEDIR RELEASEMACHINEDIR TOOLDIR USR_OBJMACHINE X11SRCDIR
 .endif
 



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 18:21:31 UTC 2021

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

Log Message:
make: rename VarExprStatus to ExprStatus

It is only used in var.c so there is no need to use a prefix.


To generate a diff of this commit:
cvs rdiff -u -r1.815 -r1.816 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.815 src/usr.bin/make/var.c:1.816
--- src/usr.bin/make/var.c:1.815	Sun Feb 14 17:27:25 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 18:21:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.815 2021/02/14 17:27:25 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.816 2021/02/14 18:21:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.815 2021/02/14 17:27:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.816 2021/02/14 18:21:31 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2044,8 +2044,8 @@ VarStrftime(const char *fmt, Boolean zul
  * Some modifiers need to free some memory.
  */
 
-typedef enum VarExprStatus {
-	/* The variable expression is based in a regular, defined variable. */
+typedef enum ExprStatus {
+	/* The variable expression is based on a regular, defined variable. */
 	VES_NONE,
 	/* The variable expression is based on an undefined variable. */
 	VES_UNDEF,
@@ -2055,12 +2055,12 @@ typedef enum VarExprStatus {
 	 * undefined to defined.
 	 */
 	VES_DEF
-} VarExprStatus;
+} ExprStatus;
 
-static const char * const VarExprStatus_Name[] = {
-	"none",
-	"VES_UNDEF",
-	"VES_DEF"
+static const char *const ExprStatus_Name[] = {
+	"none",
+	"VES_UNDEF",
+	"VES_DEF"
 };
 
 typedef struct ApplyModifiersState {
@@ -2084,7 +2084,7 @@ typedef struct ApplyModifiersState {
 	 * big word, possibly containing spaces.
 	 */
 	Boolean oneBigWord;
-	VarExprStatus exprStatus;
+	ExprStatus exprStatus;
 } ApplyModifiersState;
 
 typedef ApplyModifiersState Expr;
@@ -3490,7 +3490,7 @@ LogBeforeApply(const ApplyModifiersState
 	st->var->name.str, mod[0], is_single_char ? "" : "...", val,
 	VarEvalFlags_ToString(eflags_str, st->eflags),
 	VarFlags_ToString(vflags_str, st->var->flags),
-	VarExprStatus_Name[st->exprStatus]);
+	ExprStatus_Name[st->exprStatus]);
 }
 
 static void
@@ -3506,7 +3506,7 @@ LogAfterApply(ApplyModifiersState *st, c
 	st->var->name.str, (int)(p - mod), mod, quot, newValue, quot,
 	VarEvalFlags_ToString(eflags_str, st->eflags),
 	VarFlags_ToString(vflags_str, st->var->flags),
-	VarExprStatus_Name[st->exprStatus]);
+	ExprStatus_Name[st->exprStatus]);
 }
 
 static ApplyModifierResult
@@ -3576,7 +3576,7 @@ ApplyModifier(const char **pp, const cha
 }
 
 static FStr ApplyModifiers(const char **, FStr, char, char, Var *,
-			VarExprStatus *, GNode *, VarEvalFlags);
+			   ExprStatus *, GNode *, VarEvalFlags);
 
 typedef enum ApplyModifiersIndirectResult {
 	/* The indirect modifiers have been applied successfully. */
@@ -3720,7 +3720,7 @@ ApplyModifiers(
 char startc,		/* '(' or '{', or '\0' for indirect modifiers */
 char endc,			/* ')' or '}', or '\0' for indirect modifiers */
 Var *v,
-VarExprStatus *exprStatus,
+ExprStatus *exprStatus,
 GNode *scope,		/* for looking up and modifying variables */
 VarEvalFlags eflags
 )
@@ -4070,7 +4070,7 @@ ParseVarnameLong(
 	Boolean *out_TRUE_haveModifier,
 	const char **out_TRUE_extraModifiers,
 	Boolean *out_TRUE_dynamic,
-	VarExprStatus *out_TRUE_exprStatus
+	ExprStatus *out_TRUE_exprStatus
 )
 {
 	size_t namelen;
@@ -4225,7 +4225,7 @@ Var_Parse(const char **pp, GNode *scope,
 	Var *v;
 	FStr value;
 	char eflags_str[VarEvalFlags_ToStringSize];
-	VarExprStatus exprStatus = VES_NONE;
+	ExprStatus exprStatus = VES_NONE;
 
 	DEBUG2(VAR, "Var_Parse: %s with %s\n", start,
 	VarEvalFlags_ToString(eflags_str, eflags));



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

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 17:47:33 UTC 2021

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

Log Message:
make: add test for indirect ':U' modifier

Unlike ':ts' and ':tW', the effects of ':U' are visible even after the
modifiers from the nested expression have been applied.  These subtle
details, like many others, are not documented in the manual page.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.7 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.8
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.7	Sun Feb 14 17:22:37 2021
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb 14 17:47:33 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.7 2021/02/14 17:22:37 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.8 2021/02/14 17:47:33 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
@@ -217,10 +217,31 @@ _:=	before ${UNDEF:${:UZ}} after
 .  error
 .endif
 # In this expression, the ':ts*' is indirect, therefore the changed separator
-# only lasts until the end of the indirect modifier.  It does not affect the
-# ':M' since that is outside the scope.
+# only applies to the modifiers from the indirect text.  It does not affect
+# the ':M' since that is not part of the text from the indirect modifier.
+#
+# Implementation detail: when ApplyModifiersIndirect calls ApplyModifiers
+# (which creates a new ApplyModifiersState containing a fresh separator),
+# the outer separator character is not passed by reference to the inner
+# evaluation, therefore the scope of the inner separator ends after applying
+# the modifier ':ts*'.
 .if ${1 2 3:L:${:Uts*}:Ua b c:M*} != "a b c"
 .  error
 .endif
 
+# A direct modifier ':U' turns the expression from undefined to defined.
+# An indirect modifier ':U' has the same effect, unlike the separator from
+# ':ts*' or the single-word marker from ':tW'.
+#
+# This is because when ApplyModifiersIndirect calls ApplyModifiers, it passes
+# the definedness of the outer expression by reference.  If that weren't the
+# case, the first condition below would result in a parse error because its
+# left-hand side would be undefined.
+.if ${UNDEF:${:UUindirect-fallback}} != "indirect-fallback"
+.  error
+.endif
+.if ${UNDEF:${:UUindirect-fallback}:Uouter-fallback} != "outer-fallback"
+.  error
+.endif
+
 all:



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 17:27:25 UTC 2021

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

Log Message:
make: revert part of previous commit

That code was not ready yet.


To generate a diff of this commit:
cvs rdiff -u -r1.814 -r1.815 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.814 src/usr.bin/make/var.c:1.815
--- src/usr.bin/make/var.c:1.814	Sun Feb 14 17:24:47 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 17:27:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.814 2021/02/14 17:24:47 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.815 2021/02/14 17:27:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.814 2021/02/14 17:24:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.815 2021/02/14 17:27:25 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2087,30 +2087,25 @@ typedef struct ApplyModifiersState {
 	VarExprStatus exprStatus;
 } ApplyModifiersState;
 
-/*
- * A variable expression such as $@ or ${VAR:Mpattern:Q}.
- */
-typedef struct Expr {
-	ApplyModifiersState *st;	/* only during ApplyModifiers */
-} Expr;
+typedef ApplyModifiersState Expr;
 
 static void
 Expr_Define(Expr *expr)
 {
-	if (expr->st->exprStatus == VES_UNDEF)
-		expr->st->exprStatus = VES_DEF;
+	if (expr->exprStatus == VES_UNDEF)
+		expr->exprStatus = VES_DEF;
 }
 
 static void
 Expr_SetValueOwn(Expr *expr, char *value)
 {
-	expr->st->newValue = FStr_InitOwn(value);
+	expr->newValue = FStr_InitOwn(value);
 }
 
 static void
 Expr_SetValueRefer(Expr *expr, const char *value)
 {
-	expr->st->newValue = FStr_InitRefer(value);
+	expr->newValue = FStr_InitRefer(value);
 }
 
 typedef enum ApplyModifierResult {
@@ -2145,7 +2140,7 @@ ParseModifierPartSubst(
 const char **pp,
 char delim,
 VarEvalFlags eflags,
-Expr *expr,
+ApplyModifiersState *st,
 char **out_part,
 /* Optionally stores the length of the returned string, just to save
  * another strlen call. */
@@ -2158,7 +2153,6 @@ ParseModifierPartSubst(
 struct ModifyWord_SubstArgs *subst
 )
 {
-	ApplyModifiersState *st = expr->st;
 	Buffer buf;
 	const char *p;
 
@@ -2287,11 +2281,11 @@ ParseModifierPart(
 /* Flags for evaluating nested variables; if VARE_WANTRES is not set,
  * the text is only parsed. */
 VarEvalFlags eflags,
-Expr *expr,
+ApplyModifiersState *st,
 char **out_part
 )
 {
-	return ParseModifierPartSubst(pp, delim, eflags, expr, out_part,
+	return ParseModifierPartSubst(pp, delim, eflags, st, out_part,
 	NULL, NULL, NULL);
 }
 
@@ -2375,9 +2369,8 @@ TryParseChar(const char **pp, int base, 
 
 /* :@var@...${var}...@ */
 static ApplyModifierResult
-ApplyModifier_Loop(const char **pp, const char *val, Expr *expr)
+ApplyModifier_Loop(const char **pp, const char *val, ApplyModifiersState *st)
 {
-	ApplyModifiersState *st = expr->st;
 	struct ModifyWord_LoopArgs args;
 	char prev_sep;
 	VarParseResult res;
@@ -2385,7 +2378,7 @@ ApplyModifier_Loop(const char **pp, cons
 	args.scope = st->scope;
 
 	(*pp)++;		/* Skip the first '@' */
-	res = ParseModifierPart(pp, '@', VARE_NONE, expr, );
+	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	if (opts.strict && strchr(args.tvar, '$') != NULL) {
@@ -2396,14 +2389,14 @@ ApplyModifier_Loop(const char **pp, cons
 		return AMR_CLEANUP;
 	}
 
-	res = ParseModifierPart(pp, '@', VARE_NONE, expr, );
+	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
 	args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 	prev_sep = st->sep;
 	st->sep = ' ';		/* XXX: should be st->sep for consistency */
-	Expr_SetValueOwn(expr,
+	Expr_SetValueOwn(st,
 	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2419,9 +2412,8 @@ ApplyModifier_Loop(const char **pp, cons
 
 /* :Ddefined or :Uundefined */
 static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, const char *val, Expr *expr)
+ApplyModifier_Defined(const char **pp, const char *val, ApplyModifiersState *st)
 {
-	ApplyModifiersState *st = expr->st;
 	Buffer buf;
 	const char *p;
 
@@ -2466,12 +2458,12 @@ ApplyModifier_Defined(const char **pp, c
 	}
 	*pp = p;
 
-	Expr_Define(expr);
+	Expr_Define(st);
 
 	if (eflags & VARE_WANTRES) {
-		Expr_SetValueOwn(expr, Buf_DoneData());
+		Expr_SetValueOwn(st, Buf_DoneData());
 	} else {
-		Expr_SetValueRefer(expr, val);
+		Expr_SetValueRefer(st, val);
 		Buf_Done();
 	}
 	return AMR_OK;
@@ -2479,10 +2471,10 @@ ApplyModifier_Defined(const char **pp, c
 
 /* :L */
 static ApplyModifierResult
-ApplyModifier_Literal(const char **pp, Expr *expr)

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 17:24:47 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-indirect.exp

Log Message:
make: update line numbers in expected test output

The documentation from the previous commit added a few lines.


To generate a diff of this commit:
cvs rdiff -u -r1.813 -r1.814 src/usr.bin/make/var.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-indirect.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.813 src/usr.bin/make/var.c:1.814
--- src/usr.bin/make/var.c:1.813	Sun Feb 14 13:53:28 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 17:24:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.813 2021/02/14 13:53:28 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.814 2021/02/14 17:24:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.813 2021/02/14 13:53:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.814 2021/02/14 17:24:47 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2087,25 +2087,30 @@ typedef struct ApplyModifiersState {
 	VarExprStatus exprStatus;
 } ApplyModifiersState;
 
-typedef ApplyModifiersState Expr;
+/*
+ * A variable expression such as $@ or ${VAR:Mpattern:Q}.
+ */
+typedef struct Expr {
+	ApplyModifiersState *st;	/* only during ApplyModifiers */
+} Expr;
 
 static void
 Expr_Define(Expr *expr)
 {
-	if (expr->exprStatus == VES_UNDEF)
-		expr->exprStatus = VES_DEF;
+	if (expr->st->exprStatus == VES_UNDEF)
+		expr->st->exprStatus = VES_DEF;
 }
 
 static void
 Expr_SetValueOwn(Expr *expr, char *value)
 {
-	expr->newValue = FStr_InitOwn(value);
+	expr->st->newValue = FStr_InitOwn(value);
 }
 
 static void
 Expr_SetValueRefer(Expr *expr, const char *value)
 {
-	expr->newValue = FStr_InitRefer(value);
+	expr->st->newValue = FStr_InitRefer(value);
 }
 
 typedef enum ApplyModifierResult {
@@ -2140,7 +2145,7 @@ ParseModifierPartSubst(
 const char **pp,
 char delim,
 VarEvalFlags eflags,
-ApplyModifiersState *st,
+Expr *expr,
 char **out_part,
 /* Optionally stores the length of the returned string, just to save
  * another strlen call. */
@@ -2153,6 +2158,7 @@ ParseModifierPartSubst(
 struct ModifyWord_SubstArgs *subst
 )
 {
+	ApplyModifiersState *st = expr->st;
 	Buffer buf;
 	const char *p;
 
@@ -2281,11 +2287,11 @@ ParseModifierPart(
 /* Flags for evaluating nested variables; if VARE_WANTRES is not set,
  * the text is only parsed. */
 VarEvalFlags eflags,
-ApplyModifiersState *st,
+Expr *expr,
 char **out_part
 )
 {
-	return ParseModifierPartSubst(pp, delim, eflags, st, out_part,
+	return ParseModifierPartSubst(pp, delim, eflags, expr, out_part,
 	NULL, NULL, NULL);
 }
 
@@ -2369,8 +2375,9 @@ TryParseChar(const char **pp, int base, 
 
 /* :@var@...${var}...@ */
 static ApplyModifierResult
-ApplyModifier_Loop(const char **pp, const char *val, ApplyModifiersState *st)
+ApplyModifier_Loop(const char **pp, const char *val, Expr *expr)
 {
+	ApplyModifiersState *st = expr->st;
 	struct ModifyWord_LoopArgs args;
 	char prev_sep;
 	VarParseResult res;
@@ -2378,7 +2385,7 @@ ApplyModifier_Loop(const char **pp, cons
 	args.scope = st->scope;
 
 	(*pp)++;		/* Skip the first '@' */
-	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
+	res = ParseModifierPart(pp, '@', VARE_NONE, expr, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	if (opts.strict && strchr(args.tvar, '$') != NULL) {
@@ -2389,14 +2396,14 @@ ApplyModifier_Loop(const char **pp, cons
 		return AMR_CLEANUP;
 	}
 
-	res = ParseModifierPart(pp, '@', VARE_NONE, st, );
+	res = ParseModifierPart(pp, '@', VARE_NONE, expr, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
 	args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 	prev_sep = st->sep;
 	st->sep = ' ';		/* XXX: should be st->sep for consistency */
-	Expr_SetValueOwn(st,
+	Expr_SetValueOwn(expr,
 	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2412,8 +2419,9 @@ ApplyModifier_Loop(const char **pp, cons
 
 /* :Ddefined or :Uundefined */
 static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, const char *val, ApplyModifiersState *st)
+ApplyModifier_Defined(const char **pp, const char *val, Expr *expr)
 {
+	ApplyModifiersState *st = expr->st;
 	Buffer buf;
 	const char *p;
 
@@ -2458,12 +2466,12 @@ ApplyModifier_Defined(const char **pp, c
 	}
 	*pp = p;
 
-	Expr_Define(st);
+	Expr_Define(expr);
 
 	if (eflags & VARE_WANTRES) {
-		Expr_SetValueOwn(st, Buf_DoneData());
+		Expr_SetValueOwn(expr, Buf_DoneData());
 	} else {
-		Expr_SetValueRefer(st, val);
+		Expr_SetValueRefer(expr, val);
 		Buf_Done();
 	}

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

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 17:22:37 UTC 2021

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

Log Message:
make: document since when indirect modifiers are supported


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.6 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.7
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.6	Sun Feb 14 16:12:46 2021
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Feb 14 17:22:37 2021
@@ -1,11 +1,13 @@
-# $NetBSD: varmod-indirect.mk,v 1.6 2021/02/14 16:12:46 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.7 2021/02/14 17:22:37 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
 # uppercase or lowercase, as well as for fairly advanced modifiers that first
 # look like line noise and are hard to decipher.
 #
-# TODO: Since when are indirect modifiers supported?
+# Initial support for indirect modifiers was added in var.c 1.101 from
+# 2006-02-18.  Since var.c 1.108 from 2006-05-11 it is possible to use
+# indirect modifiers for all but the very first modifier as well.
 
 
 # To apply a modifier indirectly via another variable, the whole
@@ -202,7 +204,7 @@ _:=	before ${UNDEF:${:UZ}} after
 # interpretation only lasts until the end of the indirect modifier, it does
 # not influence the outer variable expression.
 #
-# In this expression, the direct ':ts*' has no effect since ':U' does not
+# In this first expression, the direct ':ts*' has no effect since ':U' does not
 # treat the expression value as a list of words but as a single word.  It has
 # to be ':U', not ':D', since the "expression name" is "1 2 3" and there is no
 # variable of that name.



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

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 16:12:46 UTC 2021

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

Log Message:
make: add more tests for edge cases in evaluating variable expressions

As a preparation for refactoring the code around variable expressions,
there need to be a few tests for indirect variable modifiers since these
were not covered before.

Indirect modifiers may include ':ts' and ':tW', which change the
interpretation of the variable expression in small details.  The scope
of these changes is limited to the indirect modifier, any evaluations
outside this indirect modifier are unaffected.

The changes to the .exp file are mostly line number changes, plus a
demonstration of a newly found bug, where an expression is evaluated
successfully despite producing a parse error.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.5 -r1.6 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/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.8 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.9
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.8	Tue Feb  2 16:18:16 2021
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Feb 14 16:12:46 2021
@@ -1,18 +1,20 @@
-make: "varmod-indirect.mk" line 13: Unknown modifier '$'
-make: "varmod-indirect.mk" line 108: before
-make: "varmod-indirect.mk" line 108: after
-make: "varmod-indirect.mk" line 114: before
-make: "varmod-indirect.mk" line 114: after
-make: "varmod-indirect.mk" line 120: before
-make: "varmod-indirect.mk" line 120: after
-make: "varmod-indirect.mk" line 124: Unknown modifier 'Z'
-make: "varmod-indirect.mk" line 125: before
-make: "varmod-indirect.mk" line 125: after
-ParseReadLine (134): '_:=	before ${UNDEF} after'
+make: "varmod-indirect.mk" line 17: Unknown modifier '$'
+make: "varmod-indirect.mk" line 50: Unknown modifier '$'
+make: "varmod-indirect.mk" line 53: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression.
+make: "varmod-indirect.mk" line 138: before
+make: "varmod-indirect.mk" line 138: after
+make: "varmod-indirect.mk" line 144: before
+make: "varmod-indirect.mk" line 144: after
+make: "varmod-indirect.mk" line 150: before
+make: "varmod-indirect.mk" line 150: after
+make: "varmod-indirect.mk" line 154: Unknown modifier 'Z'
+make: "varmod-indirect.mk" line 155: before
+make: "varmod-indirect.mk" line 155: after
+ParseReadLine (164): '_:=	before ${UNDEF} after'
 Global:_ = 
 Var_Parse: ${UNDEF} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Global:_ = before ${UNDEF} after
-ParseReadLine (137): '_:=	before ${UNDEF:${:US,a,a,}} after'
+ParseReadLine (167): '_:=	before ${UNDEF:${:US,a,a,}} after'
 Var_Parse: ${UNDEF:${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
@@ -27,7 +29,7 @@ Var_Parse: ${:US,a,a,}} after with VARE_
 Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
 Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_DEF)
 Global:_ = before ${UNDEF:S,a,a,} after
-ParseReadLine (147): '_:=	before ${UNDEF:${:U}} after'
+ParseReadLine (177): '_:=	before ${UNDEF:${:U}} after'
 Var_Parse: ${UNDEF:${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
@@ -37,20 +39,20 @@ Var_Parse: ${:U}} after with VARE_WANTRE
 Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
 Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_DEF)
 Global:_ = before ${UNDEF:} after
-ParseReadLine (152): '_:=	before ${UNDEF:${:UZ}} after'
+ParseReadLine (182): '_:=	before ${UNDEF:${:UZ}} after'
 Var_Parse: ${UNDEF:${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF
 Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
 Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_DEF)
 Indirect modifier "Z" from "${:UZ}"
 Applying ${UNDEF:Z} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR|VARE_KEEP_UNDEF, none, VES_UNDEF)
-make: "varmod-indirect.mk" line 152: Unknown modifier 'Z'
+make: "varmod-indirect.mk" line 182: Unknown modifier 'Z'
 Result of ${UNDEF:Z} is error 

CVS commit: src/sys/dev/pci

2021-02-14 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Feb 14 14:05:03 UTC 2021

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

Log Message:
if_bnx.c: fix misleading indentation

suggested by rillig@


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/pci/if_bnx.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/if_bnx.c
diff -u src/sys/dev/pci/if_bnx.c:1.107 src/sys/dev/pci/if_bnx.c:1.108
--- src/sys/dev/pci/if_bnx.c:1.107	Sat Feb 13 16:33:30 2021
+++ src/sys/dev/pci/if_bnx.c	Sun Feb 14 14:05:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bnx.c,v 1.107 2021/02/13 16:33:30 jakllsch Exp $	*/
+/*	$NetBSD: if_bnx.c,v 1.108 2021/02/14 14:05:03 jakllsch Exp $	*/
 /*	$OpenBSD: if_bnx.c,v 1.101 2013/03/28 17:21:44 brad Exp $	*/
 
 /*-
@@ -35,7 +35,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/sys/dev/bce/if_bce.c,v 1.3 2006/04/13 14:12:26 ru Exp $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.107 2021/02/13 16:33:30 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.108 2021/02/14 14:05:03 jakllsch Exp $");
 
 /*
  * The following controllers are supported by this driver:
@@ -4588,7 +4588,7 @@ bnx_rx_intr(struct bnx_softc *sc)
 		sc->free_rx_bd++;
 
 		DBRUN(BNX_VERBOSE_RECV, printf("%s(): ", __func__);
-		bnx_dump_rxbd(sc, sw_chain_cons, rxbd));
+		bnx_dump_rxbd(sc, sw_chain_cons, rxbd));
 
 		/* The mbuf is stored with the last rx_bd entry of a packet. */
 		if (sc->rx_mbuf_ptr[sw_chain_cons] != NULL) {



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 13:53:28 UTC 2021

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

Log Message:
make: add functions for assigning the value of an expression

The plan is to have only the "current value" of the expression as a
member, not the "new value".  To do this consistently and get the memory
management right, there must be a single place (or two) where the value
of the expression is updated.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.812 -r1.813 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.812 src/usr.bin/make/var.c:1.813
--- src/usr.bin/make/var.c:1.812	Sun Feb 14 13:46:01 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 13:53:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.812 2021/02/14 13:46:01 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.813 2021/02/14 13:53:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.812 2021/02/14 13:46:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.813 2021/02/14 13:53:28 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2028,7 +2028,7 @@ VarStrftime(const char *fmt, Boolean zul
  *
  * Evaluating the modifier usually takes the current value of the variable
  * expression from st->val, or the variable name from st->var->name and stores
- * the result in st->newVal.
+ * the result in st->newValue.
  *
  * If evaluating fails (as of 2020-08-23), an error message is printed using
  * Error.  This function has no side-effects, it really just prints the error
@@ -2075,7 +2075,7 @@ typedef struct ApplyModifiersState {
 	 * The new value of the expression, after applying the modifier,
 	 * never NULL.
 	 */
-	FStr newVal;
+	FStr newValue;
 	/* Word separator in expansions (see the :ts modifier). */
 	char sep;
 	/*
@@ -2096,6 +2096,18 @@ Expr_Define(Expr *expr)
 		expr->exprStatus = VES_DEF;
 }
 
+static void
+Expr_SetValueOwn(Expr *expr, char *value)
+{
+	expr->newValue = FStr_InitOwn(value);
+}
+
+static void
+Expr_SetValueRefer(Expr *expr, const char *value)
+{
+	expr->newValue = FStr_InitRefer(value);
+}
+
 typedef enum ApplyModifierResult {
 	/* Continue parsing */
 	AMR_OK,
@@ -2384,7 +2396,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 = FStr_InitOwn(
+	Expr_SetValueOwn(st,
 	ModifyWords(val, ModifyWord_Loop, , st->oneBigWord, st->sep));
 	st->sep = prev_sep;
 	/* XXX: Consider restoring the previous variable instead of deleting. */
@@ -2449,9 +2461,9 @@ ApplyModifier_Defined(const char **pp, c
 	Expr_Define(st);
 
 	if (eflags & VARE_WANTRES) {
-		st->newVal = FStr_InitOwn(Buf_DoneData());
+		Expr_SetValueOwn(st, Buf_DoneData());
 	} else {
-		st->newVal = FStr_InitRefer(val);
+		Expr_SetValueRefer(st, val);
 		Buf_Done();
 	}
 	return AMR_OK;
@@ -2462,7 +2474,7 @@ static ApplyModifierResult
 ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
 {
 	Expr_Define(st);
-	st->newVal = FStr_InitOwn(bmake_strdup(st->var->name.str));
+	Expr_SetValueOwn(st, bmake_strdup(st->var->name.str));
 	(*pp)++;
 	return AMR_OK;
 }
@@ -2508,7 +2520,7 @@ ApplyModifier_Gmtime(const char **pp, co
 		utc = 0;
 		*pp = mod + 6;
 	}
-	st->newVal = FStr_InitOwn(VarStrftime(val, TRUE, utc));
+	Expr_SetValueOwn(st, VarStrftime(val, TRUE, utc));
 	return AMR_OK;
 }
 
@@ -2535,7 +2547,7 @@ ApplyModifier_Localtime(const char **pp,
 		utc = 0;
 		*pp = mod + 9;
 	}
-	st->newVal = FStr_InitOwn(VarStrftime(val, FALSE, utc));
+	Expr_SetValueOwn(st, VarStrftime(val, FALSE, utc));
 	return AMR_OK;
 }
 
@@ -2546,7 +2558,7 @@ ApplyModifier_Hash(const char **pp, cons
 	if (!ModMatch(*pp, "hash", st->endc))
 		return AMR_UNKNOWN;
 
-	st->newVal = FStr_InitOwn(VarHash(val));
+	Expr_SetValueOwn(st, VarHash(val));
 	*pp += 4;
 	return AMR_OK;
 }
@@ -2571,7 +2583,7 @@ ApplyModifier_Path(const char **pp, Appl
 	}
 	if (path == NULL)
 		path = bmake_strdup(st->var->name.str);
-	st->newVal = FStr_InitOwn(path);
+	Expr_SetValueOwn(st, path);
 
 	(*pp)++;
 	return AMR_OK;
@@ -2592,9 +2604,9 @@ ApplyModifier_ShellCommand(const char **
 
 	errfmt = NULL;
 	if (st->eflags & VARE_WANTRES)
-		st->newVal = FStr_InitOwn(Cmd_Exec(cmd, ));
+		Expr_SetValueOwn(st, Cmd_Exec(cmd, ));
 	else
-		st->newVal = FStr_InitRefer("");
+		Expr_SetValueRefer(st, "");
 	if (errfmt != NULL)
 		Error(errfmt, cmd);	/* XXX: why still return AMR_OK? */
 	free(cmd);
@@ -2647,7 +2659,7 @@ ApplyModifier_Range(const char **pp, con
 		Buf_AddInt(, 1 + (int)i);
 	}
 
-	st->newVal = FStr_InitOwn(Buf_DoneData());
+	Expr_SetValueOwn(st, Buf_DoneData());
 	return AMR_OK;
 }
 
@@ -2724,8 +2736,8 @@ 

CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 13:46:01 UTC 2021

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

Log Message:
make: rename ApplyModifiersState_Define to Expr_Define

The type name ApplyModifiersState was only intended as a working draft,
its name is too long and its scope a little too narrow.

Applying the modifiers is the main part of evaluating a variable
expression, and the scope of that type will be extended to parsing the
name of the expression as well.  This will hopefully reduce the number
of parameters, which is currently at 14.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.811 -r1.812 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.811 src/usr.bin/make/var.c:1.812
--- src/usr.bin/make/var.c:1.811	Sun Feb 14 12:35:27 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 13:46:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.811 2021/02/14 12:35:27 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.812 2021/02/14 13:46:01 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.811 2021/02/14 12:35:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.812 2021/02/14 13:46:01 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2087,11 +2087,13 @@ typedef struct ApplyModifiersState {
 	VarExprStatus exprStatus;
 } ApplyModifiersState;
 
+typedef ApplyModifiersState Expr;
+
 static void
-ApplyModifiersState_Define(ApplyModifiersState *st)
+Expr_Define(Expr *expr)
 {
-	if (st->exprStatus == VES_UNDEF)
-		st->exprStatus = VES_DEF;
+	if (expr->exprStatus == VES_UNDEF)
+		expr->exprStatus = VES_DEF;
 }
 
 typedef enum ApplyModifierResult {
@@ -2444,7 +2446,7 @@ ApplyModifier_Defined(const char **pp, c
 	}
 	*pp = p;
 
-	ApplyModifiersState_Define(st);
+	Expr_Define(st);
 
 	if (eflags & VARE_WANTRES) {
 		st->newVal = FStr_InitOwn(Buf_DoneData());
@@ -2459,7 +2461,7 @@ ApplyModifier_Defined(const char **pp, c
 static ApplyModifierResult
 ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
 {
-	ApplyModifiersState_Define(st);
+	Expr_Define(st);
 	st->newVal = FStr_InitOwn(bmake_strdup(st->var->name.str));
 	(*pp)++;
 	return AMR_OK;
@@ -2556,7 +2558,7 @@ ApplyModifier_Path(const char **pp, Appl
 	GNode *gn;
 	char *path;
 
-	ApplyModifiersState_Define(st);
+	Expr_Define(st);
 
 	gn = Targ_FindNode(st->var->name.str);
 	if (gn == NULL || gn->type & OP_NOPATH) {
@@ -2597,7 +2599,7 @@ ApplyModifier_ShellCommand(const char **
 		Error(errfmt, cmd);	/* XXX: why still return AMR_OK? */
 	free(cmd);
 
-	ApplyModifiersState_Define(st);
+	Expr_Define(st);
 	return AMR_OK;
 }
 
@@ -3223,7 +3225,7 @@ ApplyModifier_IfElse(const char **pp, Ap
 		st->newVal = FStr_InitOwn(else_expr);
 		free(then_expr);
 	}
-	ApplyModifiersState_Define(st);
+	Expr_Define(st);
 	return AMR_OK;
 }
 



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 12:35:27 UTC 2021

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

Log Message:
make: condense the code for parsing :S and :C modifiers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.810 -r1.811 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.810 src/usr.bin/make/var.c:1.811
--- src/usr.bin/make/var.c:1.810	Sun Feb 14 12:24:53 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 12:35:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.810 2021/02/14 12:24:53 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.811 2021/02/14 12:35:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.810 2021/02/14 12:24:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.811 2021/02/14 12:35:27 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2772,18 +2772,14 @@ ApplyModifier_Subst(const char **pp, con
 
 	oneBigWord = st->oneBigWord;
 	for (;; (*pp)++) {
-		switch (**pp) {
-		case 'g':
+		if (**pp == 'g')
 			args.pflags.subGlobal = TRUE;
-			continue;
-		case '1':
+		else if (**pp == '1')
 			args.pflags.subOnce = TRUE;
-			continue;
-		case 'W':
+		else if (**pp == 'W')
 			oneBigWord = TRUE;
-			continue;
-		}
-		break;
+		else
+			break;
 	}
 
 	st->newVal = FStr_InitOwn(ModifyWords(val, ModifyWord_Subst, ,
@@ -2829,18 +2825,14 @@ ApplyModifier_Regex(const char **pp, con
 	args.matched = FALSE;
 	oneBigWord = st->oneBigWord;
 	for (;; (*pp)++) {
-		switch (**pp) {
-		case 'g':
+		if (**pp == 'g')
 			args.pflags.subGlobal = TRUE;
-			continue;
-		case '1':
+		else if (**pp == '1')
 			args.pflags.subOnce = TRUE;
-			continue;
-		case 'W':
+		else if (**pp == 'W')
 			oneBigWord = TRUE;
-			continue;
-		}
-		break;
+		else
+			break;
 	}
 
 	error = regcomp(, re, REG_EXTENDED);



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 12:24:53 UTC 2021

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

Log Message:
make: rearrange some comments to make them easier to spot


To generate a diff of this commit:
cvs rdiff -u -r1.809 -r1.810 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.809 src/usr.bin/make/var.c:1.810
--- src/usr.bin/make/var.c:1.809	Sun Feb 14 12:16:13 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 12:24:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.809 2021/02/14 12:16:13 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.810 2021/02/14 12:24:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.809 2021/02/14 12:16:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.810 2021/02/14 12:24:53 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2998,13 +2998,12 @@ ApplyModifier_To(const char **pp, const 
 	if (mod[1] == 's')
 		return ApplyModifier_ToSep(pp, val, st);
 
-	if (mod[2] != st->endc && mod[2] != ':') {
+	if (mod[2] != st->endc && mod[2] != ':') {	/* :t */
 		*pp = mod + 1;
-		return AMR_BAD;	/* Found ":t". */
+		return AMR_BAD;
 	}
 
-	/* Check for two-character options: ":tu", ":tl" */
-	if (mod[1] == 'A') {	/* absolute path */
+	if (mod[1] == 'A') {/* :tA */
 		st->newVal = FStr_InitOwn(
 		ModifyWords(val, ModifyWord_Realpath, NULL,
 		st->oneBigWord, st->sep));
@@ -3012,19 +3011,19 @@ ApplyModifier_To(const char **pp, const 
 		return AMR_OK;
 	}
 
-	if (mod[1] == 'u') {	/* :tu */
+	if (mod[1] == 'u') {/* :tu */
 		st->newVal = FStr_InitOwn(str_toupper(val));
 		*pp = mod + 2;
 		return AMR_OK;
 	}
 
-	if (mod[1] == 'l') {	/* :tl */
+	if (mod[1] == 'l') {/* :tl */
 		st->newVal = FStr_InitOwn(str_tolower(val));
 		*pp = mod + 2;
 		return AMR_OK;
 	}
 
-	if (mod[1] == 'W' || mod[1] == 'w') { /* :tW, :tw */
+	if (mod[1] == 'W' || mod[1] == 'w') {		/* :tW, :tw */
 		st->oneBigWord = mod[1] == 'W';
 		st->newVal = FStr_InitRefer(val);
 		*pp = mod + 2;
@@ -3050,14 +3049,13 @@ ApplyModifier_Words(const char **pp, con
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
-	/* now *pp points just after the closing ']' */
 	if (**pp != ':' && **pp != st->endc)
-		goto bad_modifier;	/* Found junk after ']' */
+		goto bad_modifier;		/* Found junk after ']' */
 
 	if (estr[0] == '\0')
-		goto bad_modifier;	/* empty square brackets in ":[]". */
+		goto bad_modifier;			/* Found ":[]". */
 
-	if (estr[0] == '#' && estr[1] == '\0') { /* Found ":[#]" */
+	if (estr[0] == '#' && estr[1] == '\0') {	/* Found ":[#]" */
 		if (st->oneBigWord) {
 			st->newVal = FStr_InitRefer("1");
 		} else {
@@ -3075,15 +3073,13 @@ ApplyModifier_Words(const char **pp, con
 		goto ok;
 	}
 
-	if (estr[0] == '*' && estr[1] == '\0') {
-		/* Found ":[*]" */
+	if (estr[0] == '*' && estr[1] == '\0') {	/* Found ":[*]" */
 		st->oneBigWord = TRUE;
 		st->newVal = FStr_InitRefer(val);
 		goto ok;
 	}
 
-	if (estr[0] == '@' && estr[1] == '\0') {
-		/* Found ":[@]" */
+	if (estr[0] == '@' && estr[1] == '\0') {	/* Found ":[@]" */
 		st->oneBigWord = FALSE;
 		st->newVal = FStr_InitRefer(val);
 		goto ok;



CVS commit: src/usr.bin/make

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 12:16:13 UTC 2021

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

Log Message:
make: document purpose of stepping back in the parser

In ApplyModifier_Assign there was no need to compute the delimiter from
st->startc since that has already be done at that point.


To generate a diff of this commit:
cvs rdiff -u -r1.808 -r1.809 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.808 src/usr.bin/make/var.c:1.809
--- src/usr.bin/make/var.c:1.808	Sat Feb  6 21:40:14 2021
+++ src/usr.bin/make/var.c	Sun Feb 14 12:16:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.808 2021/02/06 21:40:14 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.809 2021/02/14 12:16:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.808 2021/02/06 21:40:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.809 2021/02/14 12:16:13 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3220,7 +3220,8 @@ ApplyModifier_IfElse(const char **pp, Ap
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
-	(*pp)--;
+	(*pp)--;		/* Go back to the st->endc. */
+
 	if (cond_rc == COND_INVALID) {
 		Error("Bad conditional expression `%s' in %s?%s:%s",
 		st->var->name.str, st->var->name.str, then_expr, else_expr);
@@ -3264,7 +3265,6 @@ static ApplyModifierResult
 ApplyModifier_Assign(const char **pp, ApplyModifiersState *st)
 {
 	GNode *scope;
-	char delim;
 	char *val;
 	VarParseResult res;
 
@@ -3303,12 +3303,11 @@ ok:
 		break;
 	}
 
-	delim = st->startc == '(' ? ')' : '}';
-	res = ParseModifierPart(pp, delim, st->eflags, st, );
+	res = ParseModifierPart(pp, st->endc, st->eflags, st, );
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
-	(*pp)--;
+	(*pp)--;		/* Go back to the st->endc. */
 
 	/* XXX: Expanding the variable name at this point sounds wrong. */
 	if (st->eflags & VARE_WANTRES) {
@@ -3436,7 +3435,8 @@ ApplyModifier_SysV(const char **pp, cons
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 
-	(*pp)--;
+	(*pp)--;		/* Go back to the st->endc. */
+
 	if (lhs[0] == '\0' && val[0] == '\0') {
 		st->newVal = FStr_InitRefer(val); /* special case */
 	} else {



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

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 12:14:37 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: varmod-assign.mk

Log Message:
make: add test for ::= modifier enclosed in parentheses


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-assign.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-assign.mk
diff -u src/usr.bin/make/unit-tests/varmod-assign.mk:1.9 src/usr.bin/make/unit-tests/varmod-assign.mk:1.10
--- src/usr.bin/make/unit-tests/varmod-assign.mk:1.9	Fri Jan 22 22:54:53 2021
+++ src/usr.bin/make/unit-tests/varmod-assign.mk	Sun Feb 14 12:14:37 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-assign.mk,v 1.9 2021/01/22 22:54:53 rillig Exp $
+# $NetBSD: varmod-assign.mk,v 1.10 2021/02/14 12:14:37 rillig Exp $
 #
 # Tests for the obscure ::= variable modifiers, which perform variable
 # assignments during evaluation, just like the = operator in C.
@@ -91,7 +91,7 @@ mod-assign-shell-error:
 	@${SH_ERR::=previous}
 	@${SH_ERR::!= echo word; false } echo err=${SH_ERR}
 
-# XXX: The ::= modifier expands its right-hand side, exactly once.
+# XXX: The ::= modifier expands its right-hand side exactly once.
 # This differs subtly from normal assignments such as '+=' or '=', which copy
 # their right-hand side literally.
 APPEND.prev=		previous
@@ -104,3 +104,13 @@ APPEND.dollar=		$${APPEND.indirect}
 .if ${APPEND.var} != "previous indirect \${:Unot expanded}"
 .  error
 .endif
+
+
+# The assignment modifier can be used in a variable expression that is
+# enclosed in parentheses.  In such a case, parsing stops at the first ')',
+# not at the first '}'.
+VAR=	previous
+_:=	$(VAR::=current})
+.if ${VAR} != "current}"
+.  error
+.endif



CVS commit: src/tests/lib/libcurses/tests

2021-02-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Feb 14 11:21:37 UTC 2021

Modified Files:
src/tests/lib/libcurses/tests: addch

Log Message:
tests/libcurses: document the history about tab bugs in addch/addstr

Verified by installing all versions of libcurses from 2012 to 2021 and
running a simple test program on them:

#include 
#include 

int
main(int argc, char **argv)
{
int xstr, ystr, xch, ych;

initscr();

addstr("\t");
xstr = getcurx(stdscr);
addstr("\n");
ystr = getcury(stdscr);

addch('\t');
xch = getcurx(stdscr);
addch('\n');
ych = getcury(stdscr);

endwin();

fprintf(stderr, "%s\t%d,%d\t%d,%d\n",
argv[1], ystr, xstr, ych, xch);
}

Some selected outputs:

...
2016.11.24.14.49.08 1,0 2,8
2016.11.28.18.25.26 1,8 2,8
...
2019.05.12.02.29.00 1,8 2,8
2019.05.20.22.17.41 1,8 2,16
...
2021.02.13.10.37.00 1,8 2,16
2021.02.13.14.30.37 1,8 2,8


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libcurses/tests/addch

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

Modified files:

Index: src/tests/lib/libcurses/tests/addch
diff -u src/tests/lib/libcurses/tests/addch:1.6 src/tests/lib/libcurses/tests/addch:1.7
--- src/tests/lib/libcurses/tests/addch:1.6	Sat Feb 13 14:30:37 2021
+++ src/tests/lib/libcurses/tests/addch	Sun Feb 14 11:21:37 2021
@@ -1,3 +1,18 @@
+# $NetBSD: addch,v 1.7 2021/02/14 11:21:37 rillig Exp $
+#
+# Between at least 2012 and 2016, addstr did not advance win->curx for a '\t',
+# but addch did.  This was inconsistent.
+#
+# On 2016.11.28.18.25.26 on NetBSD 7.99.43, this inconsistency was fixed.
+# Now both functions advanced win->curx.
+#
+# On 2019.05.20.22.17.41 on NetBSD 8.99.41, the fix was modified, which
+# introduced another inconsistency.  Since then, addstr advanced win->curx as
+# expected, but addch advanced it by twice the amount.
+#
+# On 2021.02.13.14.30.37 on NetBSD 9.99.80, this inconsistency was fixed.
+# Now both functions advanced win->curx again.
+
 include start
 call OK addch `\001t`
 call OK refresh
@@ -5,17 +20,11 @@ call OK mvaddch 5 3 `\003e`
 call OK refresh
 call OK addch `\000\n`
 
-# Somewhere between NetBSD 8.0 and 9.0, a bug was added to addch that
-# doubled the spaces for a tab.  Instead of 8 spaces, there were 16.
-# Fixed in NetBSD 9.99.80.
 call OK addch `\000\t`
 call2 6 8 getyx STDSCR
 call OK addch `\0008`
 call OK addch `\000\n`
 
-# Somewhere between NetBSD 8.0 and 9.0, a bug was added to addch that
-# doubled the spaces for a tab.  Instead of 1 space, there were 2.
-# Fixed in NetBSD 9.99.80.
 call OK addstr "0123456"
 call OK addch `\000\t`
 call2 7 8 getyx STDSCR