Mon Aug 31 05:56:02 2020 UTC ()
make(1): fix unbalanced Lst_Open/Lst_Close in SuffFindCmds

This bug had been there since the initial import of make, on 1993-03-21.
It just never broke the build because of the missing assertion.

https://mail-index.netbsd.org/tech-toolchain/2020/08/30/msg003847.html

The error message "cd: can't cd to include" that I got when I first
applied the fix was unrelated.  It was caused by an extra directory
"include" in src/tools/compat that didn't belong there.  With that
directory removed, running "./build.sh -j8 tools" succeeds as expected.


(rillig)
diff -r1.59 -r1.60 src/usr.bin/make/lst.c
diff -r1.140 -r1.141 src/usr.bin/make/suff.c

cvs diff -r1.59 -r1.60 src/usr.bin/make/lst.c (expand / switch to context diff)
--- src/usr.bin/make/lst.c 2020/08/30 21:20:06 1.59
+++ src/usr.bin/make/lst.c 2020/08/31 05:56:02 1.60
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -542,12 +542,7 @@
 Lst_Open(Lst list)
 {
     assert(list != NULL);
-
-    /* XXX: This assertion fails for NetBSD's "build.sh -j1 tools", somewhere
-     * between "dependall ===> compat" and "dependall ===> binstall".
-     * Building without the "-j1" succeeds though. */
-    if (DEBUG(LINT) && list->isOpen)
-	Parse_Error(PARSE_WARNING, "Internal inconsistency: list opened twice");
+    assert(!list->isOpen);
 
     list->isOpen = TRUE;
     list->lastAccess = LstIsEmpty(list) ? Head : Unknown;

cvs diff -r1.140 -r1.141 src/usr.bin/make/suff.c (expand / switch to context diff)
--- src/usr.bin/make/suff.c 2020/08/30 18:26:41 1.140
+++ src/usr.bin/make/suff.c 2020/08/31 05:56:02 1.141
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -230,7 +230,6 @@
 static int SuffScanTargets(void *, void *);
 static int SuffAddSrc(void *, void *);
 static void SuffAddLevel(Lst, Src *);
-static Src *SuffFindCmds(Src *, Lst);
 static void SuffExpandChildren(LstNode, GNode *);
 static void SuffExpandWildcards(LstNode, GNode *);
 static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
@@ -1232,6 +1231,7 @@
 #endif
     Lst_Append(slst, ret);
     SUFF_DEBUG1("\tusing existing source %s\n", s->name);
+    Lst_Close(t->children);
     return ret;
 }