CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 14:43:30 UTC 2021

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

Log Message:
make: add ARGSUSED for lint


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/make/arch.c

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

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.201 src/usr.bin/make/arch.c:1.202
--- src/usr.bin/make/arch.c:1.201	Sat Aug 14 13:26:07 2021
+++ src/usr.bin/make/arch.c	Sat Aug 14 14:43:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.201 2021/08/14 13:26:07 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.202 2021/08/14 14:43:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.201 2021/08/14 13:26:07 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.202 2021/08/14 14:43:30 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -988,6 +988,7 @@ Arch_FindLib(GNode *gn, SearchPath *path
 #endif
 }
 
+/* ARGSUSED */
 static bool
 RanlibOODate(const GNode *gn MAKE_ATTR_UNUSED)
 {



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:39:43 UTC 2021

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

Log Message:
make: fix spelling of CVS and RCS in error message


To generate a diff of this commit:
cvs rdiff -u -r1.562 -r1.563 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.562 src/usr.bin/make/parse.c:1.563
--- src/usr.bin/make/parse.c:1.562	Sat Aug 14 13:37:55 2021
+++ src/usr.bin/make/parse.c	Sat Aug 14 13:39:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.562 2021/08/14 13:37:55 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.563 2021/08/14 13:39:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.562 2021/08/14 13:37:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.563 2021/08/14 13:39:43 rillig Exp $");
 
 /* types and constants */
 
@@ -1004,7 +1004,7 @@ ParseErrorNoDependency(const char *lstar
 	(strncmp(lstart, "==", 6) == 0) ||
 	(strncmp(lstart, ">>", 6) == 0))
 		Parse_Error(PARSE_FATAL,
-		"Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
+		"Makefile appears to contain unresolved CVS/RCS/??? merge conflicts");
 	else if (lstart[0] == '.') {
 		const char *dirstart = lstart + 1;
 		const char *dirend;



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:37:56 UTC 2021

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

Log Message:
make: rename ParseMark to be more expressive

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.561 -r1.562 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.561 src/usr.bin/make/parse.c:1.562
--- src/usr.bin/make/parse.c:1.561	Sat Aug 14 13:32:12 2021
+++ src/usr.bin/make/parse.c	Sat Aug 14 13:37:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.561 2021/08/14 13:32:12 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.562 2021/08/14 13:37:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.561 2021/08/14 13:32:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.562 2021/08/14 13:37:55 rillig Exp $");
 
 /* types and constants */
 
@@ -530,7 +530,7 @@ ParseIsEscaped(const char *line, const c
  * was first defined.
  */
 static void
-ParseMark(GNode *gn)
+RememberLocation(GNode *gn)
 {
 	IFile *curFile = CurFile();
 	gn->fname = curFile->fname;
@@ -782,7 +782,7 @@ TryApplyDependencyOperator(GNode *gn, GN
 
 		cohort = Targ_NewInternalNode(gn->name);
 		if (doing_depend)
-			ParseMark(cohort);
+			RememberLocation(cohort);
 		/*
 		 * Make the cohort invisible as well to avoid duplicating it
 		 * into other variables. True, parents of this target won't
@@ -837,7 +837,7 @@ ParseDependencySourceWait(bool isSpecial
 	snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number);
 	gn = Targ_NewInternalNode(wait_src);
 	if (doing_depend)
-		ParseMark(gn);
+		RememberLocation(gn);
 	gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
 	LinkToTargets(gn, isSpecial);
 
@@ -897,7 +897,7 @@ ParseDependencySourceOrder(const char *s
 	 */
 	gn = Targ_GetNode(src);
 	if (doing_depend)
-		ParseMark(gn);
+		RememberLocation(gn);
 	if (order_pred != NULL) {
 		Lst_Append(&order_pred->order_succ, gn);
 		Lst_Append(&gn->order_pred, order_pred);
@@ -934,7 +934,7 @@ ParseDependencySourceOther(const char *s
 	/* Find/create the 'src' node and attach to all targets */
 	gn = Targ_GetNode(src);
 	if (doing_depend)
-		ParseMark(gn);
+		RememberLocation(gn);
 	if (tOp != OP_NONE)
 		gn->type |= tOp;
 	else
@@ -1085,7 +1085,7 @@ ParseDependencyTargetSpecial(ParseSpecia
 	case SP_INTERRUPT: {
 		GNode *gn = Targ_GetNode(targetName);
 		if (doing_depend)
-			ParseMark(gn);
+			RememberLocation(gn);
 		gn->type |= OP_NOTMAIN | OP_SPECIAL;
 		Lst_Append(targets, gn);
 		break;
@@ -1215,7 +1215,7 @@ ParseDependencyTargetMundane(char *targe
 		? Suff_AddTransform(targName)
 		: Targ_GetNode(targName);
 		if (doing_depend)
-			ParseMark(gn);
+			RememberLocation(gn);
 
 		Lst_Append(targets, gn);
 	}
@@ -2084,7 +2084,7 @@ ParseAddCmd(GNode *gn, char *cmd)
 		Lst_Append(&gn->commands, cmd);
 		if (MaybeSubMake(cmd))
 			gn->type |= OP_SUBMAKE;
-		ParseMark(gn);
+		RememberLocation(gn);
 	} else {
 #if 0
 		/* XXX: We cannot do this until we fix the tree */



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:32:12 UTC 2021

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

Log Message:
make: rename variable and function for handling parse errors

The word 'fatals' was an unnecessary abbreviation.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.540 -r1.541 src/usr.bin/make/main.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.560 -r1.561 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.540 src/usr.bin/make/main.c:1.541
--- src/usr.bin/make/main.c:1.540	Fri Jun 18 12:54:17 2021
+++ src/usr.bin/make/main.c	Sat Aug 14 13:32:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.540 2021/06/18 12:54:17 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.541 2021/08/14 13:32:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.540 2021/06/18 12:54:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.541 2021/08/14 13:32:12 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -1658,7 +1658,7 @@ main_CleanUp(void)
 static int
 main_Exit(bool outOfDate)
 {
-	if (opts.strict && (main_errors > 0 || Parse_GetFatals() > 0))
+	if (opts.strict && (main_errors > 0 || Parse_NumErrors() > 0))
 		return 2;	/* Not 1 so -q can distinguish error */
 	return outOfDate ? 1 : 0;
 }

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.213 src/usr.bin/make/nonints.h:1.214
--- src/usr.bin/make/nonints.h:1.213	Sun Apr 11 13:35:56 2021
+++ src/usr.bin/make/nonints.h	Sat Aug 14 13:32:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.213 2021/04/11 13:35:56 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.214 2021/08/14 13:32:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -164,7 +164,7 @@ void Parse_AddIncludeDir(const char *);
 void Parse_File(const char *, int);
 void Parse_SetInput(const char *, int, int, ReadMoreProc, void *);
 void Parse_MainName(GNodeList *);
-int Parse_GetFatals(void);
+int Parse_NumErrors(void);
 
 
 /* suff.c */

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.560 src/usr.bin/make/parse.c:1.561
--- src/usr.bin/make/parse.c:1.560	Mon Jun 21 10:42:06 2021
+++ src/usr.bin/make/parse.c	Sat Aug 14 13:32:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.560 2021/06/21 10:42:06 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.561 2021/08/14 13:32:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.560 2021/06/21 10:42:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.561 2021/08/14 13:32:12 rillig Exp $");
 
 /* types and constants */
 
@@ -218,7 +218,7 @@ static GNode *order_pred;
 /* parser state */
 
 /* number of fatal errors */
-static int fatals = 0;
+static int parseErrors = 0;
 
 /*
  * Variables for doing includes
@@ -613,7 +613,7 @@ ParseVErrorInternal(FILE *f, const char 
 		goto print_stack_trace;
 	if (type == PARSE_WARNING && !opts.parseWarnFatal)
 		goto print_stack_trace;
-	fatals++;
+	parseErrors++;
 	if (type == PARSE_WARNING && !fatal_warning_error_printed) {
 		Error("parsing warnings being treated as errors");
 		fatal_warning_error_printed = true;
@@ -3250,7 +3250,7 @@ Parse_File(const char *name, int fd)
 
 	FinishDependencyGroup();
 
-	if (fatals != 0) {
+	if (parseErrors != 0) {
 		(void)fflush(stdout);
 		(void)fprintf(stderr,
 		"%s: Fatal errors encountered -- cannot continue",
@@ -3305,7 +3305,7 @@ Parse_MainName(GNodeList *mainList)
 }
 
 int
-Parse_GetFatals(void)
+Parse_NumErrors(void)
 {
-	return fatals;
+	return parseErrors;
 }



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:26:07 UTC 2021

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

Log Message:
make: extract RanlibOODate into separate function

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/usr.bin/make/arch.c

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

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.200 src/usr.bin/make/arch.c:1.201
--- src/usr.bin/make/arch.c:1.200	Sun May 30 21:16:54 2021
+++ src/usr.bin/make/arch.c	Sat Aug 14 13:26:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.201 2021/08/14 13:26:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.201 2021/08/14 13:26:07 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -988,6 +988,34 @@ Arch_FindLib(GNode *gn, SearchPath *path
 #endif
 }
 
+static bool
+RanlibOODate(const GNode *gn MAKE_ATTR_UNUSED)
+{
+#ifdef RANLIBMAG
+	struct ar_hdr *arh;	/* Header for __.SYMDEF */
+	int tocModTime;		/* The table-of-contents' mod time */
+
+	arh = ArchStatMember(gn->path, RANLIBMAG, false);
+
+	if (arh == NULL) {
+		/* A library without a table of contents is out-of-date. */
+		if (DEBUG(ARCH) || DEBUG(MAKE))
+			debug_printf("no toc...");
+		return true;
+	}
+
+	tocModTime = (int)strtol(arh->ar_date, NULL, 10);
+
+	if (DEBUG(ARCH) || DEBUG(MAKE))
+		debug_printf("%s modified %s...",
+		RANLIBMAG, Targ_FmtTime(tocModTime));
+	return gn->youngestChild == NULL ||
+	   gn->youngestChild->mtime > tocModTime;
+#else
+	return false;
+#endif
+}
+
 /*
  * Decide if a node with the OP_LIB attribute is out-of-date. Called from
  * GNode_IsOODate to make its life easier.
@@ -1021,46 +1049,19 @@ Arch_FindLib(GNode *gn, SearchPath *path
 bool
 Arch_LibOODate(GNode *gn)
 {
-	bool oodate;
 
 	if (gn->type & OP_PHONY) {
-		oodate = true;
+		return true;
 	} else if (!GNode_IsTarget(gn) && Lst_IsEmpty(&gn->children)) {
-		oodate = false;
+		return false;
 	} else if ((!Lst_IsEmpty(&gn->children) && gn->youngestChild == NULL) ||
 		   (gn->mtime > now) ||
 		   (gn->youngestChild != NULL &&
 		gn->mtime < gn->youngestChild->mtime)) {
-		oodate = true;
+		return true;
 	} else {
-#ifdef RANLIBMAG
-		struct ar_hdr *arh;	/* Header for __.SYMDEF */
-		int modTimeTOC;		/* The table-of-contents' mod time */
-
-		arh = ArchStatMember(gn->path, RANLIBMAG, false);
-
-		if (arh != NULL) {
-			modTimeTOC = (int)strtol(arh->ar_date, NULL, 10);
-
-			if (DEBUG(ARCH) || DEBUG(MAKE))
-debug_printf("%s modified %s...",
-	 RANLIBMAG,
-	 Targ_FmtTime(modTimeTOC));
-			oodate = gn->youngestChild == NULL ||
- gn->youngestChild->mtime > modTimeTOC;
-		} else {
-			/*
-			 * A library without a table of contents is out-of-date.
-			 */
-			if (DEBUG(ARCH) || DEBUG(MAKE))
-debug_printf("no toc...");
-			oodate = true;
-		}
-#else
-		oodate = false;
-#endif
+		return RanlibOODate(gn);
 	}
-	return oodate;
 }
 
 /* Initialize the archives module. */



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:11:33 UTC 2021

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

Log Message:
make: remove workaround for initialization bug in lint

The bug has been fixed in init.c 1.208 from 2021-08-14.


To generate a diff of this commit:
cvs rdiff -u -r1.946 -r1.947 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.946 src/usr.bin/make/var.c:1.947
--- src/usr.bin/make/var.c:1.946	Sun Aug  8 12:00:30 2021
+++ src/usr.bin/make/var.c	Sat Aug 14 13:11:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.946 2021/08/08 12:00:30 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.947 2021/08/14 13:11:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.946 2021/08/08 12:00:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.947 2021/08/14 13:11:33 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4019,8 +4019,6 @@ ApplyModifiers(
 char endc		/* ')' or '}'; or '\0' for indirect modifiers */
 )
 {
-	/* LINTED 115 *//* warning: left operand of '=' must be modifiable lvalue */
-	/* That's a bug in lint; see tests/usr.bin/xlint/lint1/msg_115.c. */
 	ModChain ch = ModChain_Literal(expr, startc, endc, ' ', false);
 	const char *p;
 	const char *mod;



CVS commit: src/usr.bin/make

2021-08-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug 14 13:04:00 UTC 2021

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

Log Message:
make: fix lint warning about strchr removing 'const'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/make/meta.c

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

Modified files:

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.181 src/usr.bin/make/meta.c:1.182
--- src/usr.bin/make/meta.c:1.181	Sun Apr  4 10:05:08 2021
+++ src/usr.bin/make/meta.c	Sat Aug 14 13:04:00 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: meta.c,v 1.181 2021/04/04 10:05:08 rillig Exp $ */
+/*  $NetBSD: meta.c,v 1.182 2021/08/14 13:04:00 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -321,8 +321,7 @@ is_submake(const char *cmd, GNode *gn)
 static const char *p_make = NULL;
 static size_t p_len;
 char *mp = NULL;
-char *cp;
-char *cp2;
+const char *cp, *cp2;
 bool rc = false;
 
 if (p_make == NULL) {



CVS commit: src/usr.bin/make

2021-08-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  8 12:00:30 UTC 2021

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

Log Message:
make: remove redundant initialization in ApplyModifier_Order

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.945 -r1.946 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.945 src/usr.bin/make/var.c:1.946
--- src/usr.bin/make/var.c:1.945	Sat Jul 31 09:30:17 2021
+++ src/usr.bin/make/var.c	Sun Aug  8 12:00:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.946 2021/08/08 12:00:30 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.946 2021/08/08 12:00:30 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3355,7 +3355,7 @@ ApplyModifier_Order(const char **pp, Mod
 {
 	const char *mod = *pp;
 	Words words;
-	int (*cmp)(const void *, const void *) = NULL;
+	int (*cmp)(const void *, const void *);
 
 	if (IsDelimiter(mod[1], ch) || mod[1] == '\0') {
 		cmp = str_cmp_asc;



CVS commit: src/usr.bin/make

2021-08-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Aug  3 07:12:50 UTC 2021

Modified Files:
src/usr.bin/make: make.1

Log Message:
Document :On modifiers in more detail.


To generate a diff of this commit:
cvs rdiff -u -r1.298 -r1.299 src/usr.bin/make/make.1

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/make.1
diff -u src/usr.bin/make/make.1:1.298 src/usr.bin/make/make.1:1.299
--- src/usr.bin/make/make.1:1.298	Fri Jul 30 22:16:09 2021
+++ src/usr.bin/make/make.1	Tue Aug  3 07:12:50 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.298 2021/07/30 22:16:09 rillig Exp $
+.\"	$NetBSD: make.1,v 1.299 2021/08/03 07:12:50 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd July 30, 2021
+.Dd August 3, 2021
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1235,11 +1235,13 @@ Orders every word in variable alphabetic
 .It Cm \&:On
 Orders every word in variable numerically.
 A number followed by one of
-.Ql K ,
+.Ql k ,
 .Ql M
 or
 .Ql G
-is multiplied by the appropriate factor.
+is multiplied by the appropriate factor (1024 (k), 1048576 (M), or
+1073741824 (G)).
+Both upper- and lower-case letters are accepted.
 .It Cm \&:Or
 Orders every word in variable in reverse alphabetical order.
 .It Cm \&:Orn



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

2021-08-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug  3 04:46:49 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: varmod-order-numeric.mk
varmod-order-reverse.mk varmod-order-shuffle.mk
varmod-order-string.mk varmod-order.exp varmod-order.mk

Log Message:
tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically.  If these words are
not numeric at all, they get assigned the numeric value 0.  Internally,
':On' uses qsort for sorting the words.  Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words.  This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-order-numeric.mk \
src/usr.bin/make/unit-tests/varmod-order-reverse.mk \
src/usr.bin/make/unit-tests/varmod-order.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-order-shuffle.mk \
src/usr.bin/make/unit-tests/varmod-order.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-order-string.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-order-numeric.mk
diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.4 src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.4	Sat Jul 31 20:55:46 2021
+++ src/usr.bin/make/unit-tests/varmod-order-numeric.mk	Tue Aug  3 04:46:49 2021
@@ -1,11 +1,17 @@
-# $NetBSD: varmod-order-numeric.mk,v 1.4 2021/07/31 20:55:46 rillig Exp $
+# $NetBSD: varmod-order-numeric.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
 #
-# Tests for the :On variable modifier, which returns the words, sorted in
-# ascending numeric order.
+# Tests for the variable modifiers ':On', which returns the words, sorted in
+# ascending numeric order, and for ':Orn' and ':Onr', which additionally
+# reverse the order.
+#
+# The variable modifiers ':On', ':Onr' and ':Orn' were added in var.c 1.939
+# from 2021-07-30.
 
 # This list contains only 32-bit numbers since the make code needs to conform
 # to C90, which does not provide integer types larger than 32 bit.  It uses
-# 'long long' by default, but that type is overridable if necessary.
+# 'long long' by default, but that type is overridable if necessary to support
+# older environments.
+#
 # To get 53-bit integers even in C90, it would be possible to switch to
 # 'double' instead, but that would allow floating-point numbers as well, which
 # is out of scope for this variable modifier.
@@ -24,6 +30,14 @@ NUMBERS=	3 5 7 1 42 -42 5K -3m 1M 1k -2G
 .  error ${NUMBERS:Onr}
 .endif
 
+# Duplicate numbers are preserved in the output.  In this case the
+# equal-valued numbers are spelled the same, so they are indistinguishable in
+# the output.
+DUPLICATES=	3 1 2 2 1 1	# https://oeis.org/A034002
+.if ${DUPLICATES:On} != "1 1 1 2 2 3"
+.  error ${DUPLICATES:On}
+.endif
+
 # If there are several numbers that have the same integer value, they are
 # returned in unspecified order.
 SAME_VALUE:=	${:U 79 80 0x0050 81 :On}
@@ -32,9 +46,9 @@ SAME_VALUE:=	${:U 79 80 0x0050 81 :On}
 .endif
 
 # Hexadecimal and octal numbers are supported as well.
-OCTAL=		0 010 0x7 9
-.if ${OCTAL:On} != "0 0x7 010 9"
-.  error ${OCTAL:On}
+MIXED_BASE=	0 010 0x7 9
+.if ${MIXED_BASE:On} != "0 0x7 010 9"
+.  error ${MIXED_BASE:On}
 .endif
 
 all:
Index: src/usr.bin/make/unit-tests/varmod-order-reverse.mk
diff -u src/usr.bin/make/unit-tests/varmod-order-reverse.mk:1.4 src/usr.bin/make/unit-tests/varmod-order-reverse.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-order-reverse.mk:1.4	Sat Oct 24 08:46:08 2020
+++ src/usr.bin/make/unit-tests/varmod-order-reverse.mk	Tue Aug  3 04:46:49 2021
@@ -1,13 +1,12 @@
-# $NetBSD: varmod-order-reverse.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varmod-order-reverse.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
 #
 # Tests for the :Or variable modifier, which returns the words, sorted in
 # descending order.
 
-NUMBERS=	one two three four five six seven eight nine ten
+WORDS=		one two three four five six seven eight nine ten
 
-.if ${NUMBERS:Or} != "two three ten six seven one nine four five eight"
-.  error ${NUMBERS:Or}
+.if ${WORDS:Or} != "two three ten six seven one nine four five eight"
+.  error ${WORDS:Or}
 .endif
 
 all:
-	@:;
Index: src/usr.bin/make/unit-tests/varmod-order.exp
diff -u src/usr.bin/make/unit-tests/varmod-order.exp:1.4 src/usr.bin/make/unit-tests/varmod-order.exp:1.

CVS commit: src/usr.bin/make

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 09:30:17 UTC 2021

Modified Files:
src/usr.bin/make: Makefile make.h suff.c var.c
src/usr.bin/make/filemon: filemon_ktrace.c

Log Message:
make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing.  Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about.  To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/make/Makefile
cvs rdiff -u -r1.263 -r1.264 src/usr.bin/make/make.h
cvs rdiff -u -r1.350 -r1.351 src/usr.bin/make/suff.c
cvs rdiff -u -r1.944 -r1.945 src/usr.bin/make/var.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/filemon/filemon_ktrace.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/Makefile
diff -u src/usr.bin/make/Makefile:1.115 src/usr.bin/make/Makefile:1.116
--- src/usr.bin/make/Makefile:1.115	Sun May 30 21:03:08 2021
+++ src/usr.bin/make/Makefile	Sat Jul 31 09:30:17 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.115 2021/05/30 21:03:08 rillig Exp $
+#	$NetBSD: Makefile,v 1.116 2021/07/31 09:30:17 rillig Exp $
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 
 PROG=	make
@@ -117,6 +117,7 @@ SUBDIR+=	unit-tests
 .endif
 
 LINTFLAGS+=	-T	# strict bool mode, available since 2021-01-11
+LINTFLAGS+=	-w	# treat warnings as errors
 CLEANFILES+=	*.o	# for filemon objects
 
 COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.263 src/usr.bin/make/make.h:1.264
--- src/usr.bin/make/make.h:1.263	Mon Jun 21 10:33:11 2021
+++ src/usr.bin/make/make.h	Sat Jul 31 09:30:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.263 2021/06/21 10:33:11 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.264 2021/07/31 09:30:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,14 @@
 #endif
 
 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
+
+/* MAKE_STATIC marks a function that may or may not be inlined. */
+#if defined(lint)
+/* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
+#define MAKE_STATIC MAKE_INLINE
+#else
 #define MAKE_STATIC static MAKE_ATTR_UNUSED
+#endif
 
 #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
 #include 
@@ -742,16 +749,13 @@ GNode_VarArchive(GNode *gn) { return GNo
 MAKE_INLINE const char *
 GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
 
-#if defined(__GNUC__) && __STDC_VERSION__ >= 199901L
-#define UNCONST(ptr)	({		\
-union __unconst {			\
-	const void *__cp;		\
-	void *__p;			\
-} __d;\
-__d.__cp = ptr, __d.__p; })
-#else
-#define UNCONST(ptr)	(void *)(ptr)
-#endif
+MAKE_INLINE void *
+UNCONST(const void *ptr)
+{
+	void *ret;
+	memcpy(&ret, &ptr, sizeof(ret));
+	return ret;
+}
 
 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
 #include 

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.350 src/usr.bin/make/suff.c:1.351
--- src/usr.bin/make/suff.c:1.350	Sun Apr  4 10:05:08 2021
+++ src/usr.bin/make/suff.c	Sat Jul 31 09:30:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.350 2021/04/04 10:05:08 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.351 2021/07/31 09:30:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.350 2021/04/04 10:05:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.351 2021/07/31 09:30:17 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -619,6 +619,7 @@ Suff_AddTransform(const char *name)
 		/* TODO: Avoid the redundant parsing here. */
 		bool ok = ParseTransform(name, &srcSuff, &targSuff);
 		assert(ok);
+		/* LINTED 129 *//* expression has null effect */
 		(void)ok;
 	}
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.944 src/usr.bin/make/var.c:1.945
--- src/usr.bin/make/var.c:1.944	Sat Jul 31 00:17:04 2021
+++ src/usr.bin/make/var.c	Sat Jul 31 09:30:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.945 2021/07/31 09:30:17 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=

CVS commit: src/usr.bin/make

2021-07-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 00:17:05 UTC 2021

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

Log Message:
make: clean up ApplyModifier_Order

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.943 -r1.944 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.943 src/usr.bin/make/var.c:1.944
--- src/usr.bin/make/var.c:1.943	Fri Jul 30 23:35:38 2021
+++ src/usr.bin/make/var.c	Sat Jul 31 00:17:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.943 2021/07/30 23:35:38 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.943 2021/07/30 23:35:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.944 2021/07/31 00:17:04 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3355,32 +3355,26 @@ ApplyModifier_Order(const char **pp, Mod
 {
 	const char *mod = *pp;
 	Words words;
-	enum SortMode {
-		STR, NUM, SHUFFLE
-	} mode = STR;
-	enum SortDir {
-		ASC, DESC
-	} dir = ASC;
+	int (*cmp)(const void *, const void *) = NULL;
 
 	if (IsDelimiter(mod[1], ch) || mod[1] == '\0') {
-		mode = STR;
+		cmp = str_cmp_asc;
 		(*pp)++;
 	} else if (IsDelimiter(mod[2], ch) || mod[2] == '\0') {
 		if (mod[1] == 'n')
-			mode = NUM;
+			cmp = num_cmp_asc;
 		else if (mod[1] == 'r')
-			dir = DESC;
+			cmp = str_cmp_desc;
 		else if (mod[1] == 'x')
-			mode = SHUFFLE;
+			cmp = NULL;
 		else
 			goto bad;
 		*pp += 2;
 	} else if (IsDelimiter(mod[3], ch) || mod[3] == '\0') {
 		if ((mod[1] == 'n' && mod[2] == 'r') ||
-		(mod[1] == 'r' && mod[2] == 'n')) {
-			mode = NUM;
-			dir = DESC;
-		} else
+		(mod[1] == 'r' && mod[2] == 'n'))
+			cmp = num_cmp_desc;
+		else
 			goto bad;
 		*pp += 3;
 	} else {
@@ -3391,14 +3385,10 @@ ApplyModifier_Order(const char **pp, Mod
 		return AMR_OK;
 
 	words = Str_Words(ch->expr->value.str, false);
-	if (mode == SHUFFLE)
+	if (cmp == NULL)
 		ShuffleStrings(words.words, words.len);
-	else if (mode == NUM)
-		qsort(words.words, words.len, sizeof words.words[0],
-		dir == ASC ? num_cmp_asc : num_cmp_desc);
 	else
-		qsort(words.words, words.len, sizeof words.words[0],
-		dir == ASC ? str_cmp_asc : str_cmp_desc);
+		qsort(words.words, words.len, sizeof(words.words[0]), cmp);
 	Expr_SetValueOwn(ch->expr, Words_JoinFree(words));
 
 	return AMR_OK;



CVS commit: src/usr.bin/make

2021-07-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 30 23:35:38 UTC 2021

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

Log Message:
make: reword comment for ApplyModifier_Order


To generate a diff of this commit:
cvs rdiff -u -r1.942 -r1.943 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.942 src/usr.bin/make/var.c:1.943
--- src/usr.bin/make/var.c:1.942	Fri Jul 30 23:28:04 2021
+++ src/usr.bin/make/var.c	Fri Jul 30 23:35:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.942 2021/07/30 23:28:04 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.943 2021/07/30 23:35:38 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.942 2021/07/30 23:28:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.943 2021/07/30 23:35:38 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3343,8 +3343,12 @@ ShuffleStrings(char **strs, size_t n)
 	}
 }
 
-/* :O (order ascending) or :Or (order descending) or :Ox (shuffle) or
- * :On (numeric ascending) or :Onr or :Orn (numeric descending)
+/*
+ * :O		order ascending
+ * :Or		order descending
+ * :Ox		shuffle
+ * :On		numeric ascending
+ * :Onr, :Orn	numeric descending
  */
 static ApplyModifierResult
 ApplyModifier_Order(const char **pp, ModChain *ch)



CVS commit: src/usr.bin/make

2021-07-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 30 23:28:04 UTC 2021

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

Log Message:
make: handle parse errors in ':O' uniformly

Previously, the error handling for the variable modifier ':O' differed
depending on the exact variant and in some cases led to misleading
or missing diagnostics.


To generate a diff of this commit:
cvs rdiff -u -r1.941 -r1.942 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-order-numeric.exp \
src/usr.bin/make/unit-tests/varmod-order-numeric.mk

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.941 src/usr.bin/make/var.c:1.942
--- src/usr.bin/make/var.c:1.941	Fri Jul 30 22:19:51 2021
+++ src/usr.bin/make/var.c	Fri Jul 30 23:28:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.941 2021/07/30 22:19:51 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.942 2021/07/30 23:28:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.941 2021/07/30 22:19:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.942 2021/07/30 23:28:04 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2045,7 +2045,7 @@ typedef struct Expr {
  *	  Chain 2 ends at the ':' between ${IND1} and ${IND2}.
  *	  Chain 3 starts with all modifiers from ${IND2}.
  *	  Chain 3 ends at the ':' after ${IND2}.
- *	Chain 1 continues with the the 2 modifiers ':O' and ':u'.
+ *	Chain 1 continues with the 2 modifiers ':O' and ':u'.
  *	Chain 1 ends at the final '}' of the expression.
  *
  * After such a chain ends, its properties no longer have any effect.
@@ -3349,31 +3349,39 @@ ShuffleStrings(char **strs, size_t n)
 static ApplyModifierResult
 ApplyModifier_Order(const char **pp, ModChain *ch)
 {
-	const char *mod = (*pp)++;	/* skip past the 'O' in any case */
+	const char *mod = *pp;
 	Words words;
 	enum SortMode {
-		ASC, DESC, NUM_ASC, NUM_DESC, SHUFFLE
-	} mode;
+		STR, NUM, SHUFFLE
+	} mode = STR;
+	enum SortDir {
+		ASC, DESC
+	} dir = ASC;
 
-	if (IsDelimiter(mod[1], ch)) {
-		mode = ASC;
-	} else if (mod[1] == 'n') {
-		mode = NUM_ASC;
-		(*pp)++;
-		if (!IsDelimiter(mod[2], ch)) {
-			(*pp)++;
-			if (mod[2] == 'r')
-mode = NUM_DESC;
-		}
-	} else if ((mod[1] == 'r' || mod[1] == 'x') &&
-	IsDelimiter(mod[2], ch)) {
+	if (IsDelimiter(mod[1], ch) || mod[1] == '\0') {
+		mode = STR;
 		(*pp)++;
-		mode = mod[1] == 'r' ? DESC : SHUFFLE;
-	} else if (mod[1] == 'r' && mod[2] == 'n') {
-		(*pp) += 2;
-		mode = NUM_DESC;
-	} else
-		return AMR_BAD;
+	} else if (IsDelimiter(mod[2], ch) || mod[2] == '\0') {
+		if (mod[1] == 'n')
+			mode = NUM;
+		else if (mod[1] == 'r')
+			dir = DESC;
+		else if (mod[1] == 'x')
+			mode = SHUFFLE;
+		else
+			goto bad;
+		*pp += 2;
+	} else if (IsDelimiter(mod[3], ch) || mod[3] == '\0') {
+		if ((mod[1] == 'n' && mod[2] == 'r') ||
+		(mod[1] == 'r' && mod[2] == 'n')) {
+			mode = NUM;
+			dir = DESC;
+		} else
+			goto bad;
+		*pp += 3;
+	} else {
+		goto bad;
+	}
 
 	if (!ModChain_ShouldEval(ch))
 		return AMR_OK;
@@ -3381,15 +3389,19 @@ ApplyModifier_Order(const char **pp, Mod
 	words = Str_Words(ch->expr->value.str, false);
 	if (mode == SHUFFLE)
 		ShuffleStrings(words.words, words.len);
-	else if (mode == NUM_ASC || mode == NUM_DESC)
+	else if (mode == NUM)
 		qsort(words.words, words.len, sizeof words.words[0],
-		mode == NUM_ASC ? num_cmp_asc : num_cmp_desc);
+		dir == ASC ? num_cmp_asc : num_cmp_desc);
 	else
 		qsort(words.words, words.len, sizeof words.words[0],
-		mode == ASC ? str_cmp_asc : str_cmp_desc);
+		dir == ASC ? str_cmp_asc : str_cmp_desc);
 	Expr_SetValueOwn(ch->expr, Words_JoinFree(words));
 
 	return AMR_OK;
+
+bad:
+	(*pp)++;
+	return AMR_BAD;
 }
 
 /* :? then : else */

Index: src/usr.bin/make/unit-tests/varmod-order-numeric.exp
diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.2 src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.2	Fri Jul 30 22:16:09 2021
+++ src/usr.bin/make/unit-tests/varmod-order-numeric.exp	Fri Jul 30 23:28:04 2021
@@ -1,16 +1,20 @@
 make: Bad modifier ":Oxn" for variable "NUMBERS"
 make: "varmod-order-numeric.mk" line 32: Malformed conditional (${NUMBERS:Oxn})
-make: Bad modifier ":typo" for variable "NUMBERS"
-make: "varmod-order-numeric.mk" line 45: Malformed conditional (${NUMBERS:On_typo})
-make: "varmod-order-numeric.mk" line 54: Unknown modifier "_typo"
-make: "varmod-order-numeric.mk" line 54: Malformed conditional (${NUMBERS:Onr_typo})
-make: "varmod-order-numeric.mk" line 63: Unknown modifier "_typo"
-make: "varmod-order-numeric.mk"

CVS commit: src/usr.bin/make

2021-07-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 30 22:19:51 UTC 2021

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

Log Message:
make: merge duplicate code for sorting strings and numbers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.940 -r1.941 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.940 src/usr.bin/make/var.c:1.941
--- src/usr.bin/make/var.c:1.940	Fri Jul 30 22:16:09 2021
+++ src/usr.bin/make/var.c	Fri Jul 30 22:19:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.941 2021/07/30 22:19:51 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.941 2021/07/30 22:19:51 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3315,11 +3315,7 @@ num_cmp_asc(const void *sa, const void *
 static int
 num_cmp_desc(const void *sa, const void *sb)
 {
-	NUM_TYPE a, b;
-
-	a = num_val(*(const char *const *)sa);
-	b = num_val(*(const char *const *)sb);
-	return (a > b) ? -1 : (b > a) ? 1 : 0;
+	return num_cmp_asc(sb, sa);
 }
 
 static int
@@ -3331,7 +3327,7 @@ str_cmp_asc(const void *a, const void *b
 static int
 str_cmp_desc(const void *a, const void *b)
 {
-	return strcmp(*(const char *const *)b, *(const char *const *)a);
+	return str_cmp_asc(b, a);
 }
 
 static void



CVS commit: src/usr.bin/make

2021-07-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 30 22:16:09 UTC 2021

Modified Files:
src/usr.bin/make: make.1 var.c
src/usr.bin/make/unit-tests: varmod-order-numeric.exp
varmod-order-numeric.mk

Log Message:
make: fix typo in manual page, add more tests for the new ':On'


To generate a diff of this commit:
cvs rdiff -u -r1.297 -r1.298 src/usr.bin/make/make.1
cvs rdiff -u -r1.939 -r1.940 src/usr.bin/make/var.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-order-numeric.exp \
src/usr.bin/make/unit-tests/varmod-order-numeric.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/make.1
diff -u src/usr.bin/make/make.1:1.297 src/usr.bin/make/make.1:1.298
--- src/usr.bin/make/make.1:1.297	Fri Jul 30 19:55:22 2021
+++ src/usr.bin/make/make.1	Fri Jul 30 22:16:09 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.297 2021/07/30 19:55:22 sjg Exp $
+.\"	$NetBSD: make.1,v 1.298 2021/07/30 22:16:09 rillig Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd July 30, 2020
+.Dd July 30, 2021
 .Dt MAKE 1
 .Os
 .Sh NAME

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.939 src/usr.bin/make/var.c:1.940
--- src/usr.bin/make/var.c:1.939	Fri Jul 30 19:55:22 2021
+++ src/usr.bin/make/var.c	Fri Jul 30 22:16:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.940 2021/07/30 22:16:09 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3311,7 +3311,7 @@ num_cmp_asc(const void *sa, const void *
 	b = num_val(*(const char *const *)sb);
 	return (a > b) ? 1 : (b > a) ? -1 : 0;
 }
-
+
 static int
 num_cmp_desc(const void *sa, const void *sb)
 {
@@ -3321,7 +3321,7 @@ num_cmp_desc(const void *sa, const void 
 	b = num_val(*(const char *const *)sb);
 	return (a > b) ? -1 : (b > a) ? 1 : 0;
 }
-
+
 static int
 str_cmp_asc(const void *a, const void *b)
 {

Index: src/usr.bin/make/unit-tests/varmod-order-numeric.exp
diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.1 src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-order-numeric.exp:1.1	Fri Jul 30 19:55:22 2021
+++ src/usr.bin/make/unit-tests/varmod-order-numeric.exp	Fri Jul 30 22:16:09 2021
@@ -1 +1,16 @@
-exit status 0
+make: Bad modifier ":Oxn" for variable "NUMBERS"
+make: "varmod-order-numeric.mk" line 32: Malformed conditional (${NUMBERS:Oxn})
+make: Bad modifier ":typo" for variable "NUMBERS"
+make: "varmod-order-numeric.mk" line 45: Malformed conditional (${NUMBERS:On_typo})
+make: "varmod-order-numeric.mk" line 54: Unknown modifier "_typo"
+make: "varmod-order-numeric.mk" line 54: Malformed conditional (${NUMBERS:Onr_typo})
+make: "varmod-order-numeric.mk" line 63: Unknown modifier "_typo"
+make: "varmod-order-numeric.mk" line 63: Malformed conditional (${NUMBERS:Orn_typo})
+make: "varmod-order-numeric.mk" line 75: Missing argument for ".error"
+make: "varmod-order-numeric.mk" line 83: Unknown modifier "r"
+make: "varmod-order-numeric.mk" line 83: Malformed conditional (${NUMBERS:Onrr})
+make: Bad modifier ":Orrn" for variable "NUMBERS"
+make: "varmod-order-numeric.mk" line 94: Malformed conditional (${NUMBERS:Orrn})
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/varmod-order-numeric.mk
diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.1 src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.2
--- src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.1	Fri Jul 30 19:55:22 2021
+++ src/usr.bin/make/unit-tests/varmod-order-numeric.mk	Fri Jul 30 22:16:09 2021
@@ -1,18 +1,100 @@
-# $NetBSD: varmod-order-numeric.mk,v 1.1 2021/07/30 19:55:22 sjg Exp $
+# $NetBSD: varmod-order-numeric.mk,v 1.2 2021/07/30 22:16:09 rillig Exp $
 #
 # Tests for the :On variable modifier, which returns the words, sorted in
 # ascending numeric order.
 
-NUMBERS=	3 5 7 1 42 -42 1M 1k
+# This list contains only 32-bit numbers since the make code needs to conform
+# to C90, which does not provide integer types larger than 32 bit.  It uses
+# 'long long' by default, but that type is overridable if necessary.
+# To get 53-bit integers even in C90, it would be possible to switch to
+# 'double' instead, but that would allow floating-point numbers as well, which
+# is out of scope for this variable modifier.
+NUMBERS=	3 5 7 1 42 -42 5K -3m 1M 1k -2G
 
-.if ${NUMBERS:On} != "-42 1

CVS commit: src/usr.bin/make

2021-07-30 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Fri Jul 30 19:55:22 UTC 2021

Modified Files:
src/usr.bin/make: make.1 var.c
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: varmod-order-numeric.exp
varmod-order-numeric.mk

Log Message:
Add :On for numeric sort

Reviewed by: christos rillig


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/usr.bin/make/make.1
cvs rdiff -u -r1.938 -r1.939 src/usr.bin/make/var.c
cvs rdiff -u -r1.280 -r1.281 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/varmod-order-numeric.exp \
src/usr.bin/make/unit-tests/varmod-order-numeric.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/make.1
diff -u src/usr.bin/make/make.1:1.296 src/usr.bin/make/make.1:1.297
--- src/usr.bin/make/make.1:1.296	Thu Feb  4 21:42:46 2021
+++ src/usr.bin/make/make.1	Fri Jul 30 19:55:22 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.296 2021/02/04 21:42:46 rillig Exp $
+.\"	$NetBSD: make.1,v 1.297 2021/07/30 19:55:22 sjg Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd December 22, 2020
+.Dd July 30, 2020
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -1232,8 +1232,18 @@ but selects all words which do not match
 .Ar pattern .
 .It Cm \&:O
 Orders every word in variable alphabetically.
+.It Cm \&:On
+Orders every word in variable numerically.
+A number followed by one of
+.Ql K ,
+.Ql M
+or
+.Ql G
+is multiplied by the appropriate factor.
 .It Cm \&:Or
 Orders every word in variable in reverse alphabetical order.
+.It Cm \&:Orn
+Orders every word in variable in reverse numerical order.
 .It Cm \&:Ox
 Shuffles the words in variable.
 The results will be different each time you are referring to the

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.938 src/usr.bin/make/var.c:1.939
--- src/usr.bin/make/var.c:1.938	Mon Jun 21 18:25:20 2021
+++ src/usr.bin/make/var.c	Fri Jul 30 19:55:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.938 2021/06/21 18:25:20 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.938 2021/06/21 18:25:20 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.939 2021/07/30 19:55:22 sjg Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3272,6 +3272,56 @@ bad_modifier:
 	return AMR_BAD;
 }
 
+#ifndef NUM_TYPE
+# define NUM_TYPE long long
+#endif
+
+static NUM_TYPE
+num_val(const char *s)
+{
+	NUM_TYPE val;
+	char *ep;
+
+	val = strtoll(s, &ep, 0);
+	if (ep != s) {
+		switch (*ep) {
+		case 'K':
+		case 'k':
+			val <<= 10;
+			break;
+		case 'M':
+		case 'm':
+			val <<= 20;
+			break;
+		case 'G':
+		case 'g':
+			val <<= 30;
+			break;
+		}
+	}
+	return val;
+}
+
+static int
+num_cmp_asc(const void *sa, const void *sb)
+{
+	NUM_TYPE a, b;
+
+	a = num_val(*(const char *const *)sa);
+	b = num_val(*(const char *const *)sb);
+	return (a > b) ? 1 : (b > a) ? -1 : 0;
+}
+
+static int
+num_cmp_desc(const void *sa, const void *sb)
+{
+	NUM_TYPE a, b;
+
+	a = num_val(*(const char *const *)sa);
+	b = num_val(*(const char *const *)sb);
+	return (a > b) ? -1 : (b > a) ? 1 : 0;
+}
+
 static int
 str_cmp_asc(const void *a, const void *b)
 {
@@ -3297,22 +3347,35 @@ ShuffleStrings(char **strs, size_t n)
 	}
 }
 
-/* :O (order ascending) or :Or (order descending) or :Ox (shuffle) */
+/* :O (order ascending) or :Or (order descending) or :Ox (shuffle) or
+ * :On (numeric ascending) or :Onr or :Orn (numeric descending)
+ */
 static ApplyModifierResult
 ApplyModifier_Order(const char **pp, ModChain *ch)
 {
 	const char *mod = (*pp)++;	/* skip past the 'O' in any case */
 	Words words;
 	enum SortMode {
-		ASC, DESC, SHUFFLE
+		ASC, DESC, NUM_ASC, NUM_DESC, SHUFFLE
 	} mode;
 
 	if (IsDelimiter(mod[1], ch)) {
 		mode = ASC;
+	} else if (mod[1] == 'n') {
+		mode = NUM_ASC;
+		(*pp)++;
+		if (!IsDelimiter(mod[2], ch)) {
+			(*pp)++;
+			if (mod[2] == 'r')
+mode = NUM_DESC;
+		}
 	} else if ((mod[1] == 'r' || mod[1] == 'x') &&
 	IsDelimiter(mod[2], ch)) {
 		(*pp)++;
 		mode = mod[1] == 'r' ? DESC : SHUFFLE;
+	} else if (mod[1] == 'r' && mod[2] == 'n') {
+		(*pp) += 2;
+		mode = NUM_DESC;
 	} else
 		return AMR_BAD;
 
@@ -3322,6 +3385,9 @@ ApplyModifier_Order(const char **pp, Mod
 	words = Str_Words(ch->expr->value.str, false);
 	if (mode == SHUFFLE)
 		ShuffleStrings(words.words, words.len);
+	else if (mode == NUM_ASC || mode == NUM_DESC)
+		qsort(words.words, words.len, sizeof words.words[0],
+		mode == NUM_ASC ? num_cmp_asc : num_cmp_desc);
 	else
 		qsort(words.words, words.len, sizeof words.

CVS commit: src/usr.bin/make

2021-07-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 29 06:35:21 UTC 2021

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

Log Message:
make: in TryParseNumber, reset errno as late as possible

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.269 src/usr.bin/make/cond.c:1.270
--- src/usr.bin/make/cond.c:1.269	Mon Jun 21 21:10:01 2021
+++ src/usr.bin/make/cond.c	Thu Jul 29 06:35:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.269 2021/06/21 21:10:01 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.270 2021/07/29 06:35:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.269 2021/06/21 21:10:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.270 2021/07/29 06:35:20 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -376,12 +376,12 @@ TryParseNumber(const char *str, double *
 	unsigned long ul_val;
 	double dbl_val;
 
-	errno = 0;
 	if (str[0] == '\0') {	/* XXX: why is an empty string a number? */
 		*out_value = 0.0;
 		return true;
 	}
 
+	errno = 0;
 	ul_val = strtoul(str, &end, str[1] == 'x' ? 16 : 10);
 	if (*end == '\0' && errno != ERANGE) {
 		*out_value = str[0] == '-' ? -(double)-ul_val : (double)ul_val;



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

2021-07-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 29 06:31:18 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: cond-cmp-numeric.exp cond-cmp-numeric.mk

Log Message:
tests/make: test spaces around numbers in comparisons

Just to see whether it is possible to write a conditional in the form
${ ${A} < ${B} :? ${A} : ${B} }, that is, with leading and trailing
whitespace, to make it easier for humans to read the code.

It's not possible, the result of this computation cannot be used in
further numeric comparisons, at least not in .if directives.  Leading
space would work, but trailing space wouldn't.

On the other hand, they would work in expressions of the form
${ ${A} < ${B} :? ... : ... } since in these, the condition is first
expanded and then parsed.  But that is an implementation detail that is
not documented and it is also difficult to understand.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.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/cond-cmp-numeric.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.6
--- src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.5	Thu Jan 21 23:32:28 2021
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric.exp	Thu Jul 29 06:31:18 2021
@@ -6,6 +6,10 @@ CondParser_Eval: !(${:UNaN} == NaN)
 lhs = "NaN", rhs = "NaN", op = ==
 CondParser_Eval: 123 ! 123
 make: "cond-cmp-numeric.mk" line 34: Malformed conditional (123 ! 123)
+CondParser_Eval: ${:U 123} < 124
+lhs = 123.00, rhs = 124.00, op = <
+CondParser_Eval: ${:U123 } < 124
+make: "cond-cmp-numeric.mk" line 50: String comparison operator must be either == or !=
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.mk
diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.4 src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.5
--- src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.4	Sun Nov  8 22:56:16 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-numeric.mk	Thu Jul 29 06:31:18 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric.mk,v 1.4 2020/11/08 22:56:16 rillig Exp $
+# $NetBSD: cond-cmp-numeric.mk,v 1.5 2021/07/29 06:31:18 rillig Exp $
 #
 # Tests for numeric comparisons in .if conditions.
 
@@ -37,5 +37,21 @@
 .  error
 .endif
 
+# Leading spaces are allowed for numbers.
+# See EvalCompare and TryParseNumber.
+.if ${:U 123} < 124
+.else
+.  error
+.endif
+
+# Trailing spaces are NOT allowed for numbers.
+# See EvalCompare and TryParseNumber.
+# expect+1: String comparison operator must be either == or !=
+.if ${:U123 } < 124
+.  error
+.else
+.  error
+.endif
+
 all:
 	@:;



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

2021-07-03 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Sun Jul  4 01:28:54 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: objdir-writable.exp objdir-writable.mk

Log Message:
Do not assume /tmp is safe to use if TMPDIR is set


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/objdir-writable.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/objdir-writable.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/objdir-writable.exp
diff -u src/usr.bin/make/unit-tests/objdir-writable.exp:1.2 src/usr.bin/make/unit-tests/objdir-writable.exp:1.3
--- src/usr.bin/make/unit-tests/objdir-writable.exp:1.2	Sat Feb  6 18:26:03 2021
+++ src/usr.bin/make/unit-tests/objdir-writable.exp	Sun Jul  4 01:28:54 2021
@@ -1,5 +1,5 @@
 make warning: TMPDIR/roobj: Permission denied.
-/tmp
+TMPDIR
 TMPDIR/roobj
 TMPDIR/roobj
 exit status 0

Index: src/usr.bin/make/unit-tests/objdir-writable.mk
diff -u src/usr.bin/make/unit-tests/objdir-writable.mk:1.4 src/usr.bin/make/unit-tests/objdir-writable.mk:1.5
--- src/usr.bin/make/unit-tests/objdir-writable.mk:1.4	Sat Nov 14 07:36:00 2020
+++ src/usr.bin/make/unit-tests/objdir-writable.mk	Sun Jul  4 01:28:54 2021
@@ -1,8 +1,9 @@
-# $NetBSD: objdir-writable.mk,v 1.4 2020/11/14 07:36:00 sjg Exp $
+# $NetBSD: objdir-writable.mk,v 1.5 2021/07/04 01:28:54 sjg Exp $
 
 # test checking for writable objdir
 
-RO_OBJDIR?= ${TMPDIR:U/tmp}/roobj
+TMPDIR?= /tmp
+RO_OBJDIR?= ${TMPDIR}/roobj
 
 .if make(do-objdir)
 # this should succeed
@@ -20,12 +21,12 @@ rm-objdir:
 	@rmdir ${RO_OBJDIR}
 
 no-objdir:
-	@MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C /tmp -V .OBJDIR
+	@MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C ${TMPDIR} -V .OBJDIR
 
 ro-objdir:
-	@MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C /tmp -V .OBJDIR MAKE_OBJDIR_CHECK_WRITABLE=no
+	@MAKEOBJDIR=${RO_OBJDIR} ${.MAKE} -r -f /dev/null -C ${TMPDIR} -V .OBJDIR MAKE_OBJDIR_CHECK_WRITABLE=no
 
 explicit-objdir:
-	@MAKEOBJDIR=/tmp ${.MAKE} -r -f ${MAKEFILE:tA} -C /tmp do-objdir -V .OBJDIR
+	@MAKEOBJDIR=${TMPDIR} ${.MAKE} -r -f ${MAKEFILE:tA} -C ${TMPDIR} do-objdir -V .OBJDIR
 .endif
 



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

2021-07-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  3 22:39:40 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: job-output-null.exp job-output-null.mk

Log Message:
tests/make: make test job-output-null more portable

Previously, the test dependend on implementation details of the system's
printf command.

Thank you sjg for the detailed analysis on macOS, FreeBSD and Linux.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/job-output-null.exp \
src/usr.bin/make/unit-tests/job-output-null.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/job-output-null.exp
diff -u src/usr.bin/make/unit-tests/job-output-null.exp:1.1 src/usr.bin/make/unit-tests/job-output-null.exp:1.2
--- src/usr.bin/make/unit-tests/job-output-null.exp:1.1	Thu Apr 15 19:02:29 2021
+++ src/usr.bin/make/unit-tests/job-output-null.exp	Sat Jul  3 22:39:40 2021
@@ -1,4 +1,4 @@
 hello
 hello
-hello world without   newline, hello world without   newline, hello world without   newline.
+hello without   newline, hello without   newline.
 exit status 0
Index: src/usr.bin/make/unit-tests/job-output-null.mk
diff -u src/usr.bin/make/unit-tests/job-output-null.mk:1.1 src/usr.bin/make/unit-tests/job-output-null.mk:1.2
--- src/usr.bin/make/unit-tests/job-output-null.mk:1.1	Thu Apr 15 19:02:29 2021
+++ src/usr.bin/make/unit-tests/job-output-null.mk	Sat Jul  3 22:39:40 2021
@@ -1,4 +1,4 @@
-# $NetBSD: job-output-null.mk,v 1.1 2021/04/15 19:02:29 rillig Exp $
+# $NetBSD: job-output-null.mk,v 1.2 2021/07/03 22:39:40 rillig Exp $
 #
 # Test how null bytes in the output of a command are handled.  Make processes
 # them using null-terminated strings, which may cut off some of the output.
@@ -7,20 +7,33 @@
 # inconsistently.  It's an edge case though since typically the child
 # processes output text.
 
+# Note: The printf commands used in this test must only use a single format
+# string, without parameters.  This is because it is implementation-dependent
+# how many times the command 'printf "fmt%s" "" "" ""' calls write(2).
+#
+#	NetBSD /bin/sh		1 x write("fmtfmtfmt")
+#	Dash			1 x write("fmtfmtfmt")
+#	NetBSD /bin/ksh		3 x write("fmt") (via /bin/printf)
+#	Bash 5			3 x write("fmt")
+#
+# In the latter case the output may arrive in parts, which in this test makes
+# a crucial difference since the outcome of the test depends on whether there
+# is a '\n' in each of the blocks from the output.
+
 .MAKEFLAGS: -j1		# force jobs mode
 
 all: .PHONY
 	# The null byte from the command output is kept as-is.
 	# See CollectOutput, which looks like it intended to replace these
 	# null bytes with simple spaces.
-	@printf 'hello\0world%s\n' ''
+	@printf 'hello\0world\n'
 
 	# Give the parent process a chance to see the above output, but not
 	# yet the output from the next printf command.
 	@sleep 1
 
 	# All null bytes from the command output are kept as-is.
-	@printf 'hello\0world%s\n' '' '' '' '' '' ''
+	@printf 'hello\0world\n''hello\0world\n''hello\0world\n'
 
 	@sleep 1
 
@@ -29,4 +42,4 @@ all: .PHONY
 	#
 	# The three null bytes in a row test whether this output is
 	# compressed to a single space like in DebugFailedTarget.  It isn't.
-	@printf 'hello\0world\0without\0\0\0newline%s' ', ' ', ' '.'
+	@printf 'hello\0without\0\0\0newline, hello\0without\0\0\0newline.'



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

2021-06-28 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Tue Jun 29 00:35:23 UTC 2021

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

Log Message:
Allow BROKEN_TESTS to cause TESTS to be skipped.

Some tests simply do not work in some environments.
Eg. shell-ksh on macos/arm64
Allow local site to set BROKEN_TESTS to skip those they know
will not work.

Reviewed by: rillig


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/usr.bin/make/unit-tests/Makefile

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

Modified files:

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.279 src/usr.bin/make/unit-tests/Makefile:1.280
--- src/usr.bin/make/unit-tests/Makefile:1.279	Wed Jun 16 09:39:48 2021
+++ src/usr.bin/make/unit-tests/Makefile	Tue Jun 29 00:35:23 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.279 2021/06/16 09:39:48 rillig Exp $
+# $NetBSD: Makefile,v 1.280 2021/06/29 00:35:23 sjg Exp $
 #
 # Unit tests for make(1)
 #
@@ -429,6 +429,12 @@ TESTS+=		varparse-mod
 TESTS+=		varparse-undef-partial
 TESTS+=		varquote
 
+# Some tests just do not work on some platforms or environments
+# so allow for some filtering.
+.if !empty(BROKEN_TESTS)
+TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts:}}
+.endif
+
 # Ideas for more tests:
 #	char-0020-space.mk
 #	char-005C-backslash.mk



CVS commit: src/usr.bin/make

2021-06-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 25 16:10:07 UTC 2021

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

Log Message:
make: prevent newline injection in .for loops

When a value of a .for loop contained a literal newline, such as from
the expression ${.newline}, that newline was passed verbatim to the
"expanded current body" of the .for loop.  There it was interpreted as a
literal newline, which ended the current line and started a new one.
This resulted in several syntax errors.

In cases like these, print a more precise error message.


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/usr.bin/make/for.c
cvs rdiff -u -r1.10 -r1.11 \
src/usr.bin/make/unit-tests/directive-for-escape.exp
cvs rdiff -u -r1.9 -r1.10 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/for.c
diff -u src/usr.bin/make/for.c:1.143 src/usr.bin/make/for.c:1.144
--- src/usr.bin/make/for.c:1.143	Thu Jun 24 23:19:52 2021
+++ src/usr.bin/make/for.c	Fri Jun 25 16:10:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.143 2021/06/24 23:19:52 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.144 2021/06/25 16:10:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.143 2021/06/24 23:19:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.144 2021/06/25 16:10:07 rillig Exp $");
 
 
 /* One of the variables to the left of the "in" in a .for loop. */
@@ -325,7 +325,8 @@ NeedsEscapes(const char *value, char end
 	const char *p;
 
 	for (p = value; *p != '\0'; p++) {
-		if (*p == ':' || *p == '$' || *p == '\\' || *p == endc)
+		if (*p == ':' || *p == '$' || *p == '\\' || *p == endc ||
+		*p == '\n')
 			return true;
 	}
 	return false;
@@ -360,6 +361,10 @@ Buf_AddEscaped(Buffer *cmds, const char 
 			Buf_AddByte(cmds, '\\');
 		} else if (ch == ':' || ch == '\\' || ch == endc)
 			Buf_AddByte(cmds, '\\');
+		else if (ch == '\n') {
+			Parse_Error(PARSE_FATAL, "newline in .for value");
+			ch = ' ';	/* prevent newline injection */
+		}
 		Buf_AddByte(cmds, ch);
 	}
 }

Index: src/usr.bin/make/unit-tests/directive-for-escape.exp
diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.10 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.11
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.10	Fri Jun 25 15:56:02 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Fri Jun 25 16:10:07 2021
@@ -80,17 +80,13 @@ make: "directive-for-escape.mk" line 118
 make: "directive-for-escape.mk" line 119: eight dollardollardollardollar and no cents.
 make: "directive-for-escape.mk" line 128: eight  and no cents.
 For: end for 1
+make: "directive-for-escape.mk" line 135: newline in .for value
+make: "directive-for-escape.mk" line 135: newline in .for value
 For: loop body:
-.  info short: ${:U"
-"}
-.  info long: ${:U"
-"}
-make: Unclosed variable expression, expecting '}' for modifier "U"" of variable "" with value """
-make: "directive-for-escape.mk" line 134: short: "
-make: "directive-for-escape.mk" line 135: Invalid line type
-make: Unclosed variable expression, expecting '}' for modifier "U"" of variable "" with value """
-make: "directive-for-escape.mk" line 136: long: "
-make: "directive-for-escape.mk" line 137: Invalid line type
+.  info short: ${:U" "}
+.  info long: ${:U" "}
+make: "directive-for-escape.mk" line 136: short: " "
+make: "directive-for-escape.mk" line 137: long: " "
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/directive-for-escape.mk
diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.9 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.10
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.9	Fri Jun 25 15:56:02 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk	Fri Jun 25 16:10:07 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.9 2021/06/25 15:56:02 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.10 2021/06/25 16:10:07 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
@@ -128,8 +128,10 @@ ${closing-brace}=		# alte
 .info eight ${$}${$}${$}${$} and no cents.
 
 # What happens if the values from the .for loop contain a literal newline?
-# Oops, the newline is added verbatim to the loop body, where it is later
-# interpreted as an ordinary newline.
+# Before for.c 1.144 from 2021-06-25, the newline was passed verbatim to the
+# body of the .for loop, where it was then interpreted as a literal newline,
+# leading to syntax error

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

2021-06-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 25 15:56:02 UTC 2021

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

Log Message:
tests/make: demonstrate newline injection in .for loop


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 \
src/usr.bin/make/unit-tests/directive-for-escape.exp
cvs rdiff -u -r1.8 -r1.9 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.9 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.10
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.9	Thu Jun 24 23:22:17 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Fri Jun 25 15:56:02 2021
@@ -79,4 +79,18 @@ For: loop body:
 make: "directive-for-escape.mk" line 118: eight  and no cents.
 make: "directive-for-escape.mk" line 119: eight dollardollardollardollar and no cents.
 make: "directive-for-escape.mk" line 128: eight  and no cents.
-exit status 0
+For: end for 1
+For: loop body:
+.  info short: ${:U"
+"}
+.  info long: ${:U"
+"}
+make: Unclosed variable expression, expecting '}' for modifier "U"" of variable "" with value """
+make: "directive-for-escape.mk" line 134: short: "
+make: "directive-for-escape.mk" line 135: Invalid line type
+make: Unclosed variable expression, expecting '}' for modifier "U"" of variable "" with value """
+make: "directive-for-escape.mk" line 136: long: "
+make: "directive-for-escape.mk" line 137: Invalid line type
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/directive-for-escape.mk
diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.8 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.9
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.8	Thu Jun 24 23:22:17 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk	Fri Jun 25 15:56:02 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.8 2021/06/24 23:22:17 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.9 2021/06/25 15:56:02 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
@@ -127,4 +127,12 @@ closing-brace=		}		# guard against an
 ${closing-brace}=		# alternative interpretation
 .info eight ${$}${$}${$}${$} and no cents.
 
+# What happens if the values from the .for loop contain a literal newline?
+# Oops, the newline is added verbatim to the loop body, where it is later
+# interpreted as an ordinary newline.
+.for i in "${.newline}"
+.  info short: $i
+.  info long: ${i}
+.endfor
+
 all:



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

2021-06-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jun 24 23:22:17 UTC 2021

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

Log Message:
tests/make: test .for loop over a variable named '$'

It's an impractical edge case, nevertheless it's accepted by make.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/directive-for-escape.exp
cvs rdiff -u -r1.7 -r1.8 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.8 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.9
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.8	Tue Feb 23 15:56:30 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Thu Jun 24 23:22:17 2021
@@ -72,4 +72,11 @@ make: "directive-for-escape.mk" line 107
 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
+For: end for 1
+For: loop body:
+.  info eight  and no cents.
+.  info eight ${:Udollar}${:Udollar}${:Udollar}${:Udollar} and no cents.
+make: "directive-for-escape.mk" line 118: eight  and no cents.
+make: "directive-for-escape.mk" line 119: eight dollardollardollardollar and no cents.
+make: "directive-for-escape.mk" line 128: eight  and no cents.
 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.7 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.8
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.7	Mon Feb 15 07:58:19 2021
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk	Thu Jun 24 23:22:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.7 2021/02/15 07:58:19 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.8 2021/06/24 23:22:17 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
@@ -110,4 +110,21 @@ i,=		comma
 .  info .  adjacent: $i${i}${i:M*}$i
 .endfor
 
+# The variable name can be a single '$' since there is no check on valid
+# variable names. ForLoop_SubstVarShort skips "stupid" variable names though,
+# but ForLoop_SubstVarLong naively parses the body of the loop, substituting
+# each '${$}' with an actual 'dollar'.
+.for $ in dollar
+.  info eight  and no cents.
+.  info eight ${$}${$}${$}${$} and no cents.
+.endfor
+# Outside a .for loop, '${$}' is interpreted differently. The outer '$' starts
+# a variable expression. The inner '$' is followed by a '}' and is thus a
+# silent syntax error, the '$' is skipped. The variable name is thus '', and
+# since since there is never a variable named '', the whole expression '${$}'
+# evaluates to an empty string.
+closing-brace=		}		# guard against an
+${closing-brace}=		# alternative interpretation
+.info eight ${$}${$}${$}${$} and no cents.
+
 all:



CVS commit: src/usr.bin/make

2021-06-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jun 24 23:19:52 UTC 2021

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

Log Message:
make: sprinkle const


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.142 src/usr.bin/make/for.c:1.143
--- src/usr.bin/make/for.c:1.142	Sat Apr  3 11:08:40 2021
+++ src/usr.bin/make/for.c	Thu Jun 24 23:19:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.142 2021/04/03 11:08:40 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.143 2021/06/24 23:19:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.142 2021/04/03 11:08:40 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.143 2021/06/24 23:19:52 rillig Exp $");
 
 
 /* One of the variables to the left of the "in" in a .for loop. */
@@ -72,15 +72,15 @@ typedef struct ForLoop {
 	Vector /* of ForVar */ vars; /* Iteration variables */
 	Words items;		/* Substitution items */
 	Buffer curBody;		/* Expanded body of the current iteration */
-	/* Is any of the names 1 character long? If so, when the variable values
-	 * are substituted, the parser must handle $V expressions as well, not
-	 * only ${V} and $(V). */
+	/* Is any of the names 1 character long? If so, when the variable
+	 * values are substituted, the parser must handle $V expressions as
+	 * well, not only ${V} and $(V). */
 	bool short_var;
 	unsigned int sub_next;	/* Where to continue iterating */
 } ForLoop;
 
 
-static ForLoop *accumFor;		/* Loop being accumulated */
+static ForLoop *accumFor;	/* Loop being accumulated */
 static int forLevel = 0;	/* Nesting level */
 
 
@@ -376,8 +376,8 @@ ForLoop_SubstVarLong(ForLoop *f, const c
 	const char *p = *pp;
 
 	for (i = 0; i < f->vars.len; i++) {
-		ForVar *forVar = Vector_Get(&f->vars, i);
-		char *varname = forVar->name;
+		const ForVar *forVar = Vector_Get(&f->vars, i);
+		const char *varname = forVar->name;
 		size_t varnameLen = forVar->nameLen;
 
 		if (varnameLen >= (size_t)(bodyEnd - p))
@@ -413,7 +413,7 @@ static void
 ForLoop_SubstVarShort(ForLoop *f, const char *p, const char **inout_mark)
 {
 	const char ch = *p;
-	ForVar *vars;
+	const ForVar *vars;
 	size_t i;
 
 	/* Skip $$ and stupid ones. */



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 21:10:01 UTC 2021

Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: cond-token-plain.exp

Log Message:
make: fix grammar in error message for malformed conditional


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/usr.bin/make/cond.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-token-plain.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/cond.c
diff -u src/usr.bin/make/cond.c:1.268 src/usr.bin/make/cond.c:1.269
--- src/usr.bin/make/cond.c:1.268	Mon Jun 21 21:07:35 2021
+++ src/usr.bin/make/cond.c	Mon Jun 21 21:10:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.268 2021/06/21 21:07:35 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.269 2021/06/21 21:10:01 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.268 2021/06/21 21:07:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.269 2021/06/21 21:10:01 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -699,7 +699,7 @@ CondParser_Comparison(CondParser *par, b
 
 	if (par->p[0] == '\0') {
 		Parse_Error(PARSE_FATAL,
-		"Missing right-hand-side of operator '%s'", opname[op]);
+		"Missing right-hand side of operator '%s'", opname[op]);
 		par->printedError = true;
 		goto done_lhs;
 	}

Index: src/usr.bin/make/unit-tests/cond-token-plain.exp
diff -u src/usr.bin/make/unit-tests/cond-token-plain.exp:1.9 src/usr.bin/make/unit-tests/cond-token-plain.exp:1.10
--- src/usr.bin/make/unit-tests/cond-token-plain.exp:1.9	Thu Jan 21 23:32:28 2021
+++ src/usr.bin/make/unit-tests/cond-token-plain.exp	Mon Jun 21 21:10:01 2021
@@ -39,7 +39,7 @@ make: "cond-token-plain.mk" line 130: Nu
 CondParser_Eval: 0${:Ux01}
 make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
 CondParser_Eval: "" ==
-make: "cond-token-plain.mk" line 140: Missing right-hand-side of operator '=='
+make: "cond-token-plain.mk" line 140: Missing right-hand side of operator '=='
 CondParser_Eval: == ""
 make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
 CondParser_Eval: \\



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 21:07:35 UTC 2021

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

Log Message:
make: clean up comments in cond.c


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.267 src/usr.bin/make/cond.c:1.268
--- src/usr.bin/make/cond.c:1.267	Fri Jun 11 14:52:03 2021
+++ src/usr.bin/make/cond.c	Mon Jun 21 21:07:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.267 2021/06/11 14:52:03 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.268 2021/06/21 21:07:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.267 2021/06/11 14:52:03 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.268 2021/06/21 21:07:35 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -171,6 +171,7 @@ static CondResult CondParser_Or(CondPars
 static unsigned int cond_depth = 0;	/* current .if nesting level */
 static unsigned int cond_min_depth = 0;	/* depth at makefile open */
 
+/* Names for ComparisonOp. */
 static const char *opname[] = { "<", "<=", ">", ">=", "==", "!=" };
 
 /*
@@ -309,7 +310,7 @@ FuncDefined(size_t argLen MAKE_ATTR_UNUS
 	return result;
 }
 
-/* See if the given target is being made. */
+/* See if the given target is requested to be made. */
 /*ARGSUSED*/
 static bool
 FuncMake(size_t argLen MAKE_ATTR_UNUSED, const char *arg)
@@ -682,10 +683,6 @@ CondParser_Comparison(CondParser *par, b
 	ComparisonOp op;
 	bool lhsQuoted, rhsQuoted;
 
-	/*
-	 * Parse the variable spec and skip over it, saving its
-	 * value in lhs.
-	 */
 	CondParser_Leaf(par, doEval, lhsStrict, &lhs, &lhsQuoted);
 	if (lhs.str == NULL)
 		goto done_lhs;



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 19:59:58 UTC 2021

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

Log Message:
make: use simpler upper bound for length in Buf_AddInt

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/make/buf.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/buf.c
diff -u src/usr.bin/make/buf.c:1.51 src/usr.bin/make/buf.c:1.52
--- src/usr.bin/make/buf.c:1.51	Sat Jan 30 21:18:14 2021
+++ src/usr.bin/make/buf.c	Mon Jun 21 19:59:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.c,v 1.51 2021/01/30 21:18:14 rillig Exp $	*/
+/*	$NetBSD: buf.c,v 1.52 2021/06/21 19:59:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,7 +75,7 @@
 #include "make.h"
 
 /*	"@(#)buf.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: buf.c,v 1.51 2021/01/30 21:18:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.52 2021/06/21 19:59:58 rillig Exp $");
 
 /* Make space in the buffer for adding at least 16 more bytes. */
 void
@@ -122,14 +122,7 @@ Buf_AddStr(Buffer *buf, const char *str)
 void
 Buf_AddInt(Buffer *buf, int n)
 {
-	enum {
-		bits = sizeof(int) * CHAR_BIT,
-		max_octal_digits = (bits + 2) / 3,
-		max_decimal_digits = /* at most */ max_octal_digits,
-		max_sign_chars = 1,
-		str_size = max_sign_chars + max_decimal_digits + 1
-	};
-	char str[str_size];
+	char str[sizeof(int) * CHAR_BIT + 1];
 
 	size_t len = (size_t)snprintf(str, sizeof str, "%d", n);
 	Buf_AddBytes(buf, str, len);



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 18:54:41 UTC 2021

Modified Files:
src/usr.bin/make: metachar.c metachar.h

Log Message:
make: replace macro is_shell_metachar with inline function

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/metachar.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/metachar.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/metachar.c
diff -u src/usr.bin/make/metachar.c:1.9 src/usr.bin/make/metachar.c:1.10
--- src/usr.bin/make/metachar.c:1.9	Tue Jan 19 20:51:46 2021
+++ src/usr.bin/make/metachar.c	Mon Jun 21 18:54:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: metachar.c,v 1.9 2021/01/19 20:51:46 rillig Exp $	*/
+/*	$NetBSD: metachar.c,v 1.10 2021/06/21 18:54:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 
 #include "metachar.h"
 
-MAKE_RCSID("$NetBSD: metachar.c,v 1.9 2021/01/19 20:51:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: metachar.c,v 1.10 2021/06/21 18:54:41 rillig Exp $");
 
 /*
  * The following array is used to make a fast determination of which
@@ -48,7 +48,7 @@ MAKE_RCSID("$NetBSD: metachar.c,v 1.9 20
  * directly by us.
  */
 
-unsigned char _metachar[128] = {
+const unsigned char _metachar[128] = {
 /*nul   soh   stx   etx   eot   enq   ack   bel */
 	1,0,0,0,0,0,0,0,
 /* bshtnlvtnpcrsosi */

Index: src/usr.bin/make/metachar.h
diff -u src/usr.bin/make/metachar.h:1.16 src/usr.bin/make/metachar.h:1.17
--- src/usr.bin/make/metachar.h:1.16	Sat Apr  3 11:08:40 2021
+++ src/usr.bin/make/metachar.h	Mon Jun 21 18:54:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: metachar.h,v 1.16 2021/04/03 11:08:40 rillig Exp $	*/
+/*	$NetBSD: metachar.h,v 1.17 2021/06/21 18:54:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,9 +33,13 @@
 
 #include "make.h"
 
-extern unsigned char _metachar[];
+extern const unsigned char _metachar[];
 
-#define is_shell_metachar(c)	(_metachar[(c) & 0x7f] != 0)
+MAKE_INLINE bool
+is_shell_metachar(char c)
+{
+	return _metachar[c & 0x7f] != 0;
+}
 
 MAKE_INLINE bool
 needshell(const char *cmd)



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 18:25:20 UTC 2021

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

Log Message:
make: use more practical data type in RegexReplace

While size_t is most appropriate for array indexes, make needs to be
compatible with C90, which does not support the %zu printf conversion.
To avoid type casts, use a simple unsigned int here, which is more than
enough for storing a single decimal digit.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.937 -r1.938 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.937 src/usr.bin/make/var.c:1.938
--- src/usr.bin/make/var.c:1.937	Mon Jun 21 18:12:49 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 18:25:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.937 2021/06/21 18:12:49 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.938 2021/06/21 18:25:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.937 2021/06/21 18:12:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.938 2021/06/21 18:25:20 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1594,7 +1594,7 @@ RegexReplace(const char *replace, SepBuf
 	 const regmatch_t *m, size_t nsub)
 {
 	const char *rp;
-	size_t n;
+	unsigned int n;
 
 	for (rp = replace; *rp != '\0'; rp++) {
 		if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
@@ -1615,15 +1615,14 @@ RegexReplace(const char *replace, SepBuf
 		}
 
 		/* \0 to \9 backreference */
-		n = (size_t)(rp[1] - '0');
+		n = rp[1] - '0';
 		rp++;
 
 		if (n >= nsub) {
-			Error("No subexpression \\%u", (unsigned)n);
+			Error("No subexpression \\%u", n);
 		} else if (m[n].rm_so == -1) {
 			if (opts.strict) {
-Error("No match for subexpression \\%u",
-(unsigned)n);
+Error("No match for subexpression \\%u", n);
 			}
 		} else {
 			SepBuf_AddBytesBetween(buf,



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 18:12:49 UTC 2021

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

Log Message:
make: extract RegexReplace from ModifyWord_SubstRegex

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.936 -r1.937 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.936 src/usr.bin/make/var.c:1.937
--- src/usr.bin/make/var.c:1.936	Mon Jun 21 17:52:33 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 18:12:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.936 2021/06/21 17:52:33 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.937 2021/06/21 18:12:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.936 2021/06/21 17:52:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.937 2021/06/21 18:12:49 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1585,6 +1585,53 @@ VarREError(int reerr, const regex_t *pat
 	free(errbuf);
 }
 
+/*
+ * Replacement of regular expressions is not specified by POSIX, therefore
+ * re-implement it here.
+ */
+static void
+RegexReplace(const char *replace, SepBuf *buf, const char *wp,
+	 const regmatch_t *m, size_t nsub)
+{
+	const char *rp;
+	size_t n;
+
+	for (rp = replace; *rp != '\0'; rp++) {
+		if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
+			SepBuf_AddBytes(buf, rp + 1, 1);
+			rp++;
+			continue;
+		}
+
+		if (*rp == '&') {
+			SepBuf_AddBytesBetween(buf,
+			wp + m[0].rm_so, wp + m[0].rm_eo);
+			continue;
+		}
+
+		if (*rp != '\\' || !ch_isdigit(rp[1])) {
+			SepBuf_AddBytes(buf, rp, 1);
+			continue;
+		}
+
+		/* \0 to \9 backreference */
+		n = (size_t)(rp[1] - '0');
+		rp++;
+
+		if (n >= nsub) {
+			Error("No subexpression \\%u", (unsigned)n);
+		} else if (m[n].rm_so == -1) {
+			if (opts.strict) {
+Error("No match for subexpression \\%u",
+(unsigned)n);
+			}
+		} else {
+			SepBuf_AddBytesBetween(buf,
+			wp + m[n].rm_so, wp + m[n].rm_eo);
+		}
+	}
+}
+
 struct ModifyWord_SubstRegexArgs {
 	regex_t re;
 	size_t nsub;
@@ -1603,10 +1650,8 @@ ModifyWord_SubstRegex(Substring word, Se
 	struct ModifyWord_SubstRegexArgs *args = data;
 	int xrv;
 	const char *wp;
-	const char *rp;
 	int flags = 0;
 	regmatch_t m[10];
-	size_t n;
 
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
 	wp = word.start;
@@ -1627,45 +1672,7 @@ ok:
 	args->matched = true;
 	SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
 
-	/*
-	 * Replacement of regular expressions is not specified by
-	 * POSIX, therefore re-implement it here.
-	 */
-
-	for (rp = args->replace; *rp != '\0'; rp++) {
-		if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
-			SepBuf_AddBytes(buf, rp + 1, 1);
-			rp++;
-			continue;
-		}
-
-		if (*rp == '&') {
-			SepBuf_AddBytesBetween(buf,
-			wp + m[0].rm_so, wp + m[0].rm_eo);
-			continue;
-		}
-
-		if (*rp != '\\' || !ch_isdigit(rp[1])) {
-			SepBuf_AddBytes(buf, rp, 1);
-			continue;
-		}
-
-		/* \0 to \9 backreference */
-		n = (size_t)(rp[1] - '0');
-		rp++;
-
-		if (n >= args->nsub) {
-			Error("No subexpression \\%u", (unsigned)n);
-		} else if (m[n].rm_so == -1) {
-			if (opts.strict) {
-Error("No match for subexpression \\%u",
-(unsigned)n);
-			}
-		} else {
-			SepBuf_AddBytesBetween(buf,
-			wp + m[n].rm_so, wp + m[n].rm_eo);
-		}
-	}
+	RegexReplace(args->replace, buf, wp, m, args->nsub);
 
 	wp += m[0].rm_eo;
 	if (args->pflags.subGlobal) {



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 17:52:33 UTC 2021

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

Log Message:
make: move all labels in ModifyWord_SubstRegex to the same level

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.935 -r1.936 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.935 src/usr.bin/make/var.c:1.936
--- src/usr.bin/make/var.c:1.935	Mon Jun 21 17:21:37 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 17:52:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.935 2021/06/21 17:21:37 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.936 2021/06/21 17:52:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.935 2021/06/21 17:21:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.936 2021/06/21 17:52:33 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1610,11 +1610,8 @@ ModifyWord_SubstRegex(Substring word, Se
 
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
 	wp = word.start;
-	if (args->pflags.subOnce && args->matched) {
-	nosub:
-		SepBuf_AddStr(buf, wp);
-		return;
-	}
+	if (args->pflags.subOnce && args->matched)
+		goto no_match;
 
 again:
 	xrv = regexec(&args->re, wp, args->nsub, m, flags);
@@ -1622,7 +1619,9 @@ again:
 		goto ok;
 	if (xrv != REG_NOMATCH)
 		VarREError(xrv, &args->re, "Unexpected regex error");
-	goto nosub;
+no_match:
+	SepBuf_AddStr(buf, wp);
+	return;
 
 ok:
 	args->matched = true;



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 17:21:37 UTC 2021

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

Log Message:
make: reduce indentation in ModifyWord_SubstRegex for ':C'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.934 -r1.935 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.934 src/usr.bin/make/var.c:1.935
--- src/usr.bin/make/var.c:1.934	Mon Jun 21 08:40:44 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 17:21:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.934 2021/06/21 08:40:44 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.935 2021/06/21 17:21:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.934 2021/06/21 08:40:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.935 2021/06/21 17:21:37 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1606,84 +1606,80 @@ ModifyWord_SubstRegex(Substring word, Se
 	const char *rp;
 	int flags = 0;
 	regmatch_t m[10];
+	size_t n;
 
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
 	wp = word.start;
-	if (args->pflags.subOnce && args->matched)
-		goto nosub;
+	if (args->pflags.subOnce && args->matched) {
+	nosub:
+		SepBuf_AddStr(buf, wp);
+		return;
+	}
 
-tryagain:
+again:
 	xrv = regexec(&args->re, wp, args->nsub, m, flags);
+	if (xrv == 0)
+		goto ok;
+	if (xrv != REG_NOMATCH)
+		VarREError(xrv, &args->re, "Unexpected regex error");
+	goto nosub;
 
-	switch (xrv) {
-	case 0:
-		args->matched = true;
-		SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
+ok:
+	args->matched = true;
+	SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
 
-		/*
-		 * Replacement of regular expressions is not specified by
-		 * POSIX, therefore implement it here.
-		 */
+	/*
+	 * Replacement of regular expressions is not specified by
+	 * POSIX, therefore re-implement it here.
+	 */
 
-		for (rp = args->replace; *rp != '\0'; rp++) {
-			if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
-SepBuf_AddBytes(buf, rp + 1, 1);
-rp++;
-continue;
-			}
+	for (rp = args->replace; *rp != '\0'; rp++) {
+		if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
+			SepBuf_AddBytes(buf, rp + 1, 1);
+			rp++;
+			continue;
+		}
 
-			if (*rp == '&') {
-SepBuf_AddBytesBetween(buf,
-wp + m[0].rm_so, wp + m[0].rm_eo);
-continue;
-			}
+		if (*rp == '&') {
+			SepBuf_AddBytesBetween(buf,
+			wp + m[0].rm_so, wp + m[0].rm_eo);
+			continue;
+		}
 
-			if (*rp != '\\' || !ch_isdigit(rp[1])) {
-SepBuf_AddBytes(buf, rp, 1);
-continue;
-			}
+		if (*rp != '\\' || !ch_isdigit(rp[1])) {
+			SepBuf_AddBytes(buf, rp, 1);
+			continue;
+		}
 
-			{	/* \0 to \9 backreference */
-size_t n = (size_t)(rp[1] - '0');
-rp++;
-
-if (n >= args->nsub) {
-	Error("No subexpression \\%u",
-	(unsigned)n);
-} else if (m[n].rm_so == -1) {
-	if (opts.strict) {
-		Error(
-		"No match for subexpression \\%u",
-			(unsigned)n);
-	}
-} else {
-	SepBuf_AddBytesBetween(buf,
-	wp + m[n].rm_so, wp + m[n].rm_eo);
-}
+		/* \0 to \9 backreference */
+		n = (size_t)(rp[1] - '0');
+		rp++;
+
+		if (n >= args->nsub) {
+			Error("No subexpression \\%u", (unsigned)n);
+		} else if (m[n].rm_so == -1) {
+			if (opts.strict) {
+Error("No match for subexpression \\%u",
+(unsigned)n);
 			}
+		} else {
+			SepBuf_AddBytesBetween(buf,
+			wp + m[n].rm_so, wp + m[n].rm_eo);
 		}
+	}
 
-		wp += m[0].rm_eo;
-		if (args->pflags.subGlobal) {
-			flags |= REG_NOTBOL;
-			if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
-SepBuf_AddBytes(buf, wp, 1);
-wp++;
-			}
-			if (*wp != '\0')
-goto tryagain;
+	wp += m[0].rm_eo;
+	if (args->pflags.subGlobal) {
+		flags |= REG_NOTBOL;
+		if (m[0].rm_so == 0 && m[0].rm_eo == 0) {
+			SepBuf_AddBytes(buf, wp, 1);
+			wp++;
 		}
 		if (*wp != '\0')
-			SepBuf_AddStr(buf, wp);
-		break;
-	default:
-		VarREError(xrv, &args->re, "Unexpected regex error");
-		/* FALLTHROUGH */
-	case REG_NOMATCH:
-	nosub:
-		SepBuf_AddStr(buf, wp);
-		break;
+			goto again;
 	}
+	if (*wp != '\0')
+		SepBuf_AddStr(buf, wp);
 }
 #endif
 



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 16:59:18 UTC 2021

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

Log Message:
make: eliminate local variable in Substring_Words

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/make/str.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/str.c
diff -u src/usr.bin/make/str.c:1.85 src/usr.bin/make/str.c:1.86
--- src/usr.bin/make/str.c:1.85	Sun May 30 21:16:54 2021
+++ src/usr.bin/make/str.c	Mon Jun 21 16:59:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.85 2021/05/30 21:16:54 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.86 2021/06/21 16:59:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.85 2021/05/30 21:16:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.86 2021/06/21 16:59:18 rillig Exp $");
 
 /* Return the concatenation of s1 and s2, freshly allocated. */
 char *
@@ -188,10 +188,9 @@ Substring_Words(const char *str, bool ex
 
 			*word_end++ = '\0';
 			if (words_len == words_cap) {
-size_t new_size;
 words_cap *= 2;
-new_size = (words_cap + 1) * sizeof(words[0]);
-words = bmake_realloc(words, new_size);
+words = bmake_realloc(words,
+(words_cap + 1) * sizeof(words[0]));
 			}
 			words[words_len++] =
 			Substring_Init(word_start, word_end - 1);



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 10:42:06 UTC 2021

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

Log Message:
make: document ParseDependencyOp


To generate a diff of this commit:
cvs rdiff -u -r1.559 -r1.560 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.559 src/usr.bin/make/parse.c:1.560
--- src/usr.bin/make/parse.c:1.559	Mon Jun 21 10:33:11 2021
+++ src/usr.bin/make/parse.c	Mon Jun 21 10:42:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.559 2021/06/21 10:33:11 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.560 2021/06/21 10:42:06 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.559 2021/06/21 10:33:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.560 2021/06/21 10:42:06 rillig Exp $");
 
 /* types and constants */
 
@@ -1265,8 +1265,12 @@ ParseDependencyCheckSpec(ParseSpecial sp
 	}
 }
 
+/*
+ * In a dependency line like 'targets: sources' or 'targets! sources', parse
+ * the operator ':', '::' or '!' from between the targets and the sources.
+ */
 static bool
-ParseDependencyParseOp(char **pp, const char *lstart, GNodeType *out_op)
+ParseDependencyOp(char **pp, const char *lstart, GNodeType *out_op)
 {
 	const char *cp = *pp;
 
@@ -1694,7 +1698,7 @@ ParseDependency(char *line)
 	/*
 	 * First, grind through the targets.
 	 */
-	/* XXX: don't use line as an iterator variable */
+	/* XXX: don't use 'line' as an iterator variable */
 	if (!ParseDependencyTargets(&cp, &line, lstart, &specType, &tOp,
 	&paths, &curTargs))
 		goto out;
@@ -1712,7 +1716,7 @@ ParseDependency(char *line)
 	/*
 	 * Have now parsed all the target names. Must parse the operator next.
 	 */
-	if (!ParseDependencyParseOp(&cp, lstart, &op))
+	if (!ParseDependencyOp(&cp, lstart, &op))
 		goto out;
 
 	/*



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 10:33:11 UTC 2021

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

Log Message:
make: document where to find tests for the dependency lines


To generate a diff of this commit:
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/make/make.h
cvs rdiff -u -r1.558 -r1.559 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.262 src/usr.bin/make/make.h:1.263
--- src/usr.bin/make/make.h:1.262	Wed Apr 14 17:39:11 2021
+++ src/usr.bin/make/make.h	Mon Jun 21 10:33:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.262 2021/04/14 17:39:11 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.263 2021/06/21 10:33:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -206,6 +206,8 @@ typedef enum GNodeMade {
  * should be made.
  *
  * Some of the OP_ constants can be combined, others cannot.
+ *
+ * See the tests depsrc-*.mk and deptgt-*.mk.
  */
 typedef enum GNodeType {
 	OP_NONE		= 0,

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.558 src/usr.bin/make/parse.c:1.559
--- src/usr.bin/make/parse.c:1.558	Mon Jun 21 10:29:08 2021
+++ src/usr.bin/make/parse.c	Mon Jun 21 10:33:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.558 2021/06/21 10:29:08 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.559 2021/06/21 10:33:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.558 2021/06/21 10:29:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.559 2021/06/21 10:33:11 rillig Exp $");
 
 /* types and constants */
 
@@ -1054,7 +1054,11 @@ ParseDependencyTargetWord(const char **p
 	*pp = cp;
 }
 
-/* Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER. */
+/*
+ * Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER.
+ *
+ * See the tests deptgt-*.mk.
+ */
 static void
 ParseDependencyTargetSpecial(ParseSpecial *inout_specType,
 			 const char *targetName,
@@ -1583,7 +1587,11 @@ ParseDependencySourcesMundane(char *star
 	return true;
 }
 
-/* In a dependency line like 'targets: sources', parse the sources. */
+/*
+ * In a dependency line like 'targets: sources', parse the sources.
+ *
+ * See the tests depsrc-*.mk.
+ */
 static void
 ParseDependencySources(char *const line, char *const cp,
 		   GNodeType const tOp,



CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 10:29:08 UTC 2021

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

Log Message:
make: extract ParseDependencySources from ParseDependency

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.557 -r1.558 src/usr.bin/make/parse.c

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

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.557 src/usr.bin/make/parse.c:1.558
--- src/usr.bin/make/parse.c:1.557	Sun Apr  4 11:56:43 2021
+++ src/usr.bin/make/parse.c	Mon Jun 21 10:29:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.557 2021/04/04 11:56:43 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.558 2021/06/21 10:29:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.557 2021/04/04 11:56:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.558 2021/06/21 10:29:08 rillig Exp $");
 
 /* types and constants */
 
@@ -1303,6 +1303,15 @@ ClearPaths(SearchPathList *paths)
 	Dir_SetPATH();
 }
 
+/*
+ * Several special targets take different actions if present with no
+ * sources:
+ *	a .SUFFIXES line with no sources clears out all old suffixes
+ *	a .PRECIOUS line makes all targets precious
+ *	a .IGNORE line ignores errors for all targets
+ *	a .SILENT line creates silence when making all targets
+ *	a .PATH removes all directories from the search path(s).
+ */
 static void
 ParseDependencySourcesEmpty(ParseSpecial specType, SearchPathList *paths)
 {
@@ -1574,6 +1583,55 @@ ParseDependencySourcesMundane(char *star
 	return true;
 }
 
+/* In a dependency line like 'targets: sources', parse the sources. */
+static void
+ParseDependencySources(char *const line, char *const cp,
+		   GNodeType const tOp,
+		   ParseSpecial const specType,
+		   SearchPathList ** inout_paths)
+{
+	if (line[0] == '\0') {
+		ParseDependencySourcesEmpty(specType, *inout_paths);
+	} else if (specType == SP_MFLAGS) {
+		Main_ParseArgLine(line);
+		/*
+		 * Set the initial character to a null-character so the loop
+		 * to get sources won't get anything.
+		 */
+		*line = '\0';
+	} else if (specType == SP_SHELL) {
+		if (!Job_ParseShell(line)) {
+			Parse_Error(PARSE_FATAL,
+			"improper shell specification");
+			return;
+		}
+		*line = '\0';
+	} else if (specType == SP_NOTPARALLEL || specType == SP_SINGLESHELL ||
+		   specType == SP_DELETE_ON_ERROR) {
+		*line = '\0';
+	}
+
+	/* Now go for the sources. */
+	if (specType == SP_SUFFIXES || specType == SP_PATH ||
+	specType == SP_INCLUDES || specType == SP_LIBS ||
+	specType == SP_NULL || specType == SP_OBJDIR) {
+		ParseDependencySourcesSpecial(line, cp, specType,
+		*inout_paths);
+		if (*inout_paths != NULL) {
+			Lst_Free(*inout_paths);
+			*inout_paths = NULL;
+		}
+		if (specType == SP_PATH)
+			Dir_SetPATH();
+	} else {
+		assert(*inout_paths == NULL);
+		if (!ParseDependencySourcesMundane(line, cp, specType, tOp))
+			return;
+	}
+
+	FindMainTarget();
+}
+
 /*
  * Parse a dependency line consisting of targets, followed by a dependency
  * operator, optionally followed by sources.
@@ -1665,55 +1723,7 @@ ParseDependency(char *line)
 	pp_skip_whitespace(&cp);
 	line = cp;		/* XXX: 'line' is an inappropriate name */
 
-	/*
-	 * Several special targets take different actions if present with no
-	 * sources:
-	 *	a .SUFFIXES line with no sources clears out all old suffixes
-	 *	a .PRECIOUS line makes all targets precious
-	 *	a .IGNORE line ignores errors for all targets
-	 *	a .SILENT line creates silence when making all targets
-	 *	a .PATH removes all directories from the search path(s).
-	 */
-	if (line[0] == '\0') {
-		ParseDependencySourcesEmpty(specType, paths);
-	} else if (specType == SP_MFLAGS) {
-		/*
-		 * Call on functions in main.c to deal with these arguments and
-		 * set the initial character to a null-character so the loop to
-		 * get sources won't get anything
-		 */
-		Main_ParseArgLine(line);
-		*line = '\0';
-	} else if (specType == SP_SHELL) {
-		if (!Job_ParseShell(line)) {
-			Parse_Error(PARSE_FATAL,
-			"improper shell specification");
-			goto out;
-		}
-		*line = '\0';
-	} else if (specType == SP_NOTPARALLEL || specType == SP_SINGLESHELL ||
-		   specType == SP_DELETE_ON_ERROR) {
-		*line = '\0';
-	}
-
-	/* Now go for the sources. */
-	if (specType == SP_SUFFIXES || specType == SP_PATH ||
-	specType == SP_INCLUDES || specType == SP_LIBS ||
-	specType == SP_NULL || specType == SP_OBJDIR) {
-		ParseDependencySourcesSpecial(line, cp, specType, paths);
-		if (paths != NULL) {
-			Lst_Free(paths);
-			paths = NULL;
-		}
-		if (specType == SP_PATH)
-			Dir_SetPATH();
-	} else {
-		assert(paths == NULL);
-		if (!ParseDependencySourcesMundane(line, cp, specType, tOp))
-			goto out;
-	}
-
-	FindMainTarget();
+	ParseDependen

CVS commit: src/usr.bin/make

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 08:40:44 UTC 2021

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

Log Message:
make: fix documentation for ParseModifierPart


To generate a diff of this commit:
cvs rdiff -u -r1.933 -r1.934 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.933 src/usr.bin/make/var.c:1.934
--- src/usr.bin/make/var.c:1.933	Mon Jun 21 04:24:17 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 08:40:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.933 2021/06/21 04:24:17 sjg Exp $	*/
+/*	$NetBSD: var.c,v 1.934 2021/06/21 08:40:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.933 2021/06/21 04:24:17 sjg Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.934 2021/06/21 08:40:44 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2135,7 +2135,7 @@ IsEscapedModifierPart(const char *p, cha
 	return p[1] == '&' && subst != NULL;
 }
 
-/* See ParseModifierPart */
+/* See ParseModifierPart for the documentation. */
 static VarParseResult
 ParseModifierPartSubst(
 const char **pp,
@@ -2143,8 +2143,8 @@ ParseModifierPartSubst(
 VarEvalMode emode,
 ModChain *ch,
 LazyBuf *part,
-/* For the first part of the :S modifier, sets the VARP_ANCHOR_END flag
- * if the last character of the pattern is a $. */
+/* For the first part of the modifier ':S', set anchorEnd if the last
+ * character of the pattern is a $. */
 PatternFlags *out_pflags,
 /* For the second part of the :S modifier, allow ampersands to be
  * escaped and replace unescaped ampersands with subst->lhs. */
@@ -2265,10 +2265,9 @@ ParseModifierPartSubst(
  * including the next unescaped delimiter.  The delimiter, as well as the
  * backslash or the dollar, can be escaped with a backslash.
  *
- * Return the parsed (and possibly expanded) string, or NULL if no delimiter
- * was found.  On successful return, the parsing position pp points right
- * after the delimiter.  The delimiter is not included in the returned
- * value though.
+ * Return VPR_OK if parsing succeeded, together with the parsed (and possibly
+ * expanded) part.  In that case, pp points right after the delimiter.  The
+ * delimiter is not included in the part though.
  */
 static VarParseResult
 ParseModifierPart(



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

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 08:28:37 UTC 2021

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

Log Message:
tests/make: remove unnecessary -dL from moderrs.mk

It was only needed for the test for unmatched subexpressions in the
modifier ':C'.  That test has been moved to varmod-subst-regex.mk.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/make/unit-tests/moderrs.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/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.31 src/usr.bin/make/unit-tests/moderrs.exp:1.32
--- src/usr.bin/make/unit-tests/moderrs.exp:1.31	Mon Jun 21 08:17:39 2021
+++ src/usr.bin/make/unit-tests/moderrs.exp	Mon Jun 21 08:28:37 2021
@@ -134,4 +134,4 @@ make: Unclosed variable expression, expe
 
 1 1 2 x3 5 8 1x3 21 34
 
-exit status 2
+exit status 0

Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.29 src/usr.bin/make/unit-tests/moderrs.mk:1.30
--- src/usr.bin/make/unit-tests/moderrs.mk:1.29	Mon Jun 21 08:17:39 2021
+++ src/usr.bin/make/unit-tests/moderrs.mk	Mon Jun 21 08:28:37 2021
@@ -1,10 +1,7 @@
-# $NetBSD: moderrs.mk,v 1.29 2021/06/21 08:17:39 rillig Exp $
+# $NetBSD: moderrs.mk,v 1.30 2021/06/21 08:28:37 rillig Exp $
 #
 # various modifier error tests
 
-# report unmatched subexpressions
-.MAKEFLAGS: -dL
-
 '=		'\''
 VAR=		TheVariable
 # in case we have to change it ;-)



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

2021-06-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jun 21 08:17:39 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: moderrs.exp moderrs.mk
varmod-subst-regex.exp varmod-subst-regex.mk

Log Message:
tests/make: move and extend test for unmatched '\1' in ':C'

This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/unit-tests/moderrs.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-subst-regex.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-subst-regex.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/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.30 src/usr.bin/make/unit-tests/moderrs.exp:1.31
--- src/usr.bin/make/unit-tests/moderrs.exp:1.30	Mon Jun 21 04:24:17 2021
+++ src/usr.bin/make/unit-tests/moderrs.exp	Mon Jun 21 08:17:39 2021
@@ -86,15 +86,6 @@ make: Unclosed variable expression, expe
 6: TheVariable
 7: TheVariable
 
-mod-regex-undefined-subexpression:
-one one 2 3 5 8 one3 2one 34
-make: No match for subexpression \2
-make: No match for subexpression \2
-make: No match for subexpression \1
-make: No match for subexpression \2
-make: No match for subexpression \1
-()+() ()+() ()+() 3 5 8 (3)+() ()+(1) 34
-
 mod-ts-parse:
 112358132134
 15152535558513521534

Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.28 src/usr.bin/make/unit-tests/moderrs.mk:1.29
--- src/usr.bin/make/unit-tests/moderrs.mk:1.28	Mon Jun 21 04:24:17 2021
+++ src/usr.bin/make/unit-tests/moderrs.mk	Mon Jun 21 08:17:39 2021
@@ -1,4 +1,4 @@
-# $NetBSD: moderrs.mk,v 1.28 2021/06/21 04:24:17 sjg Exp $
+# $NetBSD: moderrs.mk,v 1.29 2021/06/21 08:17:39 rillig Exp $
 #
 # various modifier error tests
 
@@ -22,7 +22,6 @@ all:	words
 all:	exclam
 all:	mod-subst-delimiter
 all:	mod-regex-delimiter
-all:	mod-regex-undefined-subexpression
 all:	mod-ts-parse
 all:	mod-t-parse
 all:	mod-ifelse-parse
@@ -122,23 +121,6 @@ mod-regex-delimiter: print-header print-
 	@echo 6: ${VAR:C,from,to,
 	@echo 7: ${VAR:C,from,to,}
 
-# In regular expressions with alternatives, not all capturing groups are
-# always set; some may be missing.  Warn about these.
-#
-# Since there is no way to turn off this warning, the combination of
-# alternative matches and capturing groups is seldom used, if at all.
-#
-# A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
-# for treating undefined capturing groups as empty, but that would create a
-# syntactical ambiguity since the :S and :C modifiers are open-ended (see
-# mod-subst-chain).  Luckily the modifier :U does not make sense after :C,
-# therefore this case does not happen in practice.
-# The sub-modifier for the :S and :C modifiers would have to be chosen
-# wisely, to not create ambiguities while parsing.
-mod-regex-undefined-subexpression: print-header print-footer
-	@echo ${FIB:C,1(.*),one\1,}		# all ok
-	@echo ${FIB:C,1(.*)|2(.*),(\1)+(\2),:Q}	# no match for subexpression
-
 mod-ts-parse: print-header print-footer
 	@echo ${FIB:ts}
 	@echo ${FIB:ts\65}	# octal 065 == U+0035 == '5'

Index: src/usr.bin/make/unit-tests/varmod-subst-regex.exp
diff -u src/usr.bin/make/unit-tests/varmod-subst-regex.exp:1.5 src/usr.bin/make/unit-tests/varmod-subst-regex.exp:1.6
--- src/usr.bin/make/unit-tests/varmod-subst-regex.exp:1.5	Tue Feb 23 15:19:41 2021
+++ src/usr.bin/make/unit-tests/varmod-subst-regex.exp	Mon Jun 21 08:17:39 2021
@@ -22,4 +22,25 @@ make: Regex compilation error: (details 
 mod-regex-errors:
 make: Unknown modifier "Z"
 mod-regex-errors: xy
-exit status 0
+unmatched-subexpression.ok: one one 2 3 5 8 one3 2one 34
+make: No match for subexpression \2
+unmatched-subexpression.1: ()()
+make: No match for subexpression \2
+unmatched-subexpression.1: ()()
+make: No match for subexpression \1
+unmatched-subexpression.2: ()()
+unmatched-subexpression.3: 3
+unmatched-subexpression.5: 5
+unmatched-subexpression.8: 8
+make: No match for subexpression \2
+unmatched-subexpression.13: (3)()
+make: No match for subexpression \1
+unmatched-subexpression.21: ()(1)
+unmatched-subexpression.34: 34
+make: No match for subexpression \2
+make: No match for subexpression \2
+make: No match for subexpression \1
+make: No match for subexpression \2
+make: No match for subexpression \1
+unmatched-subexpression.all: ()() ()() ()() 3 5 8 (3)() ()(1) 34
+exit status 2

Index: src/usr.bin/make/unit-tests/varmod-subst-regex.mk
diff -u src/usr.bin/make/unit-tests/varmod-subst-regex.mk:1.6 src/usr.bin/make/unit-tests/varmod-subst-regex.mk:1.7
--- src/usr.bin

CVS commit: src/usr.bin/make

2021-06-20 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Mon Jun 21 04:24:17 UTC 2021

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

Log Message:
Do not report unmatched regex subexpressions

It is not always an error for a subexpression to have not matched,
since the regex library can/does not convey how many matches are
expected, only report an error if opts.strict (-dL)

Reviewed by: christos


To generate a diff of this commit:
cvs rdiff -u -r1.932 -r1.933 src/usr.bin/make/var.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/make/unit-tests/moderrs.mk

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.932 src/usr.bin/make/var.c:1.933
--- src/usr.bin/make/var.c:1.932	Sun May 30 20:41:34 2021
+++ src/usr.bin/make/var.c	Mon Jun 21 04:24:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.933 2021/06/21 04:24:17 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.933 2021/06/21 04:24:17 sjg Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1651,9 +1651,11 @@ tryagain:
 	Error("No subexpression \\%u",
 	(unsigned)n);
 } else if (m[n].rm_so == -1) {
-	Error(
-	"No match for subexpression \\%u",
-	(unsigned)n);
+	if (opts.strict) {
+		Error(
+		"No match for subexpression \\%u",
+			(unsigned)n);
+	}
 } else {
 	SepBuf_AddBytesBetween(buf,
 	wp + m[n].rm_so, wp + m[n].rm_eo);

Index: src/usr.bin/make/unit-tests/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.29 src/usr.bin/make/unit-tests/moderrs.exp:1.30
--- src/usr.bin/make/unit-tests/moderrs.exp:1.29	Tue Feb 23 16:07:14 2021
+++ src/usr.bin/make/unit-tests/moderrs.exp	Mon Jun 21 04:24:17 2021
@@ -143,4 +143,4 @@ make: Unclosed variable expression, expe
 
 1 1 2 x3 5 8 1x3 21 34
 
-exit status 0
+exit status 2

Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.27 src/usr.bin/make/unit-tests/moderrs.mk:1.28
--- src/usr.bin/make/unit-tests/moderrs.mk:1.27	Tue Feb 23 16:04:16 2021
+++ src/usr.bin/make/unit-tests/moderrs.mk	Mon Jun 21 04:24:17 2021
@@ -1,7 +1,10 @@
-# $NetBSD: moderrs.mk,v 1.27 2021/02/23 16:04:16 rillig Exp $
+# $NetBSD: moderrs.mk,v 1.28 2021/06/21 04:24:17 sjg Exp $
 #
 # various modifier error tests
 
+# report unmatched subexpressions
+.MAKEFLAGS: -dL
+
 '=		'\''
 VAR=		TheVariable
 # in case we have to change it ;-)



CVS commit: src/usr.bin/make

2021-06-18 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 18 12:54:17 UTC 2021

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

Log Message:
make: clean up access to character iterator

Having both p[0] and *p intermixed was inconsistent.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.539 -r1.540 src/usr.bin/make/main.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/main.c
diff -u src/usr.bin/make/main.c:1.539 src/usr.bin/make/main.c:1.540
--- src/usr.bin/make/main.c:1.539	Mon Apr 19 16:35:11 2021
+++ src/usr.bin/make/main.c	Fri Jun 18 12:54:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.539 2021/04/19 16:35:11 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.540 2021/06/18 12:54:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.539 2021/04/19 16:35:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.540 2021/06/18 12:54:17 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -349,16 +349,16 @@ debug_setbuf:
 static bool
 IsRelativePath(const char *path)
 {
-	const char *cp;
+	const char *p;
 
 	if (path[0] != '/')
 		return true;
-	cp = path;
-	while ((cp = strstr(cp, "/.")) != NULL) {
-		cp += 2;
-		if (*cp == '.')
-			cp++;
-		if (cp[0] == '/' || cp[0] == '\0')
+	p = path;
+	while ((p = strstr(p, "/.")) != NULL) {
+		p += 2;
+		if (*p == '.')
+			p++;
+		if (*p == '/' || *p == '\0')
 			return true;
 	}
 	return false;



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

2021-06-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jun 17 15:25:34 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: deptgt-order.exp deptgt-order.mk

Log Message:
tests/make: add test for circular dependency in .ORDER


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/deptgt-order.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/deptgt-order.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/deptgt-order.exp
diff -u src/usr.bin/make/unit-tests/deptgt-order.exp:1.1 src/usr.bin/make/unit-tests/deptgt-order.exp:1.2
--- src/usr.bin/make/unit-tests/deptgt-order.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/deptgt-order.exp	Thu Jun 17 15:25:33 2021
@@ -1 +1,4 @@
+: 'Making two out of one.'
+: 'Making three out of two.'
+: 'Making all out of three.'
 exit status 0

Index: src/usr.bin/make/unit-tests/deptgt-order.mk
diff -u src/usr.bin/make/unit-tests/deptgt-order.mk:1.2 src/usr.bin/make/unit-tests/deptgt-order.mk:1.3
--- src/usr.bin/make/unit-tests/deptgt-order.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/deptgt-order.mk	Thu Jun 17 15:25:33 2021
@@ -1,8 +1,18 @@
-# $NetBSD: deptgt-order.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: deptgt-order.mk,v 1.3 2021/06/17 15:25:33 rillig Exp $
 #
 # Tests for the special target .ORDER in dependency declarations.
 
-# TODO: Implementation
+all one two three: .PHONY
 
-all:
-	@:;
+two: one
+	: 'Making $@ out of $>.'
+three: two
+	: 'Making $@ out of $>.'
+
+# This .ORDER creates a circular dependency since 'three' depends on 'one'
+# but 'one' is supposed to be built after 'three'.
+.ORDER: three one
+
+# XXX: The circular dependency should be detected here.
+all: three
+	: 'Making $@ out of $>.'



CVS commit: src/usr.bin/make

2021-06-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jun 16 09:47:51 UTC 2021

Modified Files:
src/usr.bin/make: job.c
src/usr.bin/make/unit-tests: jobs-empty-commands-error.exp

Log Message:
make: fix error handling in jobs mode

By using the same error handling code as in the branch for non-empty
commands, the behavior is the same again as before 2021-01-29.


To generate a diff of this commit:
cvs rdiff -u -r1.434 -r1.435 src/usr.bin/make/job.c
cvs rdiff -u -r1.1 -r1.2 \
src/usr.bin/make/unit-tests/jobs-empty-commands-error.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/job.c
diff -u src/usr.bin/make/job.c:1.434 src/usr.bin/make/job.c:1.435
--- src/usr.bin/make/job.c:1.434	Wed Jun 16 03:56:59 2021
+++ src/usr.bin/make/job.c	Wed Jun 16 09:47:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.434 2021/06/16 03:56:59 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.434 2021/06/16 03:56:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.435 2021/06/16 09:47:51 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1663,6 +1663,15 @@ JobStart(GNode *gn, bool special)
 	if (Lst_IsEmpty(&gn->commands)) {
 		job->cmdFILE = stdout;
 		run = false;
+
+		/*
+		 * We're serious here, but if the commands were bogus, we're
+		 * also dead...
+		 */
+		if (!cmdsOK) {
+			PrintOnError(gn, NULL); /* provide some clue */
+			DieHorribly();
+		}
 	} else if (((gn->type & OP_MAKE) && !opts.noRecursiveExecute) ||
 	(!opts.noExecute && !opts.touchFlag)) {
 		/*

Index: src/usr.bin/make/unit-tests/jobs-empty-commands-error.exp
diff -u src/usr.bin/make/unit-tests/jobs-empty-commands-error.exp:1.1 src/usr.bin/make/unit-tests/jobs-empty-commands-error.exp:1.2
--- src/usr.bin/make/unit-tests/jobs-empty-commands-error.exp:1.1	Wed Jun 16 09:39:48 2021
+++ src/usr.bin/make/unit-tests/jobs-empty-commands-error.exp	Wed Jun 16 09:47:51 2021
@@ -1,4 +1,5 @@
 : 'Making existing-target out of nothing.'
 make: don't know how to make nonexistent-target (continuing)
-`nonexistent-target' was not built (being made, type OP_DEPS_FOUND|OP_MARK, flags REMAKE|DONE_WAIT|DONE_ALLSRC|DONECYCLE)!
-exit status 1
+
+make: stopped in unit-tests
+exit status 2



CVS commit: src/usr.bin/make

2021-06-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jun 16 03:56:59 UTC 2021

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

Log Message:
make: extract commands-ok check from JobWriteShellCommands

This piece of code did not match the function name and thus could not
reasonably be expected in that function.

In job.c 1.399 from 2021-01-29 I missed exactly this little detail when
I added code to skip the apparently unnecessary creation of empty shell
files.  The code I added only handled the happy case, not the case where
the target could not be made.

That code path then differed, leading to a much more verbose error
message than before.

before:
don't know how to make ../missing/no-such.o. Stop

after:
don't know how to make ../missing/no-such.o. Stop
...
`../missing/no-such.o' was not built (made BEINGMADE, ...)!
`muck' was not built (made DEFERRED, type OP_DEPENDS|...)!
`muck' has .ORDER dependency against build-all (made DEFERRED, ...)

Thanks to sjg for finding and reproducing this unintended change of
behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.433 -r1.434 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.433 src/usr.bin/make/job.c:1.434
--- src/usr.bin/make/job.c:1.433	Wed Jun 16 03:15:47 2021
+++ src/usr.bin/make/job.c	Wed Jun 16 03:56:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.433 2021/06/16 03:15:47 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.434 2021/06/16 03:56:59 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.433 2021/06/16 03:15:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.434 2021/06/16 03:56:59 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1585,7 +1585,7 @@ JobMakeArgv(Job *job, char **argv)
 }
 
 static void
-JobWriteShellCommands(Job *job, GNode *gn, bool cmdsOK, bool *out_run)
+JobWriteShellCommands(Job *job, GNode *gn, bool *out_run)
 {
 	/*
 	 * tfile is the name of a file into which all shell commands
@@ -1595,15 +1595,6 @@ JobWriteShellCommands(Job *job, GNode *g
 	char tfile[MAXPATHLEN];
 	int tfd;		/* File descriptor to the temp file */
 
-	/*
-	 * We're serious here, but if the commands were bogus, we're
-	 * also dead...
-	 */
-	if (!cmdsOK) {
-		PrintOnError(gn, NULL); /* provide some clue */
-		DieHorribly();
-	}
-
 	tfd = Job_TempFile(TMPPAT, tfile, sizeof tfile);
 
 	job->cmdFILE = fdopen(tfd, "w+");
@@ -1681,7 +1672,16 @@ JobStart(GNode *gn, bool special)
 		 * virtual targets.
 		 */
 
-		JobWriteShellCommands(job, gn, cmdsOK, &run);
+		/*
+		 * We're serious here, but if the commands were bogus, we're
+		 * also dead...
+		 */
+		if (!cmdsOK) {
+			PrintOnError(gn, NULL); /* provide some clue */
+			DieHorribly();
+		}
+
+		JobWriteShellCommands(job, gn, &run);
 		(void)fflush(job->cmdFILE);
 	} else if (!GNode_ShouldExecute(gn)) {
 		/*



CVS commit: src/usr.bin/make

2021-06-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jun 16 03:15:47 UTC 2021

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

Log Message:
make: clean up comment for JobStart

The parameter 'flags' was renamed in job.c 1.354 from 2020-12-10 without
adjusting the documentation.

The parameter 'previous' was removed in job.c 1.108 from 2006-03-12,
also without adjusting the documentation of JobStart.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.432 -r1.433 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.432 src/usr.bin/make/job.c:1.433
--- src/usr.bin/make/job.c:1.432	Tue Apr 27 16:25:46 2021
+++ src/usr.bin/make/job.c	Wed Jun 16 03:15:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.432 2021/04/27 16:25:46 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.433 2021/06/16 03:15:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.432 2021/04/27 16:25:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.433 2021/06/16 03:15:47 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1624,20 +1624,14 @@ JobWriteShellCommands(Job *job, GNode *g
 }
 
 /*
- * Start a target-creation process going for the target described by the
- * graph node gn.
- *
- * Input:
- *	gn		target to create
- *	flags		flags for the job to override normal ones.
- *	previous	The previous Job structure for this node, if any.
+ * Start a target-creation process going for the target described by gn.
  *
  * Results:
  *	JOB_ERROR if there was an error in the commands, JOB_FINISHED
  *	if there isn't actually anything left to do for the job and
  *	JOB_RUNNING if the job has been started.
  *
- * Side Effects:
+ * Details:
  *	A new Job node is created and added to the list of running
  *	jobs. PMake is forked and a child shell created.
  *



CVS commit: src/usr.bin/make

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 14:52:03 UTC 2021

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

Log Message:
make: inline strcmp when parsing conditions

GCC 10 does not do that even though it could easily.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.266 src/usr.bin/make/cond.c:1.267
--- src/usr.bin/make/cond.c:1.266	Fri Jun 11 14:42:52 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 14:52:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.267 2021/06/11 14:52:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.267 2021/06/11 14:52:03 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -400,7 +400,8 @@ TryParseNumber(const char *str, double *
 static bool
 is_separator(char ch)
 {
-	return ch == '\0' || ch_isspace(ch) || strchr("!=><)", ch) != NULL;
+	return ch == '\0' || ch_isspace(ch) || ch == '!' || ch == '=' ||
+	   ch == '>' || ch == '<' || ch == ')' /* but not '(' */;
 }
 
 /*



CVS commit: src/usr.bin/make

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 14:42:52 UTC 2021

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

Log Message:
make: clean up function names and documentation for conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.265 src/usr.bin/make/cond.c:1.266
--- src/usr.bin/make/cond.c:1.265	Fri Jun 11 14:37:51 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 14:42:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -467,12 +467,13 @@ CondParser_StringExpr(CondParser *par, c
 }
 
 /*
- * Parse a string from a variable reference or an optionally quoted
- * string.  This is called for the lhs and rhs of string comparisons.
+ * Parse a string from a variable expression or an optionally quoted
+ * string.  This is called for the left-hand and right-hand sides of
+ * comparisons.
  *
  * Results:
  *	Returns the string, absent any quotes, or NULL on error.
- *	Sets out_quoted if the string was quoted.
+ *	Sets out_quoted if the leaf was a quoted string literal.
  */
 static void
 CondParser_Leaf(CondParser *par, bool doEval, bool strictLHS,
@@ -540,7 +541,7 @@ CondParser_Leaf(CondParser *par, bool do
 got_str:
 	str = FStr_InitOwn(buf.data);
 cleanup:
-	Buf_DoneData(&buf);
+	Buf_DoneData(&buf);	/* XXX: memory leak on failure? */
 	*out_str = str;
 }
 
@@ -824,11 +825,11 @@ CondParser_FuncCall(CondParser *par, boo
 }
 
 /*
- * Parse a function call, a number, a variable expression or a string
- * literal.
+ * Parse a comparison such as '${VAR} == "value"', or a simple leaf without
+ * operator, which is a number, a variable expression or a string literal.
  */
 static Token
-CondParser_LeafToken(CondParser *par, bool doEval)
+CondParser_ComparisonOrLeaf(CondParser *par, bool doEval)
 {
 	Token t;
 	char *arg = NULL;
@@ -849,6 +850,10 @@ CondParser_LeafToken(CondParser *par, bo
 	 * syntax would be invalid if we did "defined(a)" - so instead treat
 	 * as an expression.
 	 */
+	/*
+	 * XXX: Is it possible to have a variable expression evaluated twice
+	 *  at this point?
+	 */
 	arglen = ParseFuncArg(par, &cp, doEval, NULL, &arg);
 	cp1 = cp;
 	cpp_skip_whitespace(&cp1);
@@ -930,7 +935,7 @@ CondParser_Token(CondParser *par, bool d
 	default:
 		if (CondParser_FuncCall(par, doEval, &t))
 			return t;
-		return CondParser_LeafToken(par, doEval);
+		return CondParser_ComparisonOrLeaf(par, doEval);
 	}
 }
 



CVS commit: src/usr.bin/make

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 14:37:51 UTC 2021

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

Log Message:
make: rename If_Eval to EvalBare

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.264 -r1.265 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.264 src/usr.bin/make/cond.c:1.265
--- src/usr.bin/make/cond.c:1.264	Fri Jun 11 13:09:10 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 14:37:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.264 2021/06/11 13:09:10 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.264 2021/06/11 13:09:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -545,7 +545,7 @@ cleanup:
 }
 
 static bool
-If_Eval(const CondParser *par, const char *arg, size_t arglen)
+EvalBare(const CondParser *par, const char *arg, size_t arglen)
 {
 	bool res = par->evalBare(arglen, arg);
 	return par->negateEvalBare ? !res : res;
@@ -575,7 +575,7 @@ EvalNotEmpty(CondParser *par, const char
 	if (par->plain)
 		return value[0] != '\0';
 
-	return If_Eval(par, value, strlen(value));
+	return EvalBare(par, value, strlen(value));
 }
 
 /* Evaluate a numerical comparison, such as in ".if ${VAR} >= 9". */
@@ -862,7 +862,7 @@ CondParser_LeafToken(CondParser *par, bo
 	 * after .if must have been taken literally, so the argument cannot
 	 * be empty - even if it contained a variable expansion.
 	 */
-	t = ToToken(!doEval || If_Eval(par, arg, arglen));
+	t = ToToken(!doEval || EvalBare(par, arg, arglen));
 	free(arg);
 	return t;
 }



CVS commit: src/usr.bin/make

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 13:09:11 UTC 2021

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

Log Message:
make: move parsing of function calls out of CondParser_LeafToken

The grammar above the parsing code says that a Leaf has nothing to do
with function calls, so don't mix these in the actual code.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.263 -r1.264 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.263 src/usr.bin/make/cond.c:1.264
--- src/usr.bin/make/cond.c:1.263	Fri Jun 11 12:23:00 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 13:09:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.263 2021/06/11 12:23:00 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.264 2021/06/11 13:09:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.263 2021/06/11 12:23:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.264 2021/06/11 13:09:10 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -836,9 +836,6 @@ CondParser_LeafToken(CondParser *par, bo
 	const char *cp;
 	const char *cp1;
 
-	if (CondParser_FuncCall(par, doEval, &t))
-		return t;
-
 	/* Push anything numeric through the compare expression */
 	cp = par->p;
 	if (ch_isdigit(cp[0]) || cp[0] == '-' || cp[0] == '+')
@@ -931,6 +928,8 @@ CondParser_Token(CondParser *par, bool d
 		return CondParser_Comparison(par, doEval);
 
 	default:
+		if (CondParser_FuncCall(par, doEval, &t))
+			return t;
 		return CondParser_LeafToken(par, doEval);
 	}
 }



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

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 13:01:28 UTC 2021

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

Log Message:
tests/make: demonstrate handling of '+' and '*' in modifier ':?'

It doesn't make sense that these two characters are handled differently,
but that's what the current code has been doing for years.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varmod-ifelse.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-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.10 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.11
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.10	Mon Apr 19 23:51:42 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Fri Jun 11 13:01:28 2021
@@ -23,6 +23,10 @@ make: Bad conditional expression 'string
 make: "varmod-ifelse.mk" line 159: .
 make: Bad conditional expression 'string == "literal" ||  >= 10' in 'string == "literal" ||  >= 10?yes:no'
 make: "varmod-ifelse.mk" line 160: .
+make: "varmod-ifelse.mk" line 167: true
+make: "varmod-ifelse.mk" line 169: false
+make: Bad conditional expression '	' in '	?true:false'
+make: "varmod-ifelse.mk" line 171: 
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.16 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.17
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.16	Mon Apr 19 23:51:42 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Fri Jun 11 13:01:28 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.16 2021/04/19 23:51:42 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.17 2021/06/11 13:01:28 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -158,3 +158,14 @@ NUMBER=		no		# not really a number
 NUMBER=		# empty, not really a number either
 .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
 .info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.
+
+# CondParser_LeafToken handles [0-9-+] specially, treating them as a number.
+PLUS=		+
+ASTERISK=	*
+EMPTY=		# empty
+# "true" since "+" is not the empty string.
+.info ${${PLUS}		:?true:false}
+# "false" since the variable named "*" is not defined.
+.info ${${ASTERISK}	:?true:false}
+# syntax error since the condition is completely blank.
+.info ${${EMPTY}	:?true:false}



CVS commit: src/usr.bin/make

2021-06-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 11 12:23:00 UTC 2021

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

Log Message:
make: improve function names for parsing conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/make/cond.c

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

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.262 src/usr.bin/make/cond.c:1.263
--- src/usr.bin/make/cond.c:1.262	Mon Apr 19 23:51:42 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 12:23:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.263 2021/06/11 12:23:00 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.263 2021/06/11 12:23:00 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -475,7 +475,7 @@ CondParser_StringExpr(CondParser *par, c
  *	Sets out_quoted if the string was quoted.
  */
 static void
-CondParser_String(CondParser *par, bool doEval, bool strictLHS,
+CondParser_Leaf(CondParser *par, bool doEval, bool strictLHS,
 		  FStr *out_str, bool *out_quoted)
 {
 	Buffer buf;
@@ -684,7 +684,7 @@ CondParser_Comparison(CondParser *par, b
 	 * Parse the variable spec and skip over it, saving its
 	 * value in lhs.
 	 */
-	CondParser_String(par, doEval, lhsStrict, &lhs, &lhsQuoted);
+	CondParser_Leaf(par, doEval, lhsStrict, &lhs, &lhsQuoted);
 	if (lhs.str == NULL)
 		goto done_lhs;
 
@@ -705,7 +705,7 @@ CondParser_Comparison(CondParser *par, b
 		goto done_lhs;
 	}
 
-	CondParser_String(par, doEval, false, &rhs, &rhsQuoted);
+	CondParser_Leaf(par, doEval, false, &rhs, &rhsQuoted);
 	if (rhs.str == NULL)
 		goto done_rhs;
 
@@ -773,8 +773,9 @@ FuncEmpty(size_t arglen, const char *arg
 	return arglen == 1;
 }
 
+/* Parse a function call expression, such as 'defined(${file})'. */
 static bool
-CondParser_Func(CondParser *par, bool doEval, Token *out_token)
+CondParser_FuncCall(CondParser *par, bool doEval, Token *out_token)
 {
 	static const struct fn_def {
 		const char *fn_name;
@@ -835,7 +836,7 @@ CondParser_LeafToken(CondParser *par, bo
 	const char *cp;
 	const char *cp1;
 
-	if (CondParser_Func(par, doEval, &t))
+	if (CondParser_FuncCall(par, doEval, &t))
 		return t;
 
 	/* Push anything numeric through the compare expression */



CVS commit: src/usr.bin/make

2021-05-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 30 21:16:54 UTC 2021

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

Log Message:
make: inline str_concat4

This function is only ever used for forming strings of the form
"archive(member)".

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 src/usr.bin/make/arch.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/make/str.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/str.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/arch.c
diff -u src/usr.bin/make/arch.c:1.199 src/usr.bin/make/arch.c:1.200
--- src/usr.bin/make/arch.c:1.199	Sat Apr  3 11:08:40 2021
+++ src/usr.bin/make/arch.c	Sun May 30 21:16:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.199 2021/04/03 11:08:40 rillig Exp $	*/
+/*	$NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #include "config.h"
 
 /*	"@(#)arch.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: arch.c,v 1.199 2021/04/03 11:08:40 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -148,6 +148,7 @@ static FILE *ArchFindMember(const char *
 static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
 #endif
 
+
 #ifdef CLEANUP
 static void
 ArchFree(void *ap)
@@ -167,6 +168,19 @@ ArchFree(void *ap)
 }
 #endif
 
+/* Return "archive(member)". */
+static char *
+FullName(const char *archive, const char *member)
+{
+	size_t len1 = strlen(archive);
+	size_t len3 = strlen(member);
+	char *result = bmake_malloc(len1 + 1 + len3 + 1 + 1);
+	memcpy(result, archive, len1);
+	memcpy(result + len1, "(", 1);
+	memcpy(result + len1 + 1, member, len3);
+	memcpy(result + len1 + 1 + len3, ")", 1 + 1);
+	return result;
+}
 
 /*
  * Parse an archive specification such as "archive.a(member1 member2.${EXT})",
@@ -312,7 +326,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 			 * Now form an archive spec and recurse to deal with
 			 * nested variables and multi-word variable values.
 			 */
-			fullName = str_concat4(libName.str, "(", memName, ")");
+			fullName = FullName(libName.str, memName);
 			p = fullName;
 
 			if (strchr(memName, '$') != NULL &&
@@ -342,8 +356,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 
 			while (!Lst_IsEmpty(&members)) {
 char *member = Lst_Dequeue(&members);
-char *fullname = str_concat4(libName.str, "(",
-			 member, ")");
+char *fullname = FullName(libName.str, member);
 free(member);
 
 gn = Targ_GetNode(fullname);
@@ -355,8 +368,7 @@ Arch_ParseArchive(char **pp, GNodeList *
 			Lst_Done(&members);
 
 		} else {
-			char *fullname = str_concat4(libName.str, "(", memName,
-		 ")");
+			char *fullname = FullName(libName.str, memName);
 			gn = Targ_GetNode(fullname);
 			free(fullname);
 

Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.84 src/usr.bin/make/str.c:1.85
--- src/usr.bin/make/str.c:1.84	Sun Apr 11 19:05:06 2021
+++ src/usr.bin/make/str.c	Sun May 30 21:16:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.84 2021/04/11 19:05:06 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.85 2021/05/30 21:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.84 2021/04/11 19:05:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.85 2021/05/30 21:16:54 rillig Exp $");
 
 /* Return the concatenation of s1 and s2, freshly allocated. */
 char *
@@ -99,22 +99,6 @@ str_concat3(const char *s1, const char *
 	return result;
 }
 
-/* Return the concatenation of s1, s2, s3 and s4, freshly allocated. */
-char *
-str_concat4(const char *s1, const char *s2, const char *s3, const char *s4)
-{
-	size_t len1 = strlen(s1);
-	size_t len2 = strlen(s2);
-	size_t len3 = strlen(s3);
-	size_t len4 = strlen(s4);
-	char *result = bmake_malloc(len1 + len2 + len3 + len4 + 1);
-	memcpy(result, s1, len1);
-	memcpy(result + len1, s2, len2);
-	memcpy(result + len1 + len2, s3, len3);
-	memcpy(result + len1 + len2 + len3, s4, len4 + 1);
-	return result;
-}
-
 /*
  * Fracture a string into an array of words (as delineated by tabs or spaces)
  * taking quotation marks into account.

Index: src/usr.bin/make/str.h
diff -u src/usr.bin/make/str.h:1.8 src/usr.bin/make/str.h:1.9
--- src/usr.bin/make/str.h:1.8	Wed Apr 14 17:39:11 2021
+++ src/usr.bin/make/str.h	Sun May 30 21:16:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.8 2021/04/14 17:39:11 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.9 2021/05/30 21:16:54 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -362,6 +362,5 @@ SubstringWords_Free(SubstringWords w)
 
 char *str_concat2(const char *, const char *);
 char *str_concat3(const char *, const char *, const char *);
-char *str_concat4(const char *, cons

CVS commit: src/usr.bin/make

2021-05-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 30 21:03:09 UTC 2021

Modified Files:
src/usr.bin/make: Makefile

Log Message:
make: fix reported code coverage for *.h

In 'make test-coverage', the number of uncovered lines for inline
functions in headers was reported too high.  The cause for this is that
gcov reports the coverage for these functions multiple times, once per
translation unit.  If some of the translation units don't use these
inline functions, summing the lines containing '#' quickly leads to
numbers that are obviously too high.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/make/Makefile

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/Makefile
diff -u src/usr.bin/make/Makefile:1.114 src/usr.bin/make/Makefile:1.115
--- src/usr.bin/make/Makefile:1.114	Sun Apr 11 11:41:27 2021
+++ src/usr.bin/make/Makefile	Sun May 30 21:03:08 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.114 2021/04/11 11:41:27 rillig Exp $
+#	$NetBSD: Makefile,v 1.115 2021/05/30 21:03:08 rillig Exp $
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 
 PROG=	make
@@ -35,8 +35,11 @@ GCOV_PERL+=	} elsif (/^Function '(\S+)'/
 GCOV_PERL+=		$$func = $$1;
 GCOV_PERL+=	} elsif (/^Lines executed:(\d+\.\d+)% of (\d+)/ && defined($$file)) {
 GCOV_PERL+=		my ($$percent, $$lines) = ($$1, $$2);
-GCOV_PERL+=		my $$uncovered = `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`;
-GCOV_PERL+=		printf("%7.2f  %4d/%4d  %s%s\n",
+GCOV_PERL+=		my $$uncovered = $$file =~ /\.h$$/
+GCOV_PERL+=		? '?'
+GCOV_PERL+=		: `grep -c '\#\#\#\#\#:' < \$$(basename $$file.gcov)`;
+GCOV_PERL+=		chomp($$uncovered);
+GCOV_PERL+=		printf("%7.2f  %4s/%4d  %s%s\n",
 GCOV_PERL+=		$$percent, $$uncovered, $$lines, $$file, $$func);
 GCOV_PERL+=		$$file = undef;
 GCOV_PERL+=	}



CVS commit: src/usr.bin/make

2021-05-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 30 20:41:34 UTC 2021

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

Log Message:
make: uncompress code in ApplyModifier_Unique

The algorithm is easier to understand when each line of code only
focuses on a single topic.

No change to the resulting binary, except for line numbers in assertion
messages.


To generate a diff of this commit:
cvs rdiff -u -r1.931 -r1.932 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.931 src/usr.bin/make/var.c:1.932
--- src/usr.bin/make/var.c:1.931	Sun May 30 20:31:03 2021
+++ src/usr.bin/make/var.c	Sun May 30 20:41:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.932 2021/05/30 20:41:34 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3559,12 +3559,17 @@ ApplyModifier_Unique(const char **pp, Mo
 	words = Str_Words(ch->expr->value.str, false);
 
 	if (words.len > 1) {
-		size_t i, j;
-		for (j = 0, i = 1; i < words.len; i++)
-			if (strcmp(words.words[i], words.words[j]) != 0 &&
-			(++j != i))
-words.words[j] = words.words[i];
-		words.len = j + 1;
+		size_t si, di;
+
+		di = 0;
+		for (si = 1; si < words.len; si++) {
+			if (strcmp(words.words[si], words.words[di]) != 0) {
+di++;
+if (di != si)
+	words.words[di] = words.words[si];
+			}
+		}
+		words.len = di + 1;
 	}
 
 	Expr_SetValueOwn(ch->expr, Words_JoinFree(words));



CVS commit: src/usr.bin/make

2021-05-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 30 20:31:03 UTC 2021

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

Log Message:
make: inline VarUniq into ApplyModifier_Unique

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.930 -r1.931 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.930 src/usr.bin/make/var.c:1.931
--- src/usr.bin/make/var.c:1.930	Mon Apr 19 22:22:27 2021
+++ src/usr.bin/make/var.c	Sun May 30 20:31:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.930 2021/04/19 22:22:27 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.930 2021/04/19 22:22:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.931 2021/05/30 20:31:03 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1824,24 +1824,6 @@ Words_JoinFree(Words words)
 	return Buf_DoneData(&buf);
 }
 
-/* Remove adjacent duplicate words. */
-static char *
-VarUniq(const char *str)
-{
-	Words words = Str_Words(str, false);
-
-	if (words.len > 1) {
-		size_t i, j;
-		for (j = 0, i = 1; i < words.len; i++)
-			if (strcmp(words.words[i], words.words[j]) != 0 &&
-			(++j != i))
-words.words[j] = words.words[i];
-		words.len = j + 1;
-	}
-
-	return Words_JoinFree(words);
-}
-
 
 /*
  * Quote shell meta-characters and space characters in the string.
@@ -3561,15 +3543,31 @@ ApplyModifier_WordFunc(const char **pp, 
 	return AMR_OK;
 }
 
+/* Remove adjacent duplicate words. */
 static ApplyModifierResult
 ApplyModifier_Unique(const char **pp, ModChain *ch)
 {
+	Words words;
+
 	if (!IsDelimiter((*pp)[1], ch))
 		return AMR_UNKNOWN;
 	(*pp)++;
 
-	if (ModChain_ShouldEval(ch))
-		Expr_SetValueOwn(ch->expr, VarUniq(ch->expr->value.str));
+	if (!ModChain_ShouldEval(ch))
+		return AMR_OK;
+
+	words = Str_Words(ch->expr->value.str, false);
+
+	if (words.len > 1) {
+		size_t i, j;
+		for (j = 0, i = 1; i < words.len; i++)
+			if (strcmp(words.words[i], words.words[j]) != 0 &&
+			(++j != i))
+words.words[j] = words.words[i];
+		words.len = j + 1;
+	}
+
+	Expr_SetValueOwn(ch->expr, Words_JoinFree(words));
 
 	return AMR_OK;
 }



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

2021-05-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 30 20:26:42 UTC 2021

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

Log Message:
tests/make: test whitespace normalization for modifier ':u'


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-unique.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-unique.mk
diff -u src/usr.bin/make/unit-tests/varmod-unique.mk:1.4 src/usr.bin/make/unit-tests/varmod-unique.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-unique.mk:1.4	Mon Aug 31 17:41:38 2020
+++ src/usr.bin/make/unit-tests/varmod-unique.mk	Sun May 30 20:26:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-unique.mk,v 1.4 2020/08/31 17:41:38 rillig Exp $
+# $NetBSD: varmod-unique.mk,v 1.5 2021/05/30 20:26:41 rillig Exp $
 #
 # Tests for the :u variable modifier, which discards adjacent duplicate
 # words.
@@ -15,10 +15,18 @@
 .  warning The :u modifier must do nothing with an empty word list.
 .endif
 
-.if ${:U1:u} != "1"
+.if ${:U   :u} != ""
+.  warning The modifier ':u' must normalize the whitespace.
+.endif
+
+.if ${:Uword:u} != "word"
 .  warning The :u modifier must do nothing with a single-element word list.
 .endif
 
+.if ${:U   word   :u} != "word"
+.  warning The modifier ':u' must normalize the whitespace.
+.endif
+
 .if ${:U1 1 1 1 1 1 1 1:u} != "1"
 .  warning The :u modifier must merge _all_ adjacent duplicate words.
 .endif



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

2021-05-18 Thread Simon J. Gerraty
Module Name:src
Committed By:   sjg
Date:   Tue May 18 17:05:45 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: Makefile opt-chdir.mk

Log Message:
Do not trust that /nonexistent does not exist

Use /nonexistent.${.MAKE.PID} to avoid failure when
/nonexistent actually exists.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/opt-chdir.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/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.277 src/usr.bin/make/unit-tests/Makefile:1.278
--- src/usr.bin/make/unit-tests/Makefile:1.277	Tue Apr 27 16:20:06 2021
+++ src/usr.bin/make/unit-tests/Makefile	Tue May 18 17:05:45 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.277 2021/04/27 16:20:06 rillig Exp $
+# $NetBSD: Makefile,v 1.278 2021/05/18 17:05:45 sjg Exp $
 #
 # Unit tests for make(1)
 #
@@ -487,6 +487,7 @@ SED_CMDS.job-output-long-lines= \
 	${:D marker should always be at the beginning of the line. } \
 	-e '/^aa*--- job-b ---$$/d' \
 	-e '/^bb*--- job-a ---$$/d'
+SED_CMDS.opt-chdir=		-e 's,\(nonexistent\).[1-9][0-9]*,\1,'
 SED_CMDS.opt-debug-graph1=	${STD_SED_CMDS.dg1}
 SED_CMDS.opt-debug-graph2=	${STD_SED_CMDS.dg2}
 SED_CMDS.opt-debug-graph3=	${STD_SED_CMDS.dg3}

Index: src/usr.bin/make/unit-tests/opt-chdir.mk
diff -u src/usr.bin/make/unit-tests/opt-chdir.mk:1.5 src/usr.bin/make/unit-tests/opt-chdir.mk:1.6
--- src/usr.bin/make/unit-tests/opt-chdir.mk:1.5	Sun Nov 15 05:43:56 2020
+++ src/usr.bin/make/unit-tests/opt-chdir.mk	Tue May 18 17:05:45 2021
@@ -1,4 +1,4 @@
-# $NetBSD: opt-chdir.mk,v 1.5 2020/11/15 05:43:56 sjg Exp $
+# $NetBSD: opt-chdir.mk,v 1.6 2021/05/18 17:05:45 sjg Exp $
 #
 # Tests for the -C command line option, which changes the directory at the
 # beginning.
@@ -23,5 +23,7 @@ chdir-root: .PHONY .IGNORE
 	@MAKE_OBJDIR_CHECK_WRITABLE=no ${MAKE} -C / -V 'cwd: $${.CURDIR}'
 
 # Trying to change to a nonexistent directory exits immediately.
+# Note: just because the whole point of /nonexistent is that it should
+# not exist - doesn't mean it doesn't.
 chdir-nonexistent: .PHONY .IGNORE
-	@${MAKE} -C /nonexistent
+	@${MAKE} -C /nonexistent.${.MAKE.PID}



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

2021-05-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 14 19:37:16 UTC 2021

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

Log Message:
tests/make: show that in ':S', '.' and '*' are ordinary characters


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod-subst.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-subst.mk
diff -u src/usr.bin/make/unit-tests/varmod-subst.mk:1.7 src/usr.bin/make/unit-tests/varmod-subst.mk:1.8
--- src/usr.bin/make/unit-tests/varmod-subst.mk:1.7	Sun Nov 15 20:20:58 2020
+++ src/usr.bin/make/unit-tests/varmod-subst.mk	Fri May 14 19:37:16 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-subst.mk,v 1.7 2020/11/15 20:20:58 rillig Exp $
+# $NetBSD: varmod-subst.mk,v 1.8 2021/05/14 19:37:16 rillig Exp $
 #
 # Tests for the :S,from,to, variable modifier.
 
@@ -78,6 +78,14 @@ WORDS=		sequences of letters
 .  warning The :S modifier matches a too long suffix anchored at both ends.
 .endif
 
+.if ${WORDS:S,*,replacement,} != ${WORDS}
+.  error The '*' seems to be interpreted as a wildcard of some kind.
+.endif
+
+.if ${WORDS:S,.,replacement,} != ${WORDS}
+.  error The '.' seems to be interpreted as a wildcard of some kind.
+.endif
+
 mod-subst:
 	@echo $@:
 	@echo :${:Ua b b c:S,a b,,:Q}:



CVS commit: src/usr.bin/make

2021-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr 27 16:25:47 UTC 2021

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

Log Message:
make: use consistent variable names, types and braces in DebugFailedJob

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.431 -r1.432 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.431 src/usr.bin/make/job.c:1.432
--- src/usr.bin/make/job.c:1.431	Tue Apr 27 16:23:21 2021
+++ src/usr.bin/make/job.c	Tue Apr 27 16:25:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.431 2021/04/27 16:23:21 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.432 2021/04/27 16:25:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.431 2021/04/27 16:23:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.432 2021/04/27 16:25:46 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1063,16 +1063,15 @@ JobClosePipes(Job *job)
 static void
 DebugFailedJob(const Job *job)
 {
-	const ListNode *l;
+	const StringListNode *ln;
 
 	if (!DEBUG(ERROR))
 		return;
 
 	debug_printf("\n*** Failed target: %s\n*** Failed commands:\n",
 	job->node->name);
-	for (l = job->node->commands.first; l != NULL; l = l->next) {
-		debug_printf("\t%s\n", (const char *)l->datum);
-	}
+	for (ln = job->node->commands.first; ln != NULL; ln = ln->next)
+		debug_printf("\t%s\n", (const char *)ln->datum);
 }
 
 static void



CVS commit: src/usr.bin/make

2021-04-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Apr 27 16:23:21 UTC 2021

Modified Files:
src/usr.bin/make: job.c
src/usr.bin/make/unit-tests: opt-debug-errors-jobs.exp

Log Message:
make: remove stray space in -de output in jobs mode

In compat mode, having a space in this place makes sense to align the
target name with the command.  In jobs mode, since each command is
listed in a separate line, there is no need for the double space.


To generate a diff of this commit:
cvs rdiff -u -r1.430 -r1.431 src/usr.bin/make/job.c
cvs rdiff -u -r1.1 -r1.2 \
src/usr.bin/make/unit-tests/opt-debug-errors-jobs.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/job.c
diff -u src/usr.bin/make/job.c:1.430 src/usr.bin/make/job.c:1.431
--- src/usr.bin/make/job.c:1.430	Tue Apr 27 15:21:42 2021
+++ src/usr.bin/make/job.c	Tue Apr 27 16:23:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.430 2021/04/27 15:21:42 christos Exp $	*/
+/*	$NetBSD: job.c,v 1.431 2021/04/27 16:23:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.430 2021/04/27 15:21:42 christos Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.431 2021/04/27 16:23:21 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1068,7 +1068,7 @@ DebugFailedJob(const Job *job)
 	if (!DEBUG(ERROR))
 		return;
 
-	debug_printf("\n*** Failed target:  %s\n*** Failed commands:\n",
+	debug_printf("\n*** Failed target: %s\n*** Failed commands:\n",
 	job->node->name);
 	for (l = job->node->commands.first; l != NULL; l = l->next) {
 		debug_printf("\t%s\n", (const char *)l->datum);

Index: src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.1 src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.2
--- src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp:1.1	Tue Apr 27 16:20:06 2021
+++ src/usr.bin/make/unit-tests/opt-debug-errors-jobs.exp	Tue Apr 27 16:23:21 2021
@@ -1,7 +1,7 @@
 echo '3   spaces'; false
 3   spaces
 
-*** Failed target:  fail-spaces
+*** Failed target: fail-spaces
 *** Failed commands:
 	echo '3   spaces'; false
 *** [fail-spaces] Error code 1
@@ -10,7 +10,7 @@ make: stopped in unit-tests
 echo \  indented; false
   indented
 
-*** Failed target:  fail-escaped-space
+*** Failed target: fail-escaped-space
 *** Failed commands:
 	echo \  indented; false
 *** [fail-escaped-space] Error code 1
@@ -21,7 +21,7 @@ line2'; false
 line1
 line2
 
-*** Failed target:  fail-newline
+*** Failed target: fail-newline
 *** Failed commands:
 	echo 'line1${.newline}line2'; false
 *** [fail-newline] Error code 1
@@ -30,7 +30,7 @@ make: stopped in unit-tests
 echo 'line1 line2'; false
 line1 line2
 
-*** Failed target:  fail-multiline
+*** Failed target: fail-multiline
 *** Failed commands:
 	echo 'line1 line2'; false
 *** [fail-multiline] Error code 1
@@ -39,7 +39,7 @@ make: stopped in unit-tests
 echo	'word1'			 'word2'; false
 word1 word2
 
-*** Failed target:  fail-multiline-intention
+*** Failed target: fail-multiline-intention
 *** Failed commands:
 	echo	'word1'			 'word2'; false
 *** [fail-multiline-intention] Error code 1



CVS commit: src/usr.bin/make

2021-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 27 15:21:42 UTC 2021

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

Log Message:
Print -de error information when running multiple jobs

Problem and patch description from https://reviews.freebsd.org/D29647:

When running `make -de` (without any -j flag) bmake prints which command
failed. However, when using the -j flag the -de flag is ignored. This can
make it rather difficult to determine which command failed in an very
parallel build (especially when combined with the -s flag to avoid
ridiculously large logfiles). For single-threaded builds we can combine
-s with -de to get the failed command but this does not work with -jN
(even with -j1). This patch prints the failed shell script with -de in the
multiple jobs mode as well.

>From Alexander Richardson @ FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.429 -r1.430 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.429 src/usr.bin/make/job.c:1.430
--- src/usr.bin/make/job.c:1.429	Fri Apr 16 12:49:27 2021
+++ src/usr.bin/make/job.c	Tue Apr 27 11:21:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.429 2021/04/16 16:49:27 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.430 2021/04/27 15:21:42 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.429 2021/04/16 16:49:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.430 2021/04/27 15:21:42 christos Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1061,6 +1061,21 @@ JobClosePipes(Job *job)
 }
 
 static void
+DebugFailedJob(const Job *job)
+{
+	const ListNode *l;
+
+	if (!DEBUG(ERROR))
+		return;
+
+	debug_printf("\n*** Failed target:  %s\n*** Failed commands:\n",
+	job->node->name);
+	for (l = job->node->commands.first; l != NULL; l = l->next) {
+		debug_printf("\t%s\n", (const char *)l->datum);
+	}
+}
+
+static void
 JobFinishDoneExitedError(Job *job, int *inout_status)
 {
 	SwitchOutputTo(job->node);
@@ -1071,6 +1086,7 @@ JobFinishDoneExitedError(Job *job, int *
 	}
 #endif
 	if (!shouldDieQuietly(job->node, -1)) {
+		DebugFailedJob(job);
 		(void)printf("*** [%s] Error code %d%s\n",
 		job->node->name, WEXITSTATUS(*inout_status),
 		job->ignerr ? " (ignored)" : "");
@@ -1103,6 +1119,7 @@ static void
 JobFinishDoneSignaled(Job *job, int status)
 {
 	SwitchOutputTo(job->node);
+	DebugFailedJob(job);
 	(void)printf("*** [%s] Signal %d\n", job->node->name, WTERMSIG(status));
 	if (deleteOnError)
 		JobDeleteTarget(job->node);



CVS commit: src/usr.bin/make

2021-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 27 15:19:26 UTC 2021

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

Log Message:
add const


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/make/compat.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/compat.c
diff -u src/usr.bin/make/compat.c:1.226 src/usr.bin/make/compat.c:1.227
--- src/usr.bin/make/compat.c:1.226	Sun Apr  4 06:05:08 2021
+++ src/usr.bin/make/compat.c	Tue Apr 27 11:19:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.226 2021/04/04 10:05:08 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.227 2021/04/27 15:19:25 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.226 2021/04/04 10:05:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.227 2021/04/27 15:19:25 christos Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -161,7 +161,7 @@ CompatInterrupt(int signo)
 }
 
 static void
-DebugFailedTarget(const char *cmd, GNode *gn)
+DebugFailedTarget(const char *cmd, const GNode *gn)
 {
 	const char *p = cmd;
 	debug_printf("\n*** Failed target:  %s\n*** Failed command: ",



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

2021-04-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 25 21:05:38 UTC 2021

Modified Files:
src/usr.bin/make/unit-tests: cond-token-var.mk

Log Message:
tests/make: add tests for ${...} without operator in conditions

These tests are already covered in cond-cmp-unary.mk, but my first guess
was to search for these tests in cond-token-var.mk, so keep them in both
tests.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-token-var.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/cond-token-var.mk
diff -u src/usr.bin/make/unit-tests/cond-token-var.mk:1.5 src/usr.bin/make/unit-tests/cond-token-var.mk:1.6
--- src/usr.bin/make/unit-tests/cond-token-var.mk:1.5	Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-token-var.mk	Sun Apr 25 21:05:38 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-var.mk,v 1.5 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $
 #
 # Tests for variable expressions in .if conditions.
 #
@@ -46,3 +46,24 @@ DEF=	defined
 # Since the expression is defined now, it doesn't generate any parse error.
 .if ${UNDEF:U}
 .endif
+
+# If the value of the variable expression is a number, it is compared against
+# zero.
+.if ${:U0}
+.  error
+.endif
+.if !${:U1}
+.  error
+.endif
+
+# If the value of the variable expression is not a number, any non-empty
+# value evaluates to true, even if there is only whitespace.
+.if ${:U}
+.  error
+.endif
+.if !${:U }
+.  error
+.endif
+.if !${:Uanything}
+.  error
+.endif



CVS commit: src/usr.bin/make

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 23:51:42 UTC 2021

Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: varmod-ifelse.exp varmod-ifelse.mk

Log Message:
make: do not complain when skipping the condition 'no >= 10'

Seen in external/bsd/tmux when building with Clang.  See
varmod-ifelse.mk for the detailed story.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/cond.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-ifelse.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/cond.c
diff -u src/usr.bin/make/cond.c:1.261 src/usr.bin/make/cond.c:1.262
--- src/usr.bin/make/cond.c:1.261	Sun Apr  4 11:56:43 2021
+++ src/usr.bin/make/cond.c	Mon Apr 19 23:51:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.261 2021/04/04 11:56:43 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.261 2021/04/04 11:56:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.262 2021/04/19 23:51:42 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -854,7 +854,7 @@ CondParser_LeafToken(CondParser *par, bo
 	arglen = ParseFuncArg(par, &cp, doEval, NULL, &arg);
 	cp1 = cp;
 	cpp_skip_whitespace(&cp1);
-	if (*cp1 == '=' || *cp1 == '!')
+	if (*cp1 == '=' || *cp1 == '!' || *cp1 == '<' || *cp1 == '>')
 		return CondParser_Comparison(par, doEval);
 	par->p = cp;
 

Index: src/usr.bin/make/unit-tests/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.9 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.10
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.9	Mon Apr 19 23:43:14 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 23:51:42 2021
@@ -15,8 +15,8 @@ CondParser_Eval: ${ ${:U\$}{VAR} == valu
 CondParser_Eval: ${VAR} == value 
 lhs = "value", rhs = "value", op = ==
 lhs = "ok", rhs = "ok", op = !=
-make: Bad conditional expression 'string == "literal" && no >= 10' in 'string == "literal" && no >= 10?yes:no'
-make: "varmod-ifelse.mk" line 153: .
+make: "varmod-ifelse.mk" line 153: no.
+make: "varmod-ifelse.mk" line 154: String comparison operator must be either == or !=
 make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
 make: "varmod-ifelse.mk" line 154: .
 make: Bad conditional expression 'string == "literal" &&  >= 10' in 'string == "literal" &&  >= 10?yes:no'

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.15 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.16
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.15	Mon Apr 19 23:43:14 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Mon Apr 19 23:51:42 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.15 2021/04/19 23:43:14 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.16 2021/04/19 23:51:42 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -140,14 +140,14 @@ VAR=	value
 # therefore parsing stopped at the '>', producing the 'Bad conditional
 # expression'.
 #
-# TODO: make should at least describe the part of the condition that is
-#  wrong. In this case it is probably the "no >= 10".  Ideally that should
-#  not matter though since the left-hand side of the '&&' evaluates to false,
-#  thus the right-hand side only needs to be parsed, not evaluated.  Since
-#  this is the modifier ':?', which expands subexpressions before parsing
-#  the condition, the "no >= 10" is probably a parse error since it "can be
-#  seen at compile-time" that the operand types of '>=' don't match.  Only
-#  that the concept of "compile-time" does not really apply here.
+# Ideally, the conditional expression would not be expanded before parsing
+# it.  This would allow to write the conditions exactly as seen below.  That
+# change has a high chance of breaking _some_ existing code and would need
+# to be thoroughly tested.
+#
+# Since cond.c 1.262 from 2021-04-20, make reports a more specific error
+# message in situations like these, pointing directly to the specific problem
+# instead of just saying that the whole condition is bad.
 STRING=		string
 NUMBER=		no		# not really a number
 .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.



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

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 23:43:15 UTC 2021

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

Log Message:
tests/make: add another example for parsing of the modifier ':?'


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod-ifelse.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-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.8 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.9
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.8	Mon Apr 19 23:27:17 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 23:43:14 2021
@@ -19,6 +19,10 @@ make: Bad conditional expression 'string
 make: "varmod-ifelse.mk" line 153: .
 make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
 make: "varmod-ifelse.mk" line 154: .
+make: Bad conditional expression 'string == "literal" &&  >= 10' in 'string == "literal" &&  >= 10?yes:no'
+make: "varmod-ifelse.mk" line 159: .
+make: Bad conditional expression 'string == "literal" ||  >= 10' in 'string == "literal" ||  >= 10?yes:no'
+make: "varmod-ifelse.mk" line 160: .
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.14 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.15
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.14	Mon Apr 19 23:27:17 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Mon Apr 19 23:43:14 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.14 2021/04/19 23:27:17 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.15 2021/04/19 23:43:14 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -152,3 +152,9 @@ STRING=		string
 NUMBER=		no		# not really a number
 .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
 .info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.
+
+# The following situation occasionally occurs with MKINET6 or similar
+# variables.
+NUMBER=		# empty, not really a number either
+.info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
+.info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.



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

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 23:27:17 UTC 2021

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

Log Message:
tests/make: add detailed explanation for error message in conditional


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmod-ifelse.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-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.7 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.8
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.7	Mon Apr 19 22:22:27 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 23:27:17 2021
@@ -16,7 +16,9 @@ CondParser_Eval: ${VAR} == value 
 lhs = "value", rhs = "value", op = ==
 lhs = "ok", rhs = "ok", op = !=
 make: Bad conditional expression 'string == "literal" && no >= 10' in 'string == "literal" && no >= 10?yes:no'
-make: "varmod-ifelse.mk" line 127: .
+make: "varmod-ifelse.mk" line 153: .
+make: Bad conditional expression 'string == "literal" || no >= 10' in 'string == "literal" || no >= 10?yes:no'
+make: "varmod-ifelse.mk" line 154: .
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.13 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.14
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.13	Mon Apr 19 22:22:27 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Mon Apr 19 23:27:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.13 2021/04/19 22:22:27 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.14 2021/04/19 23:27:17 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -111,8 +111,34 @@ VAR=	value
 .endif
 .MAKEFLAGS: -d0
 
-# Seen on 2021-04-19 when building external/bsd/tmux with HAVE_LLVM=yes
-# and HAVE_GCC=no.
+# On 2021-04-19, when building external/bsd/tmux with HAVE_LLVM=yes and
+# HAVE_GCC=no, the following conditional generated this error message:
+#
+#	make: Bad conditional expression 'string == "literal" && no >= 10'
+#	in 'string == "literal" && no >= 10?yes:no'
+#
+# Despite the error message (which was not clearly marked with "error:"),
+# the build continued, for historical reasons, see main_Exit.
+#
+# The tricky detail here is that the condition that looks so obvious in the
+# form written in the makefile becomes tricky when it is actually evaluated.
+# This is because the condition is written in the place of the variable name
+# of the expression, and in an expression, the variable name is always
+# expanded first, before even looking at the modifiers.  This happens for the
+# modifier ':?' as well, so when CondEvalExpression gets to see the
+# expression, it already looks like this:
+#
+#	string == "literal" && no >= 10
+#
+# When parsing such an expression, the parser used to be strict.  It first
+# evaluated the left-hand side of the operator '&&' and then started parsing
+# the right-hand side 'no >= 10'.  The word 'no' is obviously a string
+# literal, not enclosed in quotes, which is ok, even on the left-hand side of
+# the comparison operator, but only because this is a condition in the
+# modifier ':?'.  In an ordinary directive '.if', this would be a parse error.
+# For strings, only the comparison operators '==' and '!=' are defined,
+# therefore parsing stopped at the '>', producing the 'Bad conditional
+# expression'.
 #
 # TODO: make should at least describe the part of the condition that is
 #  wrong. In this case it is probably the "no >= 10".  Ideally that should
@@ -123,5 +149,6 @@ VAR=	value
 #  seen at compile-time" that the operand types of '>=' don't match.  Only
 #  that the concept of "compile-time" does not really apply here.
 STRING=		string
-NUMBER=		no
+NUMBER=		no		# not really a number
 .info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
+.info ${${STRING} == "literal" || ${NUMBER} >= 10:?yes:no}.



CVS commit: src/usr.bin/make

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 22:22:27 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: cond-late.exp cond1.exp varmod-ifelse.exp
varmod-ifelse.mk

Log Message:
make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected.  But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case.  I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.


To generate a diff of this commit:
cvs rdiff -u -r1.929 -r1.930 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-late.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond1.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-ifelse.mk

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

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.929 src/usr.bin/make/var.c:1.930
--- src/usr.bin/make/var.c:1.929	Wed Apr 14 16:59:34 2021
+++ src/usr.bin/make/var.c	Mon Apr 19 22:22:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.929 2021/04/14 16:59:34 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.930 2021/04/19 22:22:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.929 2021/04/14 16:59:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.930 2021/04/19 22:22:27 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3384,7 +3384,7 @@ ApplyModifier_IfElse(const char **pp, Mo
 	(*pp)--;		/* Go back to the ch->endc. */
 
 	if (cond_rc == COND_INVALID) {
-		Error("Bad conditional expression `%s' in %s?%s:%s",
+		Error("Bad conditional expression '%s' in '%s?%s:%s'",
 		expr->name, expr->name, then_expr.str, else_expr.str);
 		return AMR_CLEANUP;
 	}

Index: src/usr.bin/make/unit-tests/cond-late.exp
diff -u src/usr.bin/make/unit-tests/cond-late.exp:1.3 src/usr.bin/make/unit-tests/cond-late.exp:1.4
--- src/usr.bin/make/unit-tests/cond-late.exp:1.3	Sat Jul 25 20:37:46 2020
+++ src/usr.bin/make/unit-tests/cond-late.exp	Mon Apr 19 22:22:27 2021
@@ -1,4 +1,4 @@
-make: Bad conditional expression ` != "no"' in  != "no"?:
+make: Bad conditional expression ' != "no"' in ' != "no"?:'
 yes
 no
 exit status 0

Index: src/usr.bin/make/unit-tests/cond1.exp
diff -u src/usr.bin/make/unit-tests/cond1.exp:1.4 src/usr.bin/make/unit-tests/cond1.exp:1.5
--- src/usr.bin/make/unit-tests/cond1.exp:1.4	Thu Jan 21 23:32:28 2021
+++ src/usr.bin/make/unit-tests/cond1.exp	Mon Apr 19 22:22:27 2021
@@ -17,7 +17,7 @@ Passed:
 5 is  prime
 
 make: String comparison operator must be either == or !=
-make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
+make: Bad conditional expression '"0" > 0' in '"0" > 0?OK:No'
 
 OK
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.6 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.7
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.6	Mon Apr 19 22:05:29 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 22:22:27 2021
@@ -1,21 +1,21 @@
-make: Bad conditional expression `variable expression == "literal"' in variable expression == "literal"?bad:bad
+make: Bad conditional expression 'variable expression == "literal"' in 'variable expression == "literal"?bad:bad'
 make: "varmod-ifelse.mk" line 27: Malformed conditional (${${:Uvariable expression} == "literal":?bad:bad})
-make: Bad conditional expression ` == ""' in  == ""?bad-assign:bad-assign
-make: Bad conditional expression ` == ""' in  == ""?bad-cond:bad-cond
+make: Bad conditional expression ' == ""' in ' == ""?bad-assign:bad-assign'
+make: Bad conditional expression ' == ""' in ' == ""?bad-cond:bad-cond'
 make: "varmod-ifelse.mk" line 44: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond})
-make: Bad conditional expression `1 == == 2' in 1 == == 2?yes:no
+make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no'
 make: "varmod-ifelse.mk" line 66: Malformed conditional (${1 == == 2:?yes:no} != "")
 CondParser_Eval: "${1 == == 2:?yes:no}" != ""
 CondParser_Eval: 1 == == 2
 lhs = 1.00, rhs = 0.00, op = ==
-make: Bad conditional expression `1 == == 2' in 1 == == 2?yes:no
+make: Bad conditional expression '1 == == 2' in '1 == == 2?yes:no'
 lhs = "", rhs = "", op = !=
 m

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

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 22:05:29 UTC 2021

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

Log Message:
tests/make: demonstrate unexpected behavior of the modifier ':?'


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/varmod-ifelse.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-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.5 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.6
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.5	Thu Dec 10 16:36:47 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Mon Apr 19 22:05:29 2021
@@ -15,6 +15,8 @@ CondParser_Eval: ${ ${:U\$}{VAR} == valu
 CondParser_Eval: ${VAR} == value 
 lhs = "value", rhs = "value", op = ==
 lhs = "ok", rhs = "ok", op = !=
+make: Bad conditional expression `string == "literal" && no >= 10' in string == "literal" && no >= 10?yes:no
+make: "varmod-ifelse.mk" line 127: .
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.11 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.12
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.11	Sun Apr 11 13:35:56 2021
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Mon Apr 19 22:05:29 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.11 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.12 2021/04/19 22:05:29 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -111,5 +111,18 @@ VAR=	value
 .endif
 .MAKEFLAGS: -d0
 
-all:
-	@:;
+# Seen on 2021-04-19 when building external/bsd/tmux with HAVE_LLVM=yes
+# and HAVE_GCC=no.
+#
+# TODO: make should at least describe the part of the condition that is
+#  wrong. In this case it is probably the "no >= 10".  Ideally that should
+#  not matter though since the left-hand side of the '&&' evaluates to false,
+#  thus the right-hand side only needs to be parsed, not evaluated.  Since
+#  this is the modifier ':?', which expands subexpressions before parsing
+#  the condition, the "no >= 10" is probably a parse error since it "can be
+#  seen at compile-time" that the operand types of '>=' don't match.  Only
+#  that the concept of "compile-time" does not really apply here.
+STRING=		string
+NUMBER=		no
+.info ${${STRING} == "literal" && ${NUMBER} >= 10:?yes:no}.
+# XXX: In the diagnostic, the second placeholder is missing the quotes.



CVS commit: src/usr.bin/make

2021-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 19 16:35:11 UTC 2021

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

Log Message:
make: avoid double slash in name of temporary directory

If the environment variable TMPDIR is not set, make uses a default path
that includes a trailing '/'.

For extra correctness it always appended an extra '/', leading to paths
of the form '/tmp//makeXX'.  This looked suspicious, as if there had
been a forgotten empty part between the two '/'.  Avoid this ambiguity
by replacing '//' with '/'.


To generate a diff of this commit:
cvs rdiff -u -r1.538 -r1.539 src/usr.bin/make/main.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/main.c
diff -u src/usr.bin/make/main.c:1.538 src/usr.bin/make/main.c:1.539
--- src/usr.bin/make/main.c:1.538	Wed Apr 14 17:24:48 2021
+++ src/usr.bin/make/main.c	Mon Apr 19 16:35:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.538 2021/04/14 17:24:48 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.539 2021/04/19 16:35:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.538 2021/04/14 17:24:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.539 2021/04/19 16:35:11 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -2198,7 +2198,7 @@ getTmpdir(void)
 		return tmpdir;
 
 	/* Honor $TMPDIR but only if it is valid. Ensure it ends with '/'. */
-	(void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP "}/",
+	(void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/",
 	SCOPE_GLOBAL, VARE_WANTRES, &tmpdir);
 	/* TODO: handle errors */
 



CVS commit: src/usr.bin/make

2021-04-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 16 16:49:28 UTC 2021

Modified Files:
src/usr.bin/make: job.c
src/usr.bin/make/unit-tests: sh-jobs.mk

Log Message:
make: use distinct wording for writing to the shell commands file

The word 'write' now means to write to the file that holds the shell
commands to be run later.

The word 'print' is now used exclusively for handling the output of the
child commands and printing them to make's stdout.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.428 -r1.429 src/usr.bin/make/job.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/sh-jobs.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/job.c
diff -u src/usr.bin/make/job.c:1.428 src/usr.bin/make/job.c:1.429
--- src/usr.bin/make/job.c:1.428	Fri Apr 16 16:10:01 2021
+++ src/usr.bin/make/job.c	Fri Apr 16 16:49:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.428 2021/04/16 16:10:01 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.429 2021/04/16 16:49:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.428 2021/04/16 16:10:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.429 2021/04/16 16:49:27 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -223,8 +223,8 @@ typedef struct CommandFlags {
 	bool always;
 
 	/*
-	 * true if we turned error checking off before printing the command
-	 * and need to turn it back on
+	 * true if we turned error checking off before writing the command to
+	 * the commands file and need to turn it back on
 	 */
 	bool ignerr;
 } CommandFlags;
@@ -760,7 +760,7 @@ EscapeShellDblQuot(const char *cmd)
 }
 
 static void
-ShellWriter_PrintFmt(ShellWriter *wr, const char *fmt, const char *arg)
+ShellWriter_WriteFmt(ShellWriter *wr, const char *fmt, const char *arg)
 {
 	DEBUG1(JOB, fmt, arg);
 
@@ -770,36 +770,36 @@ ShellWriter_PrintFmt(ShellWriter *wr, co
 }
 
 static void
-ShellWriter_Println(ShellWriter *wr, const char *line)
+ShellWriter_WriteLine(ShellWriter *wr, const char *line)
 {
-	ShellWriter_PrintFmt(wr, "%s\n", line);
+	ShellWriter_WriteFmt(wr, "%s\n", line);
 }
 
 static void
 ShellWriter_EchoOff(ShellWriter *wr)
 {
 	if (shell->hasEchoCtl)
-		ShellWriter_Println(wr, shell->echoOff);
+		ShellWriter_WriteLine(wr, shell->echoOff);
 }
 
 static void
 ShellWriter_EchoCmd(ShellWriter *wr, const char *escCmd)
 {
-	ShellWriter_PrintFmt(wr, shell->echoTmpl, escCmd);
+	ShellWriter_WriteFmt(wr, shell->echoTmpl, escCmd);
 }
 
 static void
 ShellWriter_EchoOn(ShellWriter *wr)
 {
 	if (shell->hasEchoCtl)
-		ShellWriter_Println(wr, shell->echoOn);
+		ShellWriter_WriteLine(wr, shell->echoOn);
 }
 
 static void
 ShellWriter_TraceOn(ShellWriter *wr)
 {
 	if (!wr->xtraced) {
-		ShellWriter_Println(wr, "set -x");
+		ShellWriter_WriteLine(wr, "set -x");
 		wr->xtraced = true;
 	}
 }
@@ -809,7 +809,7 @@ ShellWriter_ErrOff(ShellWriter *wr, bool
 {
 	if (echo)
 		ShellWriter_EchoOff(wr);
-	ShellWriter_Println(wr, shell->errOff);
+	ShellWriter_WriteLine(wr, shell->errOff);
 	if (echo)
 		ShellWriter_EchoOn(wr);
 }
@@ -819,7 +819,7 @@ ShellWriter_ErrOn(ShellWriter *wr, bool 
 {
 	if (echo)
 		ShellWriter_EchoOff(wr);
-	ShellWriter_Println(wr, shell->errOn);
+	ShellWriter_WriteLine(wr, shell->errOn);
 	if (echo)
 		ShellWriter_EchoOn(wr);
 }
@@ -830,7 +830,7 @@ ShellWriter_ErrOn(ShellWriter *wr, bool 
  * (configurable per shell).
  */
 static void
-JobPrintSpecialsEchoCtl(Job *job, ShellWriter *wr, CommandFlags *inout_cmdFlags,
+JobWriteSpecialsEchoCtl(Job *job, ShellWriter *wr, CommandFlags *inout_cmdFlags,
 			const char *escCmd, const char **inout_cmdTemplate)
 {
 	/* XXX: Why is the job modified at this point? */
@@ -860,7 +860,7 @@ JobPrintSpecialsEchoCtl(Job *job, ShellW
 }
 
 static void
-JobPrintSpecials(Job *job, ShellWriter *wr, const char *escCmd, bool run,
+JobWriteSpecials(Job *job, ShellWriter *wr, const char *escCmd, bool run,
 		 CommandFlags *inout_cmdFlags, const char **inout_cmdTemplate)
 {
 	if (!run) {
@@ -872,34 +872,38 @@ JobPrintSpecials(Job *job, ShellWriter *
 	} else if (shell->hasErrCtl)
 		ShellWriter_ErrOff(wr, job->echo && inout_cmdFlags->echo);
 	else if (shell->runIgnTmpl != NULL && shell->runIgnTmpl[0] != '\0') {
-		JobPrintSpecialsEchoCtl(job, wr, inout_cmdFlags, escCmd,
+		JobWriteSpecialsEchoCtl(job, wr, inout_cmdFlags, escCmd,
 		inout_cmdTemplate);
 	} else
 		inout_cmdFlags->ignerr = false;
 }
 
 /*
- * Put out another command for the given job.
+ * Write a shell command to the job's commands file, to be run later.
  *
  * If the command starts with '@' and neither the -s nor the -n flag was
- * given to make, we stick a shell-specific echoOff command in the script.
+ * given to make,

CVS commit: src/usr.bin/make

2021-04-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 16 16:10:01 UTC 2021

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

Log Message:
make: align name of jobs_table_dump to the other functions


To generate a diff of this commit:
cvs rdiff -u -r1.427 -r1.428 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.427 src/usr.bin/make/job.c:1.428
--- src/usr.bin/make/job.c:1.427	Thu Apr 15 19:06:42 2021
+++ src/usr.bin/make/job.c	Fri Apr 16 16:10:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.427 2021/04/15 19:06:42 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.428 2021/04/16 16:10:01 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.427 2021/04/15 19:06:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.428 2021/04/16 16:10:01 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -478,7 +478,7 @@ Job_FlagsToString(const Job *job, char *
 }
 
 static void
-job_table_dump(const char *where)
+DumpJobs(const char *where)
 {
 	Job *job;
 	char flags[4];
@@ -710,7 +710,7 @@ JobFindPid(int pid, JobStatus status, bo
 			return job;
 	}
 	if (DEBUG(JOB) && isJobs)
-		job_table_dump("no pid");
+		DumpJobs("no pid");
 	return NULL;
 }
 
@@ -1514,7 +1514,7 @@ JobExec(Job *job, char **argv)
 	if (DEBUG(JOB)) {
 		debug_printf("JobExec(%s): pid %d added to jobs table\n",
 		job->node->name, job->pid);
-		job_table_dump("job started");
+		DumpJobs("job started");
 	}
 	JobSigUnlock(&mask);
 }



CVS commit: src/usr.bin/make

2021-04-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Apr 15 19:06:43 UTC 2021

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

Log Message:
make: remove type name for the abort status in job handling


To generate a diff of this commit:
cvs rdiff -u -r1.426 -r1.427 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.426 src/usr.bin/make/job.c:1.427
--- src/usr.bin/make/job.c:1.426	Thu Apr 15 18:36:17 2021
+++ src/usr.bin/make/job.c	Thu Apr 15 19:06:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.426 2021/04/15 18:36:17 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.427 2021/04/15 19:06:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.426 2021/04/15 18:36:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.427 2021/04/15 19:06:42 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -247,14 +247,12 @@ typedef struct ShellWriter {
  * error handling variables
  */
 static int job_errors = 0;	/* number of errors reported */
-typedef enum AbortReason {	/* why is the make aborting? */
+static enum {			/* Why is the make aborting? */
 	ABORT_NONE,
-	ABORT_ERROR,		/* Because of an error */
-	ABORT_INTERRUPT,	/* Because it was interrupted */
+	ABORT_ERROR,		/* Aborted because of an error */
+	ABORT_INTERRUPT,	/* Aborted because it was interrupted */
 	ABORT_WAIT		/* Waiting for jobs to finish */
-	/* XXX: "WAIT" is not a _reason_ for aborting, it's rather a status. */
-} AbortReason;
-static AbortReason aborting = ABORT_NONE;
+} aborting = ABORT_NONE;
 #define JOB_TOKENS "+EI+"	/* Token to requeue for each abort state */
 
 /*



CVS commit: src/usr.bin/make

2021-04-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Apr 15 18:36:17 UTC 2021

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

Log Message:
make: rename PrintOutput to PrintFilteredOutput to avoid confusion

In the default configuration, the function PrintOutput did nothing.
Only if the shell has defined an output filter, something happens at
all.


To generate a diff of this commit:
cvs rdiff -u -r1.425 -r1.426 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.425 src/usr.bin/make/job.c:1.426
--- src/usr.bin/make/job.c:1.425	Thu Apr 15 18:21:27 2021
+++ src/usr.bin/make/job.c	Thu Apr 15 18:36:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.425 2021/04/15 18:21:27 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.426 2021/04/15 18:36:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.425 2021/04/15 18:21:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.426 2021/04/15 18:36:17 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1724,12 +1724,15 @@ JobStart(GNode *gn, bool special)
 }
 
 /*
- * Print the output of the shell command, skipping the noPrint text of the
- * shell, if any.  The default shell does not have noPrint though, which means
- * that in all practical cases, handling the output is left to the caller.
+ * If the shell has an output filter (which only csh and ksh have by default),
+ * print the output of the child process, skipping the noPrint text of the
+ * shell.
+ *
+ * Return the part of the output that the calling function needs to output by
+ * itself.
  */
 static char *
-PrintOutput(char *cp, char *endp)	/* XXX: should all be const */
+PrintFilteredOutput(char *cp, char *endp)	/* XXX: should all be const */
 {
 	char *ecp;		/* XXX: should be const */
 
@@ -1835,8 +1838,8 @@ again:
 		} else if (job->outBuf[i] == '\0') {
 			/*
 			 * FIXME: The null characters are only replaced with
-			 * space in the last line.  Everywhere else they hide
-			 * the rest of the command output.
+			 * space _after_ the last '\n'.  Everywhere else they
+			 * hide the rest of the command output.
 			 */
 			job->outBuf[i] = ' ';
 		}
@@ -1874,10 +1877,10 @@ again:
 			 * do anything in the default shell, this bug has gone
 			 * unnoticed until now.
 			 */
-			cp = PrintOutput(job->outBuf, &job->outBuf[i]);
+			cp = PrintFilteredOutput(job->outBuf, &job->outBuf[i]);
 
 			/*
-			 * There's still more in that thar buffer. This time,
+			 * There's still more in the output buffer. This time,
 			 * though, we know there's no newline at the end, so
 			 * we add one of our own free will.
 			 */



CVS commit: src/usr.bin/make

2021-04-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Apr 15 18:21:27 UTC 2021

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

Log Message:
make: document two previously unknown bugs in job mode


To generate a diff of this commit:
cvs rdiff -u -r1.424 -r1.425 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.424 src/usr.bin/make/job.c:1.425
--- src/usr.bin/make/job.c:1.424	Sun Apr  4 10:05:08 2021
+++ src/usr.bin/make/job.c	Thu Apr 15 18:21:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.424 2021/04/04 10:05:08 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.425 2021/04/15 18:21:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.424 2021/04/04 10:05:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.425 2021/04/15 18:21:27 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1834,7 +1834,9 @@ again:
 			break;
 		} else if (job->outBuf[i] == '\0') {
 			/*
-			 * Why?
+			 * FIXME: The null characters are only replaced with
+			 * space in the last line.  Everywhere else they hide
+			 * the rest of the command output.
 			 */
 			job->outBuf[i] = ' ';
 		}
@@ -1866,6 +1868,12 @@ again:
 		if (i >= job->curPos) {
 			char *cp;
 
+			/*
+			 * FIXME: SwitchOutputTo should be here, according to
+			 * the comment above.  But since PrintOutput does not
+			 * do anything in the default shell, this bug has gone
+			 * unnoticed until now.
+			 */
 			cp = PrintOutput(job->outBuf, &job->outBuf[i]);
 
 			/*



CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 17:39:11 UTC 2021

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

Log Message:
make: let the compiler decide whether to inline string functions

On x86_64, this reduces the binary size by 2 kB.


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/make.h
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/str.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/make.h
diff -u src/usr.bin/make/make.h:1.261 src/usr.bin/make/make.h:1.262
--- src/usr.bin/make/make.h:1.261	Sun Apr 11 12:06:53 2021
+++ src/usr.bin/make/make.h	Wed Apr 14 17:39:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.261 2021/04/11 12:06:53 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.262 2021/04/14 17:39:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,6 +131,7 @@
 #endif
 
 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
+#define MAKE_STATIC static MAKE_ATTR_UNUSED
 
 #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
 #include 

Index: src/usr.bin/make/str.h
diff -u src/usr.bin/make/str.h:1.7 src/usr.bin/make/str.h:1.8
--- src/usr.bin/make/str.h:1.7	Wed Apr 14 16:59:34 2021
+++ src/usr.bin/make/str.h	Wed Apr 14 17:39:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.7 2021/04/14 16:59:34 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.8 2021/04/14 17:39:11 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -146,7 +146,7 @@ MFStr_Done(MFStr *mfstr)
 }
 
 
-MAKE_INLINE Substring
+MAKE_STATIC Substring
 Substring_Init(const char *start, const char *end)
 {
 	Substring sub;
@@ -162,13 +162,13 @@ Substring_InitStr(const char *str)
 	return Substring_Init(str, str + strlen(str));
 }
 
-MAKE_INLINE size_t
+MAKE_STATIC size_t
 Substring_Length(Substring sub)
 {
 	return (size_t)(sub.end - sub.start);
 }
 
-MAKE_INLINE bool
+MAKE_STATIC bool
 Substring_IsEmpty(Substring sub)
 {
 	return sub.start == sub.end;
@@ -182,7 +182,7 @@ Substring_Equals(Substring sub, const ch
 	   memcmp(sub.start, str, len) == 0;
 }
 
-MAKE_INLINE Substring
+MAKE_STATIC Substring
 Substring_Sub(Substring sub, size_t start, size_t end)
 {
 	assert(start <= Substring_Length(sub));
@@ -190,14 +190,14 @@ Substring_Sub(Substring sub, size_t star
 	return Substring_Init(sub.start + start, sub.start + end);
 }
 
-MAKE_INLINE bool
+MAKE_STATIC bool
 Substring_HasPrefix(Substring sub, Substring prefix)
 {
 	return Substring_Length(sub) >= Substring_Length(prefix) &&
 	   memcmp(sub.start, prefix.start, Substring_Length(prefix)) == 0;
 }
 
-MAKE_INLINE bool
+MAKE_STATIC bool
 Substring_HasSuffix(Substring sub, Substring suffix)
 {
 	size_t suffixLen = Substring_Length(suffix);
@@ -206,7 +206,7 @@ Substring_HasSuffix(Substring sub, Subst
 }
 
 /* Returns an independent, null-terminated copy of the substring. */
-MAKE_INLINE FStr
+MAKE_STATIC FStr
 Substring_Str(Substring sub)
 {
 	if (Substring_IsEmpty(sub))
@@ -214,7 +214,7 @@ Substring_Str(Substring sub)
 	return FStr_InitOwn(bmake_strsedup(sub.start, sub.end));
 }
 
-MAKE_INLINE const char *
+MAKE_STATIC const char *
 Substring_SkipFirst(Substring sub, char ch)
 {
 	const char *p;
@@ -225,7 +225,7 @@ Substring_SkipFirst(Substring sub, char 
 	return sub.start;
 }
 
-MAKE_INLINE const char *
+MAKE_STATIC const char *
 Substring_LastIndex(Substring sub, char ch)
 {
 	const char *p;
@@ -236,7 +236,7 @@ Substring_LastIndex(Substring sub, char 
 	return NULL;
 }
 
-MAKE_INLINE Substring
+MAKE_STATIC Substring
 Substring_Dirname(Substring pathname)
 {
 	const char *p;
@@ -247,7 +247,7 @@ Substring_Dirname(Substring pathname)
 	return Substring_InitStr(".");
 }
 
-MAKE_INLINE Substring
+MAKE_STATIC Substring
 Substring_Basename(Substring pathname)
 {
 	const char *p;
@@ -259,7 +259,7 @@ Substring_Basename(Substring pathname)
 }
 
 
-MAKE_INLINE void
+MAKE_STATIC void
 LazyBuf_Init(LazyBuf *buf, const char *expected)
 {
 	buf->data = NULL;
@@ -275,7 +275,7 @@ LazyBuf_Done(LazyBuf *buf)
 	free(buf->freeIt);
 }
 
-MAKE_INLINE void
+MAKE_STATIC void
 LazyBuf_Add(LazyBuf *buf, char ch)
 {
 
@@ -298,7 +298,7 @@ LazyBuf_Add(LazyBuf *buf, char ch)
 	}
 }
 
-MAKE_INLINE void
+MAKE_STATIC void
 LazyBuf_AddStr(LazyBuf *buf, const char *str)
 {
 	const char *p;
@@ -307,7 +307,7 @@ LazyBuf_AddStr(LazyBuf *buf, const char 
 		LazyBuf_Add(buf, *p);
 }
 
-MAKE_INLINE void
+MAKE_STATIC void
 LazyBuf_AddBytesBetween(LazyBuf *buf, const char *start, const char *end)
 {
 	const char *p;
@@ -322,14 +322,14 @@ LazyBuf_AddSubstring(LazyBuf *buf, Subst
 	LazyBuf_AddBytesBetween(buf, sub.start, sub.end);
 }
 
-MAKE_INLINE Substring
+MAKE_STATIC Substring
 LazyBuf_Get(const LazyBuf *buf)
 {
 	const char *start = buf->data != NULL ? buf->data : buf->expected;
 	return Substring_Init(start, start + buf->len);
 }
 
-MAKE_INLINE FStr
+MAKE_STATIC FStr
 LazyBuf_DoneGet(LazyBuf *buf)
 {
 	if (buf->data != NULL) {


CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 17:24:48 UTC 2021

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

Log Message:
make: turn run-time string concatenation into compile-time

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.537 -r1.538 src/usr.bin/make/main.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/main.c
diff -u src/usr.bin/make/main.c:1.537 src/usr.bin/make/main.c:1.538
--- src/usr.bin/make/main.c:1.537	Wed Apr 14 17:20:48 2021
+++ src/usr.bin/make/main.c	Wed Apr 14 17:24:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.537 2021/04/14 17:20:48 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.538 2021/04/14 17:24:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.537 2021/04/14 17:20:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.538 2021/04/14 17:24:48 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -869,9 +869,8 @@ PrintVar(const char *varname, bool expan
  * is false, otherwise true.
  */
 static bool
-GetBooleanVar(const char *varname, bool fallback)
+GetBooleanExpr(const char *expr, bool fallback)
 {
-	char *expr = str_concat3("${", varname, "}");
 	char *value;
 	bool res;
 
@@ -879,7 +878,6 @@ GetBooleanVar(const char *varname, bool 
 	/* TODO: handle errors */
 	res = ParseBoolean(value, fallback);
 	free(value);
-	free(expr);
 	return res;
 }
 
@@ -894,7 +892,8 @@ doPrintVars(void)
 	else if (opts.debugVflag)
 		expandVars = false;
 	else
-		expandVars = GetBooleanVar(".MAKE.EXPAND_VARIABLES", false);
+		expandVars = GetBooleanExpr("${.MAKE.EXPAND_VARIABLES}",
+		false);
 
 	for (ln = opts.variables.first; ln != NULL; ln = ln->next) {
 		const char *varname = ln->datum;
@@ -1086,7 +1085,7 @@ InitObjdir(const char *machine, const ch
 	bool writable;
 
 	Dir_InitCur(curdir);
-	writable = GetBooleanVar("MAKE_OBJDIR_CHECK_WRITABLE", true);
+	writable = GetBooleanExpr("${MAKE_OBJDIR_CHECK_WRITABLE}", true);
 	(void)Main_SetObjdir(false, "%s", curdir);
 
 	if (!SetVarObjdir(writable, "MAKEOBJDIRPREFIX", curdir) &&
@@ -2086,7 +2085,8 @@ shouldDieQuietly(GNode *gn, int bf)
 	static int quietly = -1;
 
 	if (quietly < 0) {
-		if (DEBUG(JOB) || !GetBooleanVar(".MAKE.DIE_QUIETLY", true))
+		if (DEBUG(JOB) ||
+		!GetBooleanExpr("${.MAKE.DIE_QUIETLY}", true))
 			quietly = 0;
 		else if (bf >= 0)
 			quietly = bf;



CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 17:20:48 UTC 2021

Modified Files:
src/usr.bin/make: main.c
src/usr.bin/make/unit-tests: varname-empty.exp

Log Message:
make: remove unnecessary modifier ':U' for certain fixed expressions

No functional change, since the expression is evaluated using
VARE_WANTRES, not using VARE_UNDEFERR.


To generate a diff of this commit:
cvs rdiff -u -r1.536 -r1.537 src/usr.bin/make/main.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varname-empty.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/main.c
diff -u src/usr.bin/make/main.c:1.536 src/usr.bin/make/main.c:1.537
--- src/usr.bin/make/main.c:1.536	Sun Apr  4 10:13:09 2021
+++ src/usr.bin/make/main.c	Wed Apr 14 17:20:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.536 2021/04/04 10:13:09 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.537 2021/04/14 17:20:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.536 2021/04/04 10:13:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.537 2021/04/14 17:20:48 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	"The Regents of the University of California.  "
@@ -871,7 +871,7 @@ PrintVar(const char *varname, bool expan
 static bool
 GetBooleanVar(const char *varname, bool fallback)
 {
-	char *expr = str_concat3("${", varname, ":U}");
+	char *expr = str_concat3("${", varname, "}");
 	char *value;
 	bool res;
 

Index: src/usr.bin/make/unit-tests/varname-empty.exp
diff -u src/usr.bin/make/unit-tests/varname-empty.exp:1.15 src/usr.bin/make/unit-tests/varname-empty.exp:1.16
--- src/usr.bin/make/unit-tests/varname-empty.exp:1.15	Sat Apr 10 22:35:02 2021
+++ src/usr.bin/make/unit-tests/varname-empty.exp	Wed Apr 14 17:20:48 2021
@@ -1,9 +1,7 @@
 Var_SetExpand: variable name "${:U}" expands to empty string, with value "cmdline-u" - ignored
 Var_SetExpand: variable name "" expands to empty string, with value "cmdline-plain" - ignored
 Global: .CURDIR = 
-Var_Parse: ${MAKE_OBJDIR_CHECK_WRITABLE:U} (eval)
-Evaluating modifier ${MAKE_OBJDIR_CHECK_WRITABLE:U} on value "" (eval, undefined)
-Result of ${MAKE_OBJDIR_CHECK_WRITABLE:U} is "" (eval, defined)
+Var_Parse: ${MAKE_OBJDIR_CHECK_WRITABLE} (eval)
 Global: .OBJDIR = 
 Global:delete .PATH (not found)
 Global: .PATH = .



CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 16:59:34 UTC 2021

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

Log Message:
make: reduce memory allocations in the modifiers ':D' and ':U'


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/str.h
cvs rdiff -u -r1.928 -r1.929 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/str.h
diff -u src/usr.bin/make/str.h:1.6 src/usr.bin/make/str.h:1.7
--- src/usr.bin/make/str.h:1.6	Mon Apr 12 18:48:00 2021
+++ src/usr.bin/make/str.h	Wed Apr 14 16:59:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.6 2021/04/12 18:48:00 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.7 2021/04/14 16:59:34 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -205,9 +205,12 @@ Substring_HasSuffix(Substring sub, Subst
 	   memcmp(sub.end - suffixLen, suffix.start, suffixLen) == 0;
 }
 
+/* Returns an independent, null-terminated copy of the substring. */
 MAKE_INLINE FStr
 Substring_Str(Substring sub)
 {
+	if (Substring_IsEmpty(sub))
+		return FStr_InitRefer("");
 	return FStr_InitOwn(bmake_strsedup(sub.start, sub.end));
 }
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.928 src/usr.bin/make/var.c:1.929
--- src/usr.bin/make/var.c:1.928	Wed Apr 14 16:12:26 2021
+++ src/usr.bin/make/var.c	Wed Apr 14 16:59:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.928 2021/04/14 16:12:26 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.929 2021/04/14 16:59:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.928 2021/04/14 16:12:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.929 2021/04/14 16:59:34 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2484,7 +2484,7 @@ static ApplyModifierResult
 ApplyModifier_Defined(const char **pp, ModChain *ch)
 {
 	Expr *expr = ch->expr;
-	Buffer buf;
+	LazyBuf buf;
 	const char *p;
 
 	VarEvalMode emode = VARE_PARSE_ONLY;
@@ -2492,8 +2492,8 @@ ApplyModifier_Defined(const char **pp, M
 		if ((**pp == 'D') == (expr->defined == DEF_REGULAR))
 			emode = expr->emode;
 
-	Buf_Init(&buf);
 	p = *pp + 1;
+	LazyBuf_Init(&buf, p);
 	while (!IsDelimiter(*p, ch) && *p != '\0') {
 
 		/* XXX: This code is similar to the one in Var_Parse.
@@ -2505,7 +2505,7 @@ ApplyModifier_Defined(const char **pp, M
 		if (*p == '\\') {
 			char c = p[1];
 			if (IsDelimiter(c, ch) || c == '$' || c == '\\') {
-Buf_AddByte(&buf, c);
+LazyBuf_Add(&buf, c);
 p += 2;
 continue;
 			}
@@ -2518,13 +2518,13 @@ ApplyModifier_Defined(const char **pp, M
 			(void)Var_Parse(&p, expr->scope, emode, &nested_val);
 			/* TODO: handle errors */
 			if (Expr_ShouldEval(expr))
-Buf_AddStr(&buf, nested_val.str);
+LazyBuf_AddStr(&buf, nested_val.str);
 			FStr_Done(&nested_val);
 			continue;
 		}
 
 		/* Ordinary text */
-		Buf_AddByte(&buf, *p);
+		LazyBuf_Add(&buf, *p);
 		p++;
 	}
 	*pp = p;
@@ -2532,9 +2532,9 @@ ApplyModifier_Defined(const char **pp, M
 	Expr_Define(expr);
 
 	if (VarEvalMode_ShouldEval(emode))
-		Expr_SetValueOwn(expr, Buf_DoneData(&buf));
+		Expr_SetValue(expr, Substring_Str(LazyBuf_Get(&buf)));
 	else
-		Buf_Done(&buf);
+		LazyBuf_Done(&buf);
 
 	return AMR_OK;
 }



CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 16:12:26 UTC 2021

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

Log Message:
make: rename members of ModifyWord_LoopArgs

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.927 -r1.928 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.927 src/usr.bin/make/var.c:1.928
--- src/usr.bin/make/var.c:1.927	Wed Apr 14 15:41:08 2021
+++ src/usr.bin/make/var.c	Wed Apr 14 16:12:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.927 2021/04/14 15:41:08 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.928 2021/04/14 16:12:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.927 2021/04/14 15:41:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.928 2021/04/14 16:12:26 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1688,8 +1688,8 @@ tryagain:
 
 struct ModifyWord_LoopArgs {
 	GNode *scope;
-	const char *tvar;	/* name of temporary variable */
-	const char *str;	/* string to expand */
+	const char *var;	/* name of the temporary variable */
+	const char *body;	/* string to expand */
 	VarEvalMode emode;
 };
 
@@ -1705,15 +1705,15 @@ ModifyWord_Loop(Substring word, SepBuf *
 
 	args = data;
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
-	Var_SetWithFlags(args->scope, args->tvar, word.start,
+	Var_SetWithFlags(args->scope, args->var, word.start,
 	VAR_SET_NO_EXPORT);
-	(void)Var_Subst(args->str, args->scope, args->emode, &s);
+	(void)Var_Subst(args->body, args->scope, args->emode, &s);
 	/* TODO: handle errors */
 
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
 	DEBUG4(VAR, "ModifyWord_Loop: "
 		"in \"%s\", replace \"%s\" with \"%s\" to \"%s\"\n",
-	word.start, args->tvar, args->str, s);
+	word.start, args->var, args->body, s);
 
 	if (s[0] == '\n' || Buf_EndsWith(&buf->buf, '\n'))
 		buf->needSep = false;
@@ -2447,12 +2447,12 @@ ApplyModifier_Loop(const char **pp, ModC
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	tvar = LazyBuf_DoneGet(&tvarBuf);
-	args.tvar = tvar.str;
-	if (strchr(args.tvar, '$') != NULL) {
+	args.var = tvar.str;
+	if (strchr(args.var, '$') != NULL) {
 		Parse_Error(PARSE_FATAL,
 		"In the :@ modifier of \"%s\", the variable name \"%s\" "
 		"must not contain a dollar.",
-		expr->name, args.tvar);
+		expr->name, args.var);
 		return AMR_CLEANUP;
 	}
 
@@ -2460,7 +2460,7 @@ ApplyModifier_Loop(const char **pp, ModC
 	if (res != VPR_OK)
 		return AMR_CLEANUP;
 	str = LazyBuf_DoneGet(&strBuf);
-	args.str = str.str;
+	args.body = str.str;
 
 	if (!Expr_ShouldEval(expr))
 		goto done;
@@ -2470,8 +2470,8 @@ ApplyModifier_Loop(const char **pp, ModC
 	ch->sep = ' ';		/* XXX: should be ch->sep for consistency */
 	ModifyWords(ch, ModifyWord_Loop, &args, ch->oneBigWord);
 	ch->sep = prev_sep;
-	/* XXX: Consider restoring the previous variable instead of deleting. */
-	Var_Delete(expr->scope, args.tvar);
+	/* XXX: Consider restoring the previous value instead of deleting. */
+	Var_Delete(expr->scope, args.var);
 
 done:
 	FStr_Done(&tvar);



CVS commit: src/usr.bin/make

2021-04-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Apr 14 15:41:08 UTC 2021

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

Log Message:
make: clean up pattern flags for the modifiers ':S' and ':C'

No special handling is necessary for C90 since none of the struct
members is a const_member.

The prefix 'Var' is not necessary since this type does not apply to a
variable but only to a modifier.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.926 -r1.927 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.926 src/usr.bin/make/var.c:1.927
--- src/usr.bin/make/var.c:1.926	Mon Apr 12 18:53:51 2021
+++ src/usr.bin/make/var.c	Wed Apr 14 15:41:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.926 2021/04/12 18:53:51 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.927 2021/04/14 15:41:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.926 2021/04/12 18:53:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.927 2021/04/14 15:41:08 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -241,12 +241,12 @@ typedef enum UnexportWhat {
 } UnexportWhat;
 
 /* Flags for pattern matching in the :S and :C modifiers */
-typedef struct VarPatternFlags {
+typedef struct PatternFlags {
 	bool subGlobal: 1;	/* 'g': replace as often as possible */
 	bool subOnce: 1;	/* '1': replace only once */
 	bool anchorStart: 1;	/* '^': match only at start of word */
 	bool anchorEnd: 1;	/* '$': match only at end of word */
-} VarPatternFlags;
+} PatternFlags;
 
 /* SepBuf builds a string from words interleaved with separators. */
 typedef struct SepBuf {
@@ -1495,7 +1495,7 @@ no_match:
 struct ModifyWord_SubstArgs {
 	Substring lhs;
 	Substring rhs;
-	VarPatternFlags pflags;
+	PatternFlags pflags;
 	bool matched;
 };
 
@@ -1589,7 +1589,7 @@ struct ModifyWord_SubstRegexArgs {
 	regex_t re;
 	size_t nsub;
 	const char *replace;
-	VarPatternFlags pflags;
+	PatternFlags pflags;
 	bool matched;
 };
 
@@ -2161,7 +2161,7 @@ ParseModifierPartSubst(
 LazyBuf *part,
 /* For the first part of the :S modifier, sets the VARP_ANCHOR_END flag
  * if the last character of the pattern is a $. */
-VarPatternFlags *out_pflags,
+PatternFlags *out_pflags,
 /* For the second part of the :S modifier, allow ampersands to be
  * escaped and replace unescaped ampersands with subst->lhs. */
 struct ModifyWord_SubstArgs *subst
@@ -2858,7 +2858,7 @@ ApplyModifier_Match(const char **pp, Mod
 }
 
 static void
-ParsePatternFlags(const char **pp, VarPatternFlags *pflags, bool *oneBigWord)
+ParsePatternFlags(const char **pp, PatternFlags *pflags, bool *oneBigWord)
 {
 	for (;; (*pp)++) {
 		if (**pp == 'g')
@@ -2872,16 +2872,12 @@ ParsePatternFlags(const char **pp, VarPa
 	}
 }
 
-#if __STDC_VERSION__ >= 199901L
-#define VarPatternFlags_Literal() (VarPatternFlags) { false, false, false, false }
-#else
-MAKE_INLINE VarPatternFlags
-VarPatternFlags_Literal(void)
+MAKE_INLINE PatternFlags
+PatternFlags_None(void)
 {
-	VarPatternFlags pflags = { false, false, false, false };
+	PatternFlags pflags = { false, false, false, false };
 	return pflags;
 }
-#endif
 
 /* :S,from,to, */
 static ApplyModifierResult
@@ -2901,7 +2897,7 @@ ApplyModifier_Subst(const char **pp, Mod
 
 	*pp += 2;
 
-	args.pflags = VarPatternFlags_Literal();
+	args.pflags = PatternFlags_None();
 	args.matched = false;
 
 	if (**pp == '^') {
@@ -2968,7 +2964,7 @@ ApplyModifier_Regex(const char **pp, Mod
 	replace = LazyBuf_DoneGet(&replaceBuf);
 	args.replace = replace.str;
 
-	args.pflags = VarPatternFlags_Literal();
+	args.pflags = PatternFlags_None();
 	args.matched = false;
 	oneBigWord = ch->oneBigWord;
 	ParsePatternFlags(pp, &args.pflags, &oneBigWord);



CVS commit: src/usr.bin/make

2021-04-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 12 18:53:51 UTC 2021

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

Log Message:
make: spell SysV in mixed case

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.925 -r1.926 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.925 src/usr.bin/make/var.c:1.926
--- src/usr.bin/make/var.c:1.925	Mon Apr 12 18:48:00 2021
+++ src/usr.bin/make/var.c	Mon Apr 12 18:53:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.925 2021/04/12 18:48:00 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.926 2021/04/12 18:53:51 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.925 2021/04/12 18:48:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.926 2021/04/12 18:53:51 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1441,7 +1441,7 @@ ModifyWord_NoMatch(Substring word, SepBu
 }
 
 #ifdef SYSVVARSUB
-struct ModifyWord_SYSVSubstArgs {
+struct ModifyWord_SysVSubstArgs {
 	GNode *scope;
 	Substring lhsPrefix;
 	bool lhsPercent;
@@ -1451,9 +1451,9 @@ struct ModifyWord_SYSVSubstArgs {
 
 /* Callback for ModifyWords to implement the :%.from=%.to modifier. */
 static void
-ModifyWord_SYSVSubst(Substring word, SepBuf *buf, void *data)
+ModifyWord_SysVSubst(Substring word, SepBuf *buf, void *data)
 {
-	const struct ModifyWord_SYSVSubstArgs *args = data;
+	const struct ModifyWord_SysVSubstArgs *args = data;
 	FStr rhs;
 	char *rhsExp;
 	const char *percent;
@@ -3587,7 +3587,7 @@ ApplyModifier_SysV(const char **pp, ModC
 	VarParseResult res;
 	LazyBuf lhsBuf, rhsBuf;
 	FStr rhs;
-	struct ModifyWord_SYSVSubstArgs args;
+	struct ModifyWord_SysVSubstArgs args;
 	Substring lhs;
 	const char *lhsSuffix;
 
@@ -3642,7 +3642,7 @@ ApplyModifier_SysV(const char **pp, ModC
 	args.lhsSuffix = Substring_Init(lhsSuffix, lhs.end);
 	args.rhs = rhs.str;
 
-	ModifyWords(ch, ModifyWord_SYSVSubst, &args, ch->oneBigWord);
+	ModifyWords(ch, ModifyWord_SysVSubst, &args, ch->oneBigWord);
 
 done:
 	LazyBuf_Done(&lhsBuf);



CVS commit: src/usr.bin/make

2021-04-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 12 18:48:00 UTC 2021

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

Log Message:
make: reduce memory allocation and strlen calls in modifier ':from=to'

Previously, SysVMatch was quite verbose and felt like hand-optimized
assembler code, which made it difficult to discover the underlying idea
of the code.

All this code was replaced with two simple calls to Substring_HasPrefix
and Substring_HasSuffix.  Now that the operands of that modifier are no
longer passed as C strings, there is no need to collect all information
in a single scan through the word and the pattern.

It was not necessary to call Var_Subst unconditionally.  Calling it only
when the string contains a '$' saves another memory allocation and two
string copies (because of the Buf_DoneDataCompact).

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/str.h
cvs rdiff -u -r1.924 -r1.925 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/str.h
diff -u src/usr.bin/make/str.h:1.5 src/usr.bin/make/str.h:1.6
--- src/usr.bin/make/str.h:1.5	Sun Apr 11 22:53:45 2021
+++ src/usr.bin/make/str.h	Mon Apr 12 18:48:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.5 2021/04/11 22:53:45 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.6 2021/04/12 18:48:00 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -190,6 +190,21 @@ Substring_Sub(Substring sub, size_t star
 	return Substring_Init(sub.start + start, sub.start + end);
 }
 
+MAKE_INLINE bool
+Substring_HasPrefix(Substring sub, Substring prefix)
+{
+	return Substring_Length(sub) >= Substring_Length(prefix) &&
+	   memcmp(sub.start, prefix.start, Substring_Length(prefix)) == 0;
+}
+
+MAKE_INLINE bool
+Substring_HasSuffix(Substring sub, Substring suffix)
+{
+	size_t suffixLen = Substring_Length(suffix);
+	return Substring_Length(sub) >= suffixLen &&
+	   memcmp(sub.end - suffixLen, suffix.start, suffixLen) == 0;
+}
+
 MAKE_INLINE FStr
 Substring_Str(Substring sub)
 {
@@ -197,6 +212,17 @@ Substring_Str(Substring sub)
 }
 
 MAKE_INLINE const char *
+Substring_SkipFirst(Substring sub, char ch)
+{
+	const char *p;
+
+	for (p = sub.start; p != sub.end; p++)
+		if (*p == ch)
+			return p + 1;
+	return sub.start;
+}
+
+MAKE_INLINE const char *
 Substring_LastIndex(Substring sub, char ch)
 {
 	const char *p;

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.924 src/usr.bin/make/var.c:1.925
--- src/usr.bin/make/var.c:1.924	Mon Apr 12 13:28:35 2021
+++ src/usr.bin/make/var.c	Mon Apr 12 18:48:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.924 2021/04/12 13:28:35 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.925 2021/04/12 18:48:00 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.924 2021/04/12 13:28:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.925 2021/04/12 18:48:00 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1441,69 +1441,11 @@ ModifyWord_NoMatch(Substring word, SepBu
 }
 
 #ifdef SYSVVARSUB
-
-/*
- * Check word against pattern for a match (% is a wildcard).
- *
- * Input:
- *	word		Word to examine
- *	pattern		Pattern to examine against
- *
- * Results:
- *	Returns the start of the match, or NULL.
- *	out_match_len returns the length of the match, if any.
- *	out_hasPercent returns whether the pattern contains a percent.
- */
-/* TODO: migrate to using Substring */
-static const char *
-SysVMatch(const char *word, const char *pattern,
-	  size_t *out_match_len, bool *out_hasPercent)
-{
-	const char *p = pattern;
-	const char *w = word;
-	const char *percent;
-	size_t w_len;
-	size_t p_len;
-	const char *w_tail;
-
-	*out_hasPercent = false;
-	percent = strchr(p, '%');
-	if (percent != NULL) {		/* ${VAR:...%...=...} */
-		*out_hasPercent = true;
-		if (w[0] == '\0')
-			return NULL;	/* empty word does not match pattern */
-
-		/* check that the prefix matches */
-		for (; p != percent && *w != '\0' && *w == *p; w++, p++)
-			continue;
-		if (p != percent)
-			return NULL;	/* No match */
-
-		p++;		/* Skip the percent */
-		if (*p == '\0') {
-			/* No more pattern, return the rest of the string */
-			*out_match_len = strlen(w);
-			return w;
-		}
-	}
-
-	/* Test whether the tail matches */
-	w_len = strlen(w);
-	p_len = strlen(p);
-	if (w_len < p_len)
-		return NULL;
-
-	w_tail = w + w_len - p_len;
-	if (memcmp(p, w_tail, p_len) != 0)
-		return NULL;
-
-	*out_match_len = (size_t)(w_tail - w);
-	return w;
-}
-
 struct ModifyWord_SYSVSubstArgs {
 	GNode *scope;
-	const char *lhs;
+	Substring lhsPrefix;
+	bool lhsPercent;
+	Substring lhsSuffix;
 	const char *rhs;
 };
 
@@ -1512,43 +1454,40 @@ static void
 ModifyWord_SYSVSubst(Substring word, SepBuf *buf, void *data)
 {
 	co

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

2021-04-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 12 16:09:57 UTC 2021

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

Log Message:
tests/make: fix test for modifier ':from=to'

I had forgotten to remove the single quotes, to produce a really empty
word.  Plus I had forgotten the modifier ':Q' for the result, which
meant that the single quotes did not show up in the output.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-sysv.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmod-sysv.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-sysv.exp
diff -u src/usr.bin/make/unit-tests/varmod-sysv.exp:1.8 src/usr.bin/make/unit-tests/varmod-sysv.exp:1.9
--- src/usr.bin/make/unit-tests/varmod-sysv.exp:1.8	Mon Apr 12 16:04:30 2021
+++ src/usr.bin/make/unit-tests/varmod-sysv.exp	Mon Apr 12 16:09:57 2021
@@ -5,23 +5,23 @@ word modifier   
 suffix   ="suffix"
 prefix   ="prefix"
 pre-middle-suffix="pre-middle-suffix"
-''   =NS  "NS"
+''   =NS  ""
 suffix   =NS  "suffixNS"
 prefix   =NS  "prefixNS"
 pre-middle-suffix=NS  "pre-middle-suffixNS"
-''   =%   "%"
+''   =%   ""
 suffix   =%   "suffix%"
 prefix   =%   "prefix%"
 pre-middle-suffix=%   "pre-middle-suffix%"
-''   =%NS "%NS"
+''   =%NS ""
 suffix   =%NS "suffix%NS"
 prefix   =%NS "prefix%NS"
 pre-middle-suffix=%NS "pre-middle-suffix%NS"
-''   =NPre%   "NPre%"
+''   =NPre%   ""
 suffix   =NPre%   "suffixNPre%"
 prefix   =NPre%   "prefixNPre%"
 pre-middle-suffix=NPre%   "pre-middle-suffixNPre%"
-''   =NPre%NS "NPre%NS"
+''   =NPre%NS ""
 suffix   =NPre%NS "suffixNPre%NS"
 prefix   =NPre%NS "prefixNPre%NS"
 pre-middle-suffix=NPre%NS "pre-middle-suffixNPre%NS"
@@ -53,7 +53,7 @@ pre-middle-suffixffix=NPre%NS   
 suffix   %=   ""
 prefix   %=   ""
 pre-middle-suffix%=   ""
-''   %=NS "NS"
+''   %=NS ""
 suffix   %=NS "NS"
 prefix   %=NS "NS"
 pre-middle-suffix%=NS "NS"
@@ -61,15 +61,15 @@ pre-middle-suffix%=NS   
 suffix   %=%  "suffix"
 prefix   %=%  "prefix"
 pre-middle-suffix%=%  "pre-middle-suffix"
-''   %=%NS"NS"
+''   %=%NS""
 suffix   %=%NS"suffixNS"
 prefix   %=%NS"prefixNS"
 pre-middle-suffix%=%NS"pre-middle-suffixNS"
-''   %=NPre%  "NPre"
+''   %=NPre%  ""
 suffix   %=NPre%  "NPresuffix"
 prefix   %=NPre%  "NPreprefix"
 pre-middle-suffix%=NPre%  "NPrepre-middle-suffix"
-''   %=NPre%NS"NPreNS"
+''   %=NPre%NS""
 suffix   %=NPre%NS"NPresuffixNS"
 prefix   %=NPre%NS"NPreprefixNS"
 pre-middle-suffix%=NPre%NS"NPrepre-middle-suffixNS"

Index: src/usr.bin/make/unit-tests/varmod-sysv.mk
diff -u src/usr.bin/make/unit-tests/varmod-sysv.mk:1.13 src/usr.bin/make/unit-tests/varmod-sysv.mk:1.14
--- src/usr.bin/make/unit-tests/varmod-sysv.mk:1.13	Mon Apr 12 16:04:30 2021
+++ src/usr.bin/make/unit-tests/varmod-sysv.mk	Mon Apr 12 16:09:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sysv.mk,v 1.13 2021/04/12 16:04:30 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.14 2021/04/12 16:09:57 ri

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

2021-04-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 12 16:04:31 UTC 2021

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

Log Message:
tests/make: add table test for the modifier ':from=to'

Just to prevent any accidental change in the upcoming refactoring to
reduce memory allocation in ApplyModifier_SysV.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmod-sysv.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-sysv.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-sysv.exp
diff -u src/usr.bin/make/unit-tests/varmod-sysv.exp:1.7 src/usr.bin/make/unit-tests/varmod-sysv.exp:1.8
--- src/usr.bin/make/unit-tests/varmod-sysv.exp:1.7	Tue Feb 23 00:04:48 2021
+++ src/usr.bin/make/unit-tests/varmod-sysv.exp	Mon Apr 12 16:04:30 2021
@@ -1,5 +1,150 @@
 make: Unfinished modifier for "word214" ('=' missing)
 make: "varmod-sysv.mk" line 214: Malformed conditional (${word214:L:from${:D=}to})
+word modifier result  
+''   =""
+suffix   ="suffix"
+prefix   ="prefix"
+pre-middle-suffix="pre-middle-suffix"
+''   =NS  "NS"
+suffix   =NS  "suffixNS"
+prefix   =NS  "prefixNS"
+pre-middle-suffix=NS  "pre-middle-suffixNS"
+''   =%   "%"
+suffix   =%   "suffix%"
+prefix   =%   "prefix%"
+pre-middle-suffix=%   "pre-middle-suffix%"
+''   =%NS "%NS"
+suffix   =%NS "suffix%NS"
+prefix   =%NS "prefix%NS"
+pre-middle-suffix=%NS "pre-middle-suffix%NS"
+''   =NPre%   "NPre%"
+suffix   =NPre%   "suffixNPre%"
+prefix   =NPre%   "prefixNPre%"
+pre-middle-suffix=NPre%   "pre-middle-suffixNPre%"
+''   =NPre%NS "NPre%NS"
+suffix   =NPre%NS "suffixNPre%NS"
+prefix   =NPre%NS "prefixNPre%NS"
+pre-middle-suffix=NPre%NS "pre-middle-suffixNPre%NS"
+''   ffix=""
+suffix   ffix="su"
+prefix   ffix="prefix"
+pre-middle-suffixffix="pre-middle-su"
+''   ffix=NS  ""
+suffix   ffix=NS  "suNS"
+prefix   ffix=NS  "prefix"
+pre-middle-suffixffix=NS  "pre-middle-suNS"
+''   ffix=%   ""
+suffix   ffix=%   "su%"
+prefix   ffix=%   "prefix"
+pre-middle-suffixffix=%   "pre-middle-su%"
+''   ffix=%NS ""
+suffix   ffix=%NS "su%NS"
+prefix   ffix=%NS "prefix"
+pre-middle-suffixffix=%NS "pre-middle-su%NS"
+''   ffix=NPre%   ""
+suffix   ffix=NPre%   "suNPre%"
+prefix   ffix=NPre%   "prefix"
+pre-middle-suffixffix=NPre%   "pre-middle-suNPre%"
+''   ffix=NPre%NS ""
+suffix   ffix=NPre%NS "suNPre%NS"
+prefix   ffix=NPre%NS "prefix"
+pre-middle-suffixffix=NPre%NS "pre-middle-suNPre%NS"
+''   %=   ""
+suffix   %=   ""
+prefix   %=   ""
+pre-middle-suffix%=   ""
+''   %=NS "NS"
+suffix   %=NS "NS"
+prefix   %=NS "NS"
+pre-middle-suffix%=NS "NS"
+''   %=%  ""
+suffix   %=%  "suffix"
+prefix   %=%  "prefix"
+pre-middle-suffix%=%  "pre-middle-suffix"
+''   %=%NS"NS"
+suffix   %=%NS"su

CVS commit: src/usr.bin/make

2021-04-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Apr 12 13:28:35 UTC 2021

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

Log Message:
make: in the ':Q' modifier, only allocate memory if necessary


To generate a diff of this commit:
cvs rdiff -u -r1.923 -r1.924 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.923 src/usr.bin/make/var.c:1.924
--- src/usr.bin/make/var.c:1.923	Sun Apr 11 22:53:45 2021
+++ src/usr.bin/make/var.c	Mon Apr 12 13:28:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.923 2021/04/11 22:53:45 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.924 2021/04/12 13:28:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.923 2021/04/11 22:53:45 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.924 2021/04/12 13:28:35 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1908,28 +1908,26 @@ VarUniq(const char *str)
  * Quote shell meta-characters and space characters in the string.
  * If quoteDollar is set, also quote and double any '$' characters.
  */
-static char *
-VarQuote(const char *str, bool quoteDollar)
+static void
+VarQuote(const char *str, bool quoteDollar, LazyBuf *buf)
 {
-	Buffer buf;
-	Buf_Init(&buf);
+	const char *p;
 
-	for (; *str != '\0'; str++) {
-		if (*str == '\n') {
+	LazyBuf_Init(buf, str);
+	for (p = str; *p != '\0'; p++) {
+		if (*p == '\n') {
 			const char *newline = Shell_GetNewline();
 			if (newline == NULL)
 newline = "\\\n";
-			Buf_AddStr(&buf, newline);
+			LazyBuf_AddStr(buf, newline);
 			continue;
 		}
-		if (ch_isspace(*str) || is_shell_metachar((unsigned char)*str))
-			Buf_AddByte(&buf, '\\');
-		Buf_AddByte(&buf, *str);
-		if (quoteDollar && *str == '$')
-			Buf_AddStr(&buf, "\\$");
+		if (ch_isspace(*p) || is_shell_metachar((unsigned char)*p))
+			LazyBuf_Add(buf, '\\');
+		LazyBuf_Add(buf, *p);
+		if (quoteDollar && *p == '$')
+			LazyBuf_AddStr(buf, "\\$");
 	}
-
-	return Buf_DoneData(&buf);
 }
 
 /*
@@ -3068,14 +3066,22 @@ ApplyModifier_Regex(const char **pp, Mod
 static ApplyModifierResult
 ApplyModifier_Quote(const char **pp, ModChain *ch)
 {
-	bool quoteDollar = **pp == 'q';
+	LazyBuf buf;
+	bool quoteDollar;
+
+	quoteDollar = **pp == 'q';
 	if (!IsDelimiter((*pp)[1], ch))
 		return AMR_UNKNOWN;
 	(*pp)++;
 
-	if (ModChain_ShouldEval(ch))
-		Expr_SetValueOwn(ch->expr,
-		VarQuote(ch->expr->value.str, quoteDollar));
+	if (!ModChain_ShouldEval(ch))
+		return AMR_OK;
+
+	VarQuote(ch->expr->value.str, quoteDollar, &buf);
+	if (buf.data != NULL)
+		Expr_SetValue(ch->expr, LazyBuf_DoneGet(&buf));
+	else
+		LazyBuf_Done(&buf);
 
 	return AMR_OK;
 }



CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 22:53:46 UTC 2021

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

Log Message:
make: improve performance for LazyBuf

The previous O(n^2) time complexity for parsing a long string with many
variable expressions was not meant to last for long.  I had hoped to fix
it within a few minutes, but that will take more time.

For now, make LazyBuf simpler by using a traditional C string for the
expected part instead of a Substring.  This avoids a strlen call per
Var_Parse.

No functional change, only performance.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/str.h
cvs rdiff -u -r1.922 -r1.923 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/str.h
diff -u src/usr.bin/make/str.h:1.4 src/usr.bin/make/str.h:1.5
--- src/usr.bin/make/str.h:1.4	Sun Apr 11 20:38:43 2021
+++ src/usr.bin/make/str.h	Sun Apr 11 22:53:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.4 2021/04/11 20:38:43 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.5 2021/04/11 22:53:45 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -59,7 +59,7 @@ typedef struct LazyBuf {
 	char *data;
 	size_t len;
 	size_t cap;
-	Substring expected;
+	const char *expected;
 	void *freeIt;
 } LazyBuf;
 
@@ -231,7 +231,7 @@ Substring_Basename(Substring pathname)
 
 
 MAKE_INLINE void
-LazyBuf_Init(LazyBuf *buf, Substring expected)
+LazyBuf_Init(LazyBuf *buf, const char *expected)
 {
 	buf->data = NULL;
 	buf->len = 0;
@@ -257,15 +257,14 @@ LazyBuf_Add(LazyBuf *buf, char ch)
 		}
 		buf->data[buf->len++] = ch;
 
-	} else if (buf->len < Substring_Length(buf->expected) &&
-	ch == buf->expected.start[buf->len]) {
+	} else if (ch == buf->expected[buf->len]) {
 		buf->len++;
 		return;
 
 	} else {
 		buf->cap = buf->len + 16;
 		buf->data = bmake_malloc(buf->cap);
-		memcpy(buf->data, buf->expected.start, buf->len);
+		memcpy(buf->data, buf->expected, buf->len);
 		buf->data[buf->len++] = ch;
 	}
 }
@@ -297,8 +296,7 @@ LazyBuf_AddSubstring(LazyBuf *buf, Subst
 MAKE_INLINE Substring
 LazyBuf_Get(const LazyBuf *buf)
 {
-	const char *start = buf->data != NULL
-	? buf->data : buf->expected.start;
+	const char *start = buf->data != NULL ? buf->data : buf->expected;
 	return Substring_Init(start, start + buf->len);
 }
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.922 src/usr.bin/make/var.c:1.923
--- src/usr.bin/make/var.c:1.922	Sun Apr 11 21:29:57 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 22:53:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.922 2021/04/11 21:29:57 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.923 2021/04/11 22:53:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.922 2021/04/11 21:29:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.923 2021/04/11 22:53:45 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2233,7 +2233,7 @@ ParseModifierPartSubst(
 	const char *p;
 
 	p = *pp;
-	LazyBuf_Init(part, Substring_InitStr(p)); /* TODO: O(n^2) */
+	LazyBuf_Init(part, p);
 
 	/*
 	 * Skim through until the matching delimiter is found; pick up
@@ -4136,7 +4136,7 @@ ParseVarname(const char **pp, char start
 	const char *p = *pp;
 	int depth = 0;		/* Track depth so we can spot parse errors. */
 
-	LazyBuf_Init(buf, Substring_InitStr(p));
+	LazyBuf_Init(buf, p);
 
 	while (*p != '\0') {
 		if ((*p == endc || *p == ':') && depth == 0)



CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 21:29:57 UTC 2021

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

Log Message:
make: remove redundant parameter from ParseVarnameLong

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.921 -r1.922 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.921 src/usr.bin/make/var.c:1.922
--- src/usr.bin/make/var.c:1.921	Sun Apr 11 20:38:43 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 21:29:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.921 2021/04/11 20:38:43 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.922 2021/04/11 21:29:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.921 2021/04/11 20:38:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.922 2021/04/11 21:29:57 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4305,7 +4305,7 @@ EvalUndefined(bool dynamic, const char *
  */
 static bool
 ParseVarnameLong(
-	const char *p,
+	const char **pp,
 	char startc,
 	GNode *scope,
 	VarEvalMode emode,
@@ -4315,7 +4315,6 @@ ParseVarnameLong(
 	FStr *out_false_val,
 
 	char *out_true_endc,
-	const char **out_true_p,
 	Var **out_true_v,
 	bool *out_true_haveModifier,
 	const char **out_true_extraModifiers,
@@ -4328,6 +4327,7 @@ ParseVarnameLong(
 	bool haveModifier;
 	bool dynamic = false;
 
+	const char *p = *pp;
 	const char *const start = p;
 	char endc = startc == '(' ? ')' : '}';
 
@@ -4394,8 +4394,8 @@ ParseVarnameLong(
 	} else
 		LazyBuf_Done(&varname);
 
+	*pp = p;
 	*out_true_endc = endc;
-	*out_true_p = p;
 	*out_true_v = v;
 	*out_true_haveModifier = haveModifier;
 	*out_true_dynamic = dynamic;
@@ -4548,9 +4548,9 @@ Var_Parse(const char **pp, GNode *scope,
 		p++;
 	} else {
 		VarParseResult res;
-		if (!ParseVarnameLong(p, startc, scope, emode,
+		if (!ParseVarnameLong(&p, startc, scope, emode,
 		pp, &res, out_val,
-		&endc, &p, &v, &haveModifier, &extramodifiers,
+		&endc, &v, &haveModifier, &extramodifiers,
 		&dynamic, &expr.defined))
 			return res;
 	}



CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 20:38:43 UTC 2021

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

Log Message:
make: migrate ParseModifierPart to use Substring

This will reduce memory allocation for modifier parts without the escape
characters '$' or '\'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/str.h
cvs rdiff -u -r1.920 -r1.921 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/str.h
diff -u src/usr.bin/make/str.h:1.3 src/usr.bin/make/str.h:1.4
--- src/usr.bin/make/str.h:1.3	Sun Apr 11 19:05:06 2021
+++ src/usr.bin/make/str.h	Sun Apr 11 20:38:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.3 2021/04/11 19:05:06 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.4 2021/04/11 20:38:43 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -46,7 +46,7 @@ typedef struct MFStr {
 } MFStr;
 
 /* A read-only range of a character array, NOT null-terminated. */
-typedef struct {
+typedef struct Substring {
 	const char *start;
 	const char *end;
 } Substring;
@@ -279,6 +279,21 @@ LazyBuf_AddStr(LazyBuf *buf, const char 
 		LazyBuf_Add(buf, *p);
 }
 
+MAKE_INLINE void
+LazyBuf_AddBytesBetween(LazyBuf *buf, const char *start, const char *end)
+{
+	const char *p;
+
+	for (p = start; p != end; p++)
+		LazyBuf_Add(buf, *p);
+}
+
+MAKE_INLINE void
+LazyBuf_AddSubstring(LazyBuf *buf, Substring sub)
+{
+	LazyBuf_AddBytesBetween(buf, sub.start, sub.end);
+}
+
 MAKE_INLINE Substring
 LazyBuf_Get(const LazyBuf *buf)
 {

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.920 src/usr.bin/make/var.c:1.921
--- src/usr.bin/make/var.c:1.920	Sun Apr 11 19:05:06 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 20:38:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.920 2021/04/11 19:05:06 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.921 2021/04/11 20:38:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.920 2021/04/11 19:05:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.921 2021/04/11 20:38:43 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1618,7 +1618,7 @@ ModifyWord_Subst(Substring word, SepBuf 
 		return;
 	}
 
-	if (args->lhs.start[0] == '\0')
+	if (Substring_IsEmpty(args->lhs))
 		goto nosub;
 
 	/* unanchored case, may match more than once */
@@ -1626,7 +1626,7 @@ ModifyWord_Subst(Substring word, SepBuf 
 		SepBuf_AddBytesBetween(buf, word.start, match);
 		SepBuf_AddSubstring(buf, args->rhs);
 		args->matched = true;
-		word.start += (size_t)(match - word.start) + lhsLen;
+		word.start = match + lhsLen;
 		if (Substring_IsEmpty(word) || !args->pflags.subGlobal)
 			break;
 	}
@@ -1649,7 +1649,7 @@ VarREError(int reerr, const regex_t *pat
 struct ModifyWord_SubstRegexArgs {
 	regex_t re;
 	size_t nsub;
-	char *replace;
+	const char *replace;
 	VarPatternFlags pflags;
 	bool matched;
 };
@@ -1664,7 +1664,7 @@ ModifyWord_SubstRegex(Substring word, Se
 	struct ModifyWord_SubstRegexArgs *args = data;
 	int xrv;
 	const char *wp;
-	char *rp;
+	const char *rp;
 	int flags = 0;
 	regmatch_t m[10];
 
@@ -1749,8 +1749,8 @@ tryagain:
 
 struct ModifyWord_LoopArgs {
 	GNode *scope;
-	char *tvar;		/* name of temporary variable */
-	char *str;		/* string to expand */
+	const char *tvar;	/* name of temporary variable */
+	const char *str;	/* string to expand */
 	VarEvalMode emode;
 };
 
@@ -2157,17 +2157,22 @@ Expr_Define(Expr *expr)
 }
 
 static void
-Expr_SetValueOwn(Expr *expr, char *value)
+Expr_SetValue(Expr *expr, FStr value)
 {
 	FStr_Done(&expr->value);
-	expr->value = FStr_InitOwn(value);
+	expr->value = value;
+}
+
+static void
+Expr_SetValueOwn(Expr *expr, char *value)
+{
+	Expr_SetValue(expr, FStr_InitOwn(value));
 }
 
 static void
 Expr_SetValueRefer(Expr *expr, const char *value)
 {
-	FStr_Done(&expr->value);
-	expr->value = FStr_InitRefer(value);
+	Expr_SetValue(expr, FStr_InitRefer(value));
 }
 
 static bool
@@ -2216,10 +2221,7 @@ ParseModifierPartSubst(
 char delim,
 VarEvalMode emode,
 ModChain *ch,
-char **out_part,
-/* Optionally stores the end of the returned string, just to save
- * another strlen call. */
-const char **out_part_end,
+LazyBuf *part,
 /* For the first part of the :S modifier, sets the VARP_ANCHOR_END flag
  * if the last character of the pattern is a $. */
 VarPatternFlags *out_pflags,
@@ -2228,31 +2230,29 @@ ParseModifierPartSubst(
 struct ModifyWord_SubstArgs *subst
 )
 {
-	Buffer buf;
 	const char *p;
 
-	Buf_Init(&buf);
+	p = *pp;
+	LazyBuf_Init(part, Substring_InitStr(p)); /* TODO: O(n^2) */
 
 	/*
 	 * Skim through until the matching delimiter is found; pick up
 	 * variable expressions on the way.
 	 */
-	p = *pp;
 	while (*p != '\0' && *p !=

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 19:05:06 UTC 2021

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

Log Message:
make: avoid unnecessary calls to strlen when evaluating modifiers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/make/str.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/str.h
cvs rdiff -u -r1.919 -r1.920 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/str.c
diff -u src/usr.bin/make/str.c:1.83 src/usr.bin/make/str.c:1.84
--- src/usr.bin/make/str.c:1.83	Sat Apr  3 14:39:02 2021
+++ src/usr.bin/make/str.c	Sun Apr 11 19:05:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.83 2021/04/03 14:39:02 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.84 2021/04/11 19:05:06 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.83 2021/04/03 14:39:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.84 2021/04/11 19:05:06 rillig Exp $");
 
 /* Return the concatenation of s1 and s2, freshly allocated. */
 char *
@@ -125,13 +125,13 @@ str_concat4(const char *s1, const char *
  * Returns the fractured words, which must be freed later using Words_Free,
  * unless the returned Words.words was NULL.
  */
-Words
-Str_Words(const char *str, bool expand)
+SubstringWords
+Substring_Words(const char *str, bool expand)
 {
 	size_t str_len;
 	char *words_buf;
 	size_t words_cap;
-	char **words;
+	Substring *words;
 	size_t words_len;
 	char inquote;
 	char *word_start;
@@ -146,7 +146,7 @@ Str_Words(const char *str, bool expand)
 	words_buf = bmake_malloc(str_len + 1);
 
 	words_cap = str_len / 5 > 50 ? str_len / 5 : 50;
-	words = bmake_malloc((words_cap + 1) * sizeof(char *));
+	words = bmake_malloc((words_cap + 1) * sizeof(words[0]));
 
 	/*
 	 * copy the string; at the same time, parse backslashes,
@@ -205,15 +205,16 @@ Str_Words(const char *str, bool expand)
 			*word_end++ = '\0';
 			if (words_len == words_cap) {
 size_t new_size;
-words_cap *= 2;		/* ramp up fast */
-new_size = (words_cap + 1) * sizeof(char *);
+words_cap *= 2;
+new_size = (words_cap + 1) * sizeof(words[0]);
 words = bmake_realloc(words, new_size);
 			}
-			words[words_len++] = word_start;
+			words[words_len++] =
+			Substring_Init(word_start, word_end - 1);
 			word_start = NULL;
 			if (ch == '\n' || ch == '\0') {
 if (expand && inquote != '\0') {
-	Words res;
+	SubstringWords res;
 
 	free(words);
 	free(words_buf);
@@ -268,10 +269,10 @@ Str_Words(const char *str, bool expand)
 		*word_end++ = ch;
 	}
 done:
-	words[words_len] = NULL;	/* useful for argv */
+	words[words_len] = Substring_Init(NULL, NULL);	/* useful for argv */
 
 	{
-		Words result;
+		SubstringWords result;
 
 		result.words = words;
 		result.len = words_len;
@@ -280,6 +281,30 @@ done:
 	}
 }
 
+Words
+Str_Words(const char *str, bool expand)
+{
+	SubstringWords swords;
+	Words words;
+	size_t i;
+
+	swords = Substring_Words(str, expand);
+	if (swords.words == NULL) {
+		words.words = NULL;
+		words.len = 0;
+		words.freeIt = NULL;
+		return words;
+	}
+
+	words.words = bmake_malloc((swords.len + 1) * sizeof(words.words[0]));
+	words.len = swords.len;
+	words.freeIt = swords.freeIt;
+	for (i = 0; i < swords.len + 1; i++)
+		words.words[i] = UNCONST(swords.words[i].start);
+	free(swords.words);
+	return words;
+}
+
 /*
  * Str_Match -- Test if a string matches a pattern like "*.[ch]".
  * The following special characters are known *?\[] (as in fnmatch(3)).

Index: src/usr.bin/make/str.h
diff -u src/usr.bin/make/str.h:1.2 src/usr.bin/make/str.h:1.3
--- src/usr.bin/make/str.h:1.2	Sun Apr 11 18:44:57 2021
+++ src/usr.bin/make/str.h	Sun Apr 11 19:05:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.2 2021/04/11 18:44:57 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.3 2021/04/11 19:05:06 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -70,6 +70,13 @@ typedef struct Words {
 	void *freeIt;
 } Words;
 
+/* The result of splitting a string into words. */
+typedef struct SubstringWords {
+	Substring *words;
+	size_t len;
+	void *freeIt;
+} SubstringWords;
+
 
 MAKE_INLINE FStr
 FStr_Init(const char *str, void *freeIt)
@@ -301,6 +308,16 @@ Words_Free(Words w)
 }
 
 
+SubstringWords Substring_Words(const char *, bool);
+
+MAKE_INLINE void
+SubstringWords_Free(SubstringWords w)
+{
+	free(w.words);
+	free(w.freeIt);
+}
+
+
 char *str_concat2(const char *, const char *);
 char *str_concat3(const char *, const char *, const char *);
 char *str_concat4(const char *, const char *, const char *, const char *);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.919 src/usr.bin/make/var.c:1.920
--- src/usr.bin/make/var.c:1.919	Sun Apr 11 18:44:57 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 19:05:06 2021
@@ -1,

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 18:44:58 UTC 2021

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

Log Message:
make: migrate ModifyWord functions to use Substring

This benefits the modifiers ':T' and ':H' since these scan the word from
the end.  The SysV modifier '.c=.o' does not benefit yet, this will be
done in a follow-up commit.

Currently ModifyWords calls strlen for each single word, which degrades
performance.  This will be cleaned up in a follow-up commit as well.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/str.h
cvs rdiff -u -r1.918 -r1.919 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/str.h
diff -u src/usr.bin/make/str.h:1.1 src/usr.bin/make/str.h:1.2
--- src/usr.bin/make/str.h:1.1	Sun Apr 11 12:06:53 2021
+++ src/usr.bin/make/str.h	Sun Apr 11 18:44:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.h,v 1.1 2021/04/11 12:06:53 rillig Exp $	*/
+/*	$NetBSD: str.h,v 1.2 2021/04/11 18:44:57 rillig Exp $	*/
 
 /*
  Copyright (c) 2021 Roland Illig 
@@ -162,6 +162,12 @@ Substring_Length(Substring sub)
 }
 
 MAKE_INLINE bool
+Substring_IsEmpty(Substring sub)
+{
+	return sub.start == sub.end;
+}
+
+MAKE_INLINE bool
 Substring_Equals(Substring sub, const char *str)
 {
 	size_t len = strlen(str);
@@ -183,6 +189,39 @@ Substring_Str(Substring sub)
 	return FStr_InitOwn(bmake_strsedup(sub.start, sub.end));
 }
 
+MAKE_INLINE const char *
+Substring_LastIndex(Substring sub, char ch)
+{
+	const char *p;
+
+	for (p = sub.end; p != sub.start; p--)
+		if (p[-1] == ch)
+			return p - 1;
+	return NULL;
+}
+
+MAKE_INLINE Substring
+Substring_Dirname(Substring pathname)
+{
+	const char *p;
+
+	for (p = pathname.end; p != pathname.start; p--)
+		if (p[-1] == '/')
+			return Substring_Init(pathname.start, p - 1);
+	return Substring_InitStr(".");
+}
+
+MAKE_INLINE Substring
+Substring_Basename(Substring pathname)
+{
+	const char *p;
+
+	for (p = pathname.end; p != pathname.start; p--)
+		if (p[-1] == '/')
+			return Substring_Init(p, pathname.end);
+	return pathname;
+}
+
 
 MAKE_INLINE void
 LazyBuf_Init(LazyBuf *buf, Substring expected)

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.918 src/usr.bin/make/var.c:1.919
--- src/usr.bin/make/var.c:1.918	Sun Apr 11 17:48:01 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 18:44:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.918 2021/04/11 17:48:01 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.919 2021/04/11 18:44:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.918 2021/04/11 17:48:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.919 2021/04/11 18:44:57 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1334,6 +1334,12 @@ SepBuf_AddStr(SepBuf *buf, const char *s
 	SepBuf_AddBytes(buf, str, strlen(str));
 }
 
+static void
+SepBuf_AddSubstring(SepBuf *buf, Substring sub)
+{
+	SepBuf_AddBytesBetween(buf, sub.start, sub.end);
+}
+
 static char *
 SepBuf_DoneData(SepBuf *buf)
 {
@@ -1348,8 +1354,12 @@ SepBuf_DoneData(SepBuf *buf)
  *
  * 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".
+ *
+ * Some ModifyWord functions assume that they are always passed a
+ * null-terminated substring, which is currently guaranteed but may change in
+ * the future.
  */
-typedef void (*ModifyWordProc)(const char *word, SepBuf *buf, void *data);
+typedef void (*ModifyWordProc)(Substring word, SepBuf *buf, void *data);
 
 
 /*
@@ -1358,13 +1368,9 @@ typedef void (*ModifyWordProc)(const cha
  */
 /*ARGSUSED*/
 static void
-ModifyWord_Head(const char *word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Head(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
-	const char *slash = strrchr(word, '/');
-	if (slash != NULL)
-		SepBuf_AddBytesBetween(buf, word, slash);
-	else
-		SepBuf_AddStr(buf, ".");
+	SepBuf_AddSubstring(buf, Substring_Dirname(word));
 }
 
 /*
@@ -1373,9 +1379,9 @@ ModifyWord_Head(const char *word, SepBuf
  */
 /*ARGSUSED*/
 static void
-ModifyWord_Tail(const char *word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Tail(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
-	SepBuf_AddStr(buf, str_basename(word));
+	SepBuf_AddSubstring(buf, Substring_Basename(word));
 }
 
 /*
@@ -1384,11 +1390,11 @@ ModifyWord_Tail(const char *word, SepBuf
  */
 /*ARGSUSED*/
 static void
-ModifyWord_Suffix(const char *word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Suffix(Substring word, SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
-	const char *lastDot = strrchr(word, '.');
+	const char *lastDot = Substring_LastIndex(word, '.');
 	if (lastDot != NULL)
-		SepBuf_Add

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 17:48:01 UTC 2021

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

Log Message:
make: migrate handling of the modifier ':S,from,to,' to Substring

Right now this does not gain any performance, it only makes the code in
ModifyWord_Subst a little simpler since it only uses
Buf_AddBytesBetween, not a mixture with Buf_AddBytes.

When the word passed to the ModifyWord functions is converted to
Substring as well, the call to strlen will become redundant.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.917 -r1.918 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.917 src/usr.bin/make/var.c:1.918
--- src/usr.bin/make/var.c:1.917	Sun Apr 11 13:35:56 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 17:48:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.917 2021/04/11 13:35:56 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.918 2021/04/11 17:48:01 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.917 2021/04/11 13:35:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.918 2021/04/11 17:48:01 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1541,14 +1541,25 @@ ModifyWord_SYSVSubst(const char *word, S
 
 
 struct ModifyWord_SubstArgs {
-	const char *lhs;
-	size_t lhsLen;
-	const char *rhs;
-	size_t rhsLen;
+	Substring lhs;
+	Substring rhs;
 	VarPatternFlags pflags;
 	bool matched;
 };
 
+static const char *
+Substring_Find(Substring haystack, Substring needle)
+{
+	size_t len, needleLen, i;
+
+	len = Substring_Length(haystack);
+	needleLen = Substring_Length(needle);
+	for (i = 0; i + needleLen <= len; i++)
+		if (memcmp(haystack.start + i, needle.start, needleLen) == 0)
+			return haystack.start + i;
+	return NULL;
+}
+
 /*
  * Callback for ModifyWords to implement the :S,from,to, modifier.
  * Perform a string substitution on the given word.
@@ -1556,61 +1567,59 @@ struct ModifyWord_SubstArgs {
 static void
 ModifyWord_Subst(const char *word, SepBuf *buf, void *data)
 {
-	size_t wordLen = strlen(word);
 	struct ModifyWord_SubstArgs *args = data;
-	const char *match;
+	size_t wordLen, lhsLen;
+	const char *wordEnd, *match;
 
+	wordLen = strlen(word);
+	wordEnd = word + wordLen;
 	if (args->pflags.subOnce && args->matched)
 		goto nosub;
 
+	lhsLen = Substring_Length(args->lhs);
 	if (args->pflags.anchorStart) {
-		if (wordLen < args->lhsLen ||
-		memcmp(word, args->lhs, args->lhsLen) != 0)
+		if (wordLen < lhsLen ||
+		memcmp(word, args->lhs.start, lhsLen) != 0)
 			goto nosub;
 
-		if (args->pflags.anchorEnd && wordLen != args->lhsLen)
+		if (args->pflags.anchorEnd && wordLen != lhsLen)
 			goto nosub;
 
 		/* :S,^prefix,replacement, or :S,^whole$,replacement, */
-		SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
-		SepBuf_AddBytesBetween(buf,
-		word + args->lhsLen, word + wordLen);
+		SepBuf_AddBytesBetween(buf, args->rhs.start, args->rhs.end);
+		SepBuf_AddBytesBetween(buf, word + lhsLen, wordEnd);
 		args->matched = true;
 		return;
 	}
 
 	if (args->pflags.anchorEnd) {
-		const char *start;
-
-		if (wordLen < args->lhsLen)
+		if (wordLen < lhsLen)
 			goto nosub;
-
-		start = word + (wordLen - args->lhsLen);
-		if (memcmp(start, args->lhs, args->lhsLen) != 0)
+		if (memcmp(wordEnd - lhsLen, args->lhs.start, lhsLen) != 0)
 			goto nosub;
 
 		/* :S,suffix$,replacement, */
-		SepBuf_AddBytesBetween(buf, word, start);
-		SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
+		SepBuf_AddBytesBetween(buf, word, wordEnd - lhsLen);
+		SepBuf_AddBytesBetween(buf, args->rhs.start, args->rhs.end);
 		args->matched = true;
 		return;
 	}
 
-	if (args->lhs[0] == '\0')
+	if (args->lhs.start[0] == '\0')
 		goto nosub;
 
 	/* unanchored case, may match more than once */
-	while ((match = strstr(word, args->lhs)) != NULL) {
+	while ((match = Substring_Find(Substring_Init(word, wordEnd),
+	args->lhs)) != NULL) {
 		SepBuf_AddBytesBetween(buf, word, match);
-		SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
+		SepBuf_AddBytesBetween(buf, args->rhs.start, args->rhs.end);
 		args->matched = true;
-		wordLen -= (size_t)(match - word) + args->lhsLen;
-		word += (size_t)(match - word) + args->lhsLen;
-		if (wordLen == 0 || !args->pflags.subGlobal)
+		word += (size_t)(match - word) + lhsLen;
+		if (word == wordEnd || !args->pflags.subGlobal)
 			break;
 	}
 nosub:
-	SepBuf_AddBytes(buf, word, wordLen);
+	SepBuf_AddBytesBetween(buf, word, wordEnd);
 }
 
 #ifndef NO_REGEX
@@ -2189,9 +2198,9 @@ ParseModifierPartSubst(
 VarEvalMode emode,
 ModChain *ch,
 char **out_part,
-/* Optionally stores the length of the returned string, just to save
+/* Optionally stores the end of the returned strin

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 13:35:56 UTC 2021

Modified Files:
src/usr.bin/make: nonints.h var.c
src/usr.bin/make/unit-tests: cond-func-empty.mk varmod-defined.mk
varmod-ifelse.mk varmod-loop.mk

Log Message:
make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode.  There were some
comments and tests that still referred to the old names.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.916 -r1.917 src/usr.bin/make/var.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/cond-func-empty.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod-defined.mk \
src/usr.bin/make/unit-tests/varmod-ifelse.mk
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod-loop.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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.212 src/usr.bin/make/nonints.h:1.213
--- src/usr.bin/make/nonints.h:1.212	Sun Apr 11 12:06:53 2021
+++ src/usr.bin/make/nonints.h	Sun Apr 11 13:35:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.212 2021/04/11 12:06:53 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.213 2021/04/11 13:35:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -292,7 +292,7 @@ typedef enum VarParseResult {
 	 * information to them, for now.
 	 *
 	 * TODO: Instead of having this special return value, rather ensure
-	 *  that VarEvalFlags.keepUndef is processed properly.
+	 *  that VARE_EVAL_KEEP_UNDEF is processed properly.
 	 */
 	VPR_UNDEF
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.916 src/usr.bin/make/var.c:1.917
--- src/usr.bin/make/var.c:1.916	Sun Apr 11 12:46:54 2021
+++ src/usr.bin/make/var.c	Sun Apr 11 13:35:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.916 2021/04/11 12:46:54 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.917 2021/04/11 13:35:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.916 2021/04/11 12:46:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.917 2021/04/11 13:35:56 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -272,11 +272,11 @@ char var_Error[] = "";
 
 /*
  * Special return value for Var_Parse, indicating an undefined variable in
- * a case where VarEvalFlags.undefErr is not set.  This undefined variable is
+ * a case where VARE_UNDEFERR is not set.  This undefined variable is
  * typically a dynamic variable such as ${.TARGET}, whose expansion needs to
  * be deferred until it is defined in an actual target.
  *
- * See VarEvalFlags.keepUndef.
+ * See VARE_EVAL_KEEP_UNDEF.
  */
 static char varUndefined[] = "";
 
@@ -2253,7 +2253,7 @@ ParseModifierPartSubst(
 
 		/*
 		 * XXX: This whole block is very similar to Var_Parse without
-		 * VarEvalFlags.wantRes.  There may be subtle edge cases
+		 * VARE_WANTRES.  There may be subtle edge cases
 		 * though that are not yet covered in the unit tests and that
 		 * are parsed differently, depending on whether they are
 		 * evaluated or not.
@@ -4352,18 +4352,18 @@ FreeEnvVar(Var *v, FStr *inout_val)
 }
 
 #if __STDC_VERSION__ >= 199901L
-#define Expr_Literal(name, value, eflags, scope, defined) \
-	{ name, value, eflags, scope, defined }
+#define Expr_Literal(name, value, emode, scope, defined) \
+	{ name, value, emode, scope, defined }
 #else
 MAKE_INLINE Expr
 Expr_Literal(const char *name, FStr value,
-	 VarEvalFlags eflags, GNode *scope, ExprDefined defined)
+	 VarEvalMode emode, GNode *scope, ExprDefined defined)
 {
 	Expr expr;
 
 	expr.name = name;
 	expr.value = value;
-	expr.eflags = eflags;
+	expr.emode = emode;
 	expr.scope = scope;
 	expr.defined = defined;
 	return expr;
@@ -4412,7 +4412,7 @@ Var_Parse_FastLane(const char **pp, VarE
  *			point to the "y" of "empty(VARNAME:Modifiers)", which
  *			is syntactically the same.
  *	scope		The scope for finding variables
- *	eflags		Control the exact details of parsing
+ *	emode		Controls the exact details of parsing and evaluation
  *
  * Output:
  *	*pp		The position where to continue parsing.
@@ -4424,13 +4424,13 @@ Var_Parse_FastLane(const char **pp, VarE
  *	*out_val	The value of the variable expression, never NULL.
  *	*out_val	var_Error if there was a parse error.
  *	*out_val	var_Error if the base variable of the expression was
- *			undefined, eflags has undefErr set, and none of
+ *			undefined, emode is VARE_UNDEFERR, and none of
  *			the modifiers turned the undefined expression into a
  *			defined expression.
  *			XXX: It is not guaranteed that an error message has
  *			been printed.
  *	*out_val	varUndefined if the base variable of the expression
- *			was undefined, eflags did not h

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 12:46:55 UTC 2021

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

Log Message:
make: avoid allocating memory for simple variable names

The main change is in ParseVarname, where a Buffer is replaced with the
newly introduced LazyBuf.  LazyBuf is inspired by
https://golang.org/src/path/path.go.

In CanonicalVarname, the pre-comparison of the first letter of the
variable name is no longer necessary.  GCC 9 optimizes a fixed-length
memcmp so well that the code can finally be written to target human
readers, leaving the optimization to the compiler.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/make/hash.c
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/make/hash.h
cvs rdiff -u -r1.915 -r1.916 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/hash.c
diff -u src/usr.bin/make/hash.c:1.63 src/usr.bin/make/hash.c:1.64
--- src/usr.bin/make/hash.c:1.63	Sat Apr  3 14:39:02 2021
+++ src/usr.bin/make/hash.c	Sun Apr 11 12:46:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.63 2021/04/03 14:39:02 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.64 2021/04/11 12:46:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -74,7 +74,7 @@
 #include "make.h"
 
 /*	"@(#)hash.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: hash.c,v 1.63 2021/04/03 14:39:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.64 2021/04/11 12:46:54 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -84,7 +84,7 @@ MAKE_RCSID("$NetBSD: hash.c,v 1.63 2021/
 
 /* This hash function matches Gosling's Emacs and java.lang.String. */
 static unsigned int
-hash(const char *key, size_t *out_keylen)
+Hash_String(const char *key, size_t *out_keylen)
 {
 	unsigned int h;
 	const char *p;
@@ -98,10 +98,17 @@ hash(const char *key, size_t *out_keylen
 	return h;
 }
 
+/* This hash function matches Gosling's Emacs and java.lang.String. */
 unsigned int
-Hash_Hash(const char *key)
+Hash_Substring(Substring key)
 {
-	return hash(key, NULL);
+	unsigned int h;
+	const char *p;
+
+	h = 0;
+	for (p = key.start; p != key.end; p++)
+		h = 31 * h + (unsigned char)*p;
+	return h;
 }
 
 static HashEntry *
@@ -126,6 +133,41 @@ HashTable_Find(HashTable *t, unsigned in
 	return e;
 }
 
+static bool
+HashEntry_KeyEquals(const HashEntry *he, Substring key)
+{
+	const char *heKey, *p;
+
+	heKey = he->key;
+	for (p = key.start; p != key.end; p++, heKey++)
+		if (*p != *heKey || *heKey == '\0')
+			return false;
+	return *heKey == '\0';
+}
+
+static HashEntry *
+HashTable_FindEntryBySubstring(HashTable *t, Substring key, unsigned int h)
+{
+	HashEntry *e;
+	unsigned int chainlen = 0;
+
+#ifdef DEBUG_HASH_LOOKUP
+	DEBUG4(HASH, "%s: %p h=%08x key=%.*s\n", __func__, t, h,
+	(int)Substring_Length(key), key.start);
+#endif
+
+	for (e = t->buckets[h & t->bucketsMask]; e != NULL; e = e->next) {
+		chainlen++;
+		if (e->key_hash == h && HashEntry_KeyEquals(e, key))
+			break;
+	}
+
+	if (chainlen > t->maxchain)
+		t->maxchain = chainlen;
+
+	return e;
+}
+
 /* Set up the hash table. */
 void
 HashTable_Init(HashTable *t)
@@ -171,7 +213,7 @@ HashTable_Done(HashTable *t)
 HashEntry *
 HashTable_FindEntry(HashTable *t, const char *key)
 {
-	unsigned int h = hash(key, NULL);
+	unsigned int h = Hash_String(key, NULL);
 	return HashTable_Find(t, h, key);
 }
 
@@ -188,9 +230,9 @@ HashTable_FindValue(HashTable *t, const 
  * or return NULL.
  */
 void *
-HashTable_FindValueHash(HashTable *t, const char *key, unsigned int h)
+HashTable_FindValueBySubstringHash(HashTable *t, Substring key, unsigned int h)
 {
-	HashEntry *he = HashTable_Find(t, h, key);
+	HashEntry *he = HashTable_FindEntryBySubstring(t, key, h);
 	return he != NULL ? he->value : NULL;
 }
 
@@ -239,7 +281,7 @@ HashEntry *
 HashTable_CreateEntry(HashTable *t, const char *key, bool *out_isNew)
 {
 	size_t keylen;
-	unsigned int h = hash(key, &keylen);
+	unsigned int h = Hash_String(key, &keylen);
 	HashEntry *he = HashTable_Find(t, h, key);
 
 	if (he != NULL) {

Index: src/usr.bin/make/hash.h
diff -u src/usr.bin/make/hash.h:1.39 src/usr.bin/make/hash.h:1.40
--- src/usr.bin/make/hash.h:1.39	Sat Apr  3 11:08:40 2021
+++ src/usr.bin/make/hash.h	Sun Apr 11 12:46:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.39 2021/04/03 11:08:40 rillig Exp $	*/
+/*	$NetBSD: hash.h,v 1.40 2021/04/11 12:46:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -124,8 +124,8 @@ void HashTable_Init(HashTable *);
 void HashTable_Done(HashTable *);
 HashEntry *HashTable_FindEntry(HashTable *, const char *);
 void *HashTable_FindValue(HashTable *, const char *);
-unsigned int Hash_Hash(const char *);
-void *HashTable_FindValueHash(HashTable *, const char *, unsigned int);
+unsigned int Ha

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 12:06:53 UTC 2021

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

Log Message:
make: add types Substring and LazyBuf

These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/usr.bin/make/make.h
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/make/nonints.h
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/str.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/make.h
diff -u src/usr.bin/make/make.h:1.260 src/usr.bin/make/make.h:1.261
--- src/usr.bin/make/make.h:1.260	Sun Apr  4 10:05:08 2021
+++ src/usr.bin/make/make.h	Sun Apr 11 12:06:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.260 2021/04/04 10:05:08 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.261 2021/04/11 12:06:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -149,10 +149,11 @@ typedef unsigned int Boolean;
 
 #include "lst.h"
 #include "enum.h"
+#include "make_malloc.h"
+#include "str.h"
 #include "hash.h"
 #include "config.h"
 #include "buf.h"
-#include "make_malloc.h"
 
 /*
  * The typical flow of states is:

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.211 src/usr.bin/make/nonints.h:1.212
--- src/usr.bin/make/nonints.h:1.211	Sun Apr  4 11:56:43 2021
+++ src/usr.bin/make/nonints.h	Sun Apr 11 12:06:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.211 2021/04/04 11:56:43 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.212 2021/04/11 12:06:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -166,112 +166,6 @@ void Parse_SetInput(const char *, int, i
 void Parse_MainName(GNodeList *);
 int Parse_GetFatals(void);
 
-/* str.c */
-
-/* A read-only string that may need to be freed after use. */
-typedef struct FStr {
-	const char *str;
-	void *freeIt;
-} FStr;
-
-/* A modifiable string that may need to be freed after use. */
-typedef struct MFStr {
-	char *str;
-	void *freeIt;
-} MFStr;
-
-typedef struct Words {
-	char **words;
-	size_t len;
-	void *freeIt;
-} Words;
-
-#if __STDC_VERSION__ >= 199901L
-#  define FStr_Literal(str, freeIt) (FStr) { str, freeIt }
-#else
-MAKE_INLINE FStr
-FStr_Literal(const char *str, void *freeIt)
-{
-	FStr fstr;
-	fstr.str = str;
-	fstr.freeIt = freeIt;
-	return fstr;
-}
-#endif
-
-/* Return a string that is the sole owner of str. */
-MAKE_INLINE FStr
-FStr_InitOwn(char *str)
-{
-	return FStr_Literal(str, str);
-}
-
-/* Return a string that refers to the shared str. */
-MAKE_INLINE FStr
-FStr_InitRefer(const char *str)
-{
-	return FStr_Literal(str, NULL);
-}
-
-MAKE_INLINE void
-FStr_Done(FStr *fstr)
-{
-	free(fstr->freeIt);
-#ifdef CLEANUP
-	fstr->str = NULL;
-	fstr->freeIt = NULL;
-#endif
-}
-
-#if __STDC_VERSION__ >= 199901L
-#  define MFStr_Literal(str, freeIt) (MFStr) { str, freeIt }
-#else
-MAKE_INLINE MFStr
-MFStr_Literal(char *str, void *freeIt)
-{
-	MFStr mfstr;
-	mfstr.str = str;
-	mfstr.freeIt = freeIt;
-	return mfstr;
-}
-#endif
-
-/* Return a string that is the sole owner of str. */
-MAKE_INLINE MFStr
-MFStr_InitOwn(char *str)
-{
-	return MFStr_Literal(str, str);
-}
-
-/* Return a string that refers to the shared str. */
-MAKE_INLINE MFStr
-MFStr_InitRefer(char *str)
-{
-	return MFStr_Literal(str, NULL);
-}
-
-MAKE_INLINE void
-MFStr_Done(MFStr *mfstr)
-{
-	free(mfstr->freeIt);
-#ifdef CLEANUP
-	mfstr->str = NULL;
-	mfstr->freeIt = NULL;
-#endif
-}
-
-Words Str_Words(const char *, bool);
-MAKE_INLINE void
-Words_Free(Words w)
-{
-	free(w.words);
-	free(w.freeIt);
-}
-
-char *str_concat2(const char *, const char *);
-char *str_concat3(const char *, const char *, const char *);
-char *str_concat4(const char *, const char *, const char *, const char *);
-bool Str_Match(const char *, const char *);
 
 /* suff.c */
 void Suff_Init(void);

Added files:

Index: src/usr.bin/make/str.h
diff -u /dev/null src/usr.bin/make/str.h:1.1
--- /dev/null	Sun Apr 11 12:06:53 2021
+++ src/usr.bin/make/str.h	Sun Apr 11 12:06:53 2021
@@ -0,0 +1,269 @@
+/*	$NetBSD: str.h,v 1.1 2021/04/11 12:06:53 rillig Exp $	*/
+
+/*
+ Copyright (c) 2021 Roland Illig 
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS

CVS commit: src/usr.bin/make

2021-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 11 11:41:27 UTC 2021

Modified Files:
src/usr.bin/make: Makefile

Log Message:
make: clean up Makefile

The dependencies on the header files are handled by 'make depend'.  They
do not need to be spelled out.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/make/Makefile

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/Makefile
diff -u src/usr.bin/make/Makefile:1.113 src/usr.bin/make/Makefile:1.114
--- src/usr.bin/make/Makefile:1.113	Mon Feb 22 20:45:46 2021
+++ src/usr.bin/make/Makefile	Sun Apr 11 11:41:27 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.113 2021/02/22 20:45:46 rillig Exp $
+#	$NetBSD: Makefile,v 1.114 2021/04/11 11:41:27 rillig Exp $
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 
 PROG=	make
@@ -23,20 +23,6 @@ SRCS+=  targ.c
 SRCS+=  trace.c
 SRCS+=  var.c
 SRCS+=  util.c
-HDRS=   buf.h
-HDRS+=  config.h
-HDRS+=  dir.h
-HDRS+=  enum.h
-HDRS+=  hash.h
-HDRS+=  job.h
-HDRS+=  lst.h
-HDRS+=  make.h
-HDRS+=  make_malloc.h
-HDRS+=  meta.h
-HDRS+=  metachar.h
-HDRS+=  nonints.h
-HDRS+=  pathnames.h
-HDRS+=  trace.h
 
 # Whether to generate a coverage report after running the tests.
 USE_COVERAGE?=	no		# works only with gcc; clang9 fails to link
@@ -128,9 +114,7 @@ SUBDIR+=	unit-tests
 .endif
 
 LINTFLAGS+=	-T	# strict bool mode, available since 2021-01-11
-
-${SRCS:M*.c:.c=.o}: ${HDRS}
-CLEANFILES+=	*.o
+CLEANFILES+=	*.o	# for filemon objects
 
 COPTS.arch.c+=	${GCC_NO_FORMAT_TRUNCATION}
 COPTS.dir.c+=	${GCC_NO_FORMAT_TRUNCATION}



CVS commit: src/usr.bin/make

2021-04-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 10 22:40:34 UTC 2021

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

Log Message:
make: fix out-of-bounds read in Var_Parse_FastLane (since 30 minutes)

This bug made the test varmod-edge.mk fail sometimes with varying error
messages, as can be expected for an out-of-bounds read.


To generate a diff of this commit:
cvs rdiff -u -r1.914 -r1.915 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.914 src/usr.bin/make/var.c:1.915
--- src/usr.bin/make/var.c:1.914	Sat Apr 10 22:35:02 2021
+++ src/usr.bin/make/var.c	Sat Apr 10 22:40:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.914 2021/04/10 22:35:02 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.915 2021/04/10 22:40:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.914 2021/04/10 22:35:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.915 2021/04/10 22:40:34 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4401,7 +4401,8 @@ Var_Parse_FastLane(const char **pp, VarE
 		return false;
 
 	p += 4;
-	while (*p != '$' && *p != '{' && *p != ':' && *p != '\\' && *p != '}')
+	while (*p != '$' && *p != '{' && *p != ':' && *p != '\\' &&
+	   *p != '}' && *p != '\0')
 		p++;
 	if (*p != '}')
 		return false;



CVS commit: src/usr.bin/make

2021-04-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 10 22:35:02 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: vardebug.exp varname-empty.exp

Log Message:
make: reword debug log message for empty variable name

The function names did not match anymore, after one of the many
refactorings in the last few months.


To generate a diff of this commit:
cvs rdiff -u -r1.913 -r1.914 src/usr.bin/make/var.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varname-empty.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.913 src/usr.bin/make/var.c:1.914
--- src/usr.bin/make/var.c:1.913	Sat Apr 10 22:09:53 2021
+++ src/usr.bin/make/var.c	Sat Apr 10 22:35:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.913 2021/04/10 22:09:53 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.914 2021/04/10 22:35:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.913 2021/04/10 22:09:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.914 2021/04/10 22:35:02 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1040,8 +1040,9 @@ Var_SetExpandWithFlags(GNode *scope, con
 	}
 
 	if (varname.str[0] == '\0') {
-		DEBUG2(VAR, "Var_Set(\"%s\", \"%s\", ...) "
-			"name expands to empty string - ignored\n",
+		DEBUG2(VAR,
+		"Var_SetExpand: variable name \"%s\" expands "
+		"to empty string, with value \"%s\" - ignored\n",
 		unexpanded_name, val);
 	} else
 		Var_SetWithFlags(scope, varname.str, val, flags);
@@ -1165,9 +1166,9 @@ Var_AppendExpand(GNode *scope, const cha
 		/* TODO: handle errors */
 		xname = FStr_InitOwn(expanded);
 		if (expanded[0] == '\0') {
-			/* TODO: update function name in the debug message */
-			DEBUG2(VAR, "Var_Append(\"%s\", \"%s\", ...) "
-"name expands to empty string - ignored\n",
+			DEBUG2(VAR,
+			"Var_AppendExpand: variable name \"%s\" expands "
+			"to empty string, with value \"%s\" - ignored\n",
 			name, val);
 			FStr_Done(&xname);
 			return;

Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u src/usr.bin/make/unit-tests/vardebug.exp:1.25 src/usr.bin/make/unit-tests/vardebug.exp:1.26
--- src/usr.bin/make/unit-tests/vardebug.exp:1.25	Sat Apr 10 22:09:54 2021
+++ src/usr.bin/make/unit-tests/vardebug.exp	Sat Apr 10 22:35:02 2021
@@ -5,8 +5,8 @@ Global: VAR = added
 Global: VAR = overwritten
 Global:delete VAR
 Global:delete VAR (not found)
-Var_Set("${:U}", "empty name", ...) name expands to empty string - ignored
-Var_Append("${:U}", "empty name", ...) name expands to empty string - ignored
+Var_SetExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored
+Var_AppendExpand: variable name "${:U}" expands to empty string, with value "empty name" - ignored
 Global: FROM_CMDLINE = overwritten ignored!
 Global: VAR = 1
 Global: VAR = 1 2

Index: src/usr.bin/make/unit-tests/varname-empty.exp
diff -u src/usr.bin/make/unit-tests/varname-empty.exp:1.14 src/usr.bin/make/unit-tests/varname-empty.exp:1.15
--- src/usr.bin/make/unit-tests/varname-empty.exp:1.14	Sat Apr 10 22:09:54 2021
+++ src/usr.bin/make/unit-tests/varname-empty.exp	Sat Apr 10 22:35:02 2021
@@ -1,5 +1,5 @@
-Var_Set("${:U}", "cmdline-u", ...) name expands to empty string - ignored
-Var_Set("", "cmdline-plain", ...) name expands to empty string - ignored
+Var_SetExpand: variable name "${:U}" expands to empty string, with value "cmdline-u" - ignored
+Var_SetExpand: variable name "" expands to empty string, with value "cmdline-plain" - ignored
 Global: .CURDIR = 
 Var_Parse: ${MAKE_OBJDIR_CHECK_WRITABLE:U} (eval)
 Evaluating modifier ${MAKE_OBJDIR_CHECK_WRITABLE:U} on value "" (eval, undefined)
@@ -14,14 +14,14 @@ Global: .MAKE.MAKEFILES = varname-empty.
 Global: .PARSEFILE = varname-empty.mk
 Global:delete .INCLUDEDFROMDIR (not found)
 Global:delete .INCLUDEDFROMFILE (not found)
-Var_Set("", "default", ...) name expands to empty string - ignored
-Var_Set("", "assigned", ...) name expands to empty string - ignored
+Var_SetExpand: variable name "" expands to empty string, with value "default" - ignored
+Var_SetExpand: variable name "" expands to empty string, with value "assigned" - ignored
 SetVar: variable name is empty - ignored
-Var_Set("", "", ...) name expands to empty string - ignored
-Var_Set("", "subst", ...) name expands to empty string - ignored
-Var_Set("", "shell-output", ...) name expands to empty string - ignored
-Var_Set("${:U}", "assigned indirectly", ...) name expands to empty string - ignored
-Var_Append("${:U}", "appended indirectly", ...) name expands to empty string - ignored
+Var_SetExpand: variable name "" expands to e

CVS commit: src/usr.bin/make

2021-04-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Apr 10 22:09:54 UTC 2021

Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: vardebug.exp varmod-indirect.exp
varmod-match-escape.exp varname-empty.exp varname.exp

Log Message:
make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.


To generate a diff of this commit:
cvs rdiff -u -r1.912 -r1.913 src/usr.bin/make/var.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.14 -r1.15 \
src/usr.bin/make/unit-tests/varmod-match-escape.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varname-empty.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varname.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.912 src/usr.bin/make/var.c:1.913
--- src/usr.bin/make/var.c:1.912	Tue Apr  6 01:38:39 2021
+++ src/usr.bin/make/var.c	Sat Apr 10 22:09:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.912 2021/04/06 01:38:39 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.913 2021/04/10 22:09:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.912 2021/04/06 01:38:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.913 2021/04/10 22:09:53 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -437,6 +437,11 @@ VarFind(const char *name, GNode *scope, 
 	if (var == NULL) {
 		char *env;
 
+		/*
+		 * TODO: try setting an environment variable with the empty
+		 *  name, which should be technically possible, just to see
+		 *  how make reacts.  All .for loops should be broken then.
+		 */
 		if ((env = getenv(name)) != NULL) {
 			char *varname = bmake_strdup(name);
 			return VarNew(FStr_InitOwn(varname), env, true, false);
@@ -4381,6 +4386,34 @@ Expr_Literal(const char *name, FStr valu
 #endif
 
 /*
+ * Expressions of the form ${:U...} with a trivial value are often generated
+ * by .for loops and are boring, therefore parse and evaluate them in a fast
+ * lane without debug logging.
+ */
+static bool
+Var_Parse_FastLane(const char **pp, VarEvalMode emode, FStr *out_value)
+{
+	const char *p;
+
+	p = *pp;
+	if (!(p[0] == '$' && p[1] == '{' && p[2] == ':' && p[3] == 'U'))
+		return false;
+
+	p += 4;
+	while (*p != '$' && *p != '{' && *p != ':' && *p != '\\' && *p != '}')
+		p++;
+	if (*p != '}')
+		return false;
+
+	if (emode == VARE_PARSE_ONLY)
+		*out_value = FStr_InitRefer("");
+	else
+		*out_value = FStr_InitOwn(bmake_strsedup(*pp + 4, p));
+	*pp = p + 1;
+	return true;
+}
+
+/*
  * Given the start of a variable expression (such as $v, $(VAR),
  * ${VAR:Mpattern}), extract the variable name and value, and the modifiers,
  * if any.  While doing that, apply the modifiers to the value of the
@@ -4439,6 +4472,9 @@ Var_Parse(const char **pp, GNode *scope,
 	Expr expr = Expr_Literal(NULL, FStr_InitRefer(NULL), emode,
 	scope, DEF_REGULAR);
 
+	if (Var_Parse_FastLane(pp, emode, out_val))
+		return VPR_OK;
+
 	DEBUG2(VAR, "Var_Parse: %s (%s)\n", start, VarEvalMode_Name[emode]);
 
 	*out_val = FStr_InitRefer(NULL);

Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u src/usr.bin/make/unit-tests/vardebug.exp:1.24 src/usr.bin/make/unit-tests/vardebug.exp:1.25
--- src/usr.bin/make/unit-tests/vardebug.exp:1.24	Tue Apr  6 01:38:39 2021
+++ src/usr.bin/make/unit-tests/vardebug.exp	Sat Apr 10 22:09:54 2021
@@ -5,13 +5,7 @@ Global: VAR = added
 Global: VAR = overwritten
 Global:delete VAR
 Global:delete VAR (not found)
-Var_Parse: ${:U} (eval)
-Evaluating modifier ${:U} on value "" (eval, undefined)
-Result of ${:U} is "" (eval, defined)
 Var_Set("${:U}", "empty name", ...) name expands to empty string - ignored
-Var_Parse: ${:U} (eval)
-Evaluating modifier ${:U} on value "" (eval, undefined)
-Result of ${:U} is "" (eval, defined)
 Var_Append("${:U}", "empty name", ...) name expands to empty string - ignored
 Global: FROM_CMDLINE = overwritten ignored!
 Global: VAR = 1
@@ -46,9 +40,6 @@ Result of ${VAR:Q} is "1\ 2\ 3"
 Var_Parse: ${:Uvalue:${:UM*e}:Mvalu[e]} (eval-defined)
 Evaluating modifier ${:U...} on value "" (eval-defined, undefined)
 Result of ${:Uvalue} is "value" (eval-defined, defined)
-Var_Parse: ${:UM*e}:Mvalu[e]} (eval-defined)
-Evaluating modifier ${:U...} on value "" (eval-defined, undefined)
-Result of ${:UM*e} is "M*e" (eval-defined, defined)
 Indirect modifier "M*e" from "${:UM*e}"
 Evaluating modifier ${:M...}

  1   2   3   4   5   6   7   8   9   10   >