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 unified 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $ */ 1/* $NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,31 +27,31 @@ @@ -27,31 +27,31 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <stdint.h> 35#include <stdint.h>
36 36
37#include "make.h" 37#include "make.h"
38 38
39#ifndef MAKE_NATIVE 39#ifndef MAKE_NATIVE
40static char rcsid[] = "$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $"; 40static char rcsid[] = "$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $";
41#else 41#else
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43#ifndef lint 43#ifndef lint
44__RCSID("$NetBSD: lst.c,v 1.59 2020/08/30 21:20:06 rillig Exp $"); 44__RCSID("$NetBSD: lst.c,v 1.60 2020/08/31 05:56:02 rillig Exp $");
45#endif /* not lint */ 45#endif /* not lint */
46#endif 46#endif
47 47
48struct ListNode { 48struct ListNode {
49 struct ListNode *prev; /* previous element in list */ 49 struct ListNode *prev; /* previous element in list */
50 struct ListNode *next; /* next in list */ 50 struct ListNode *next; /* next in list */
51 uint8_t useCount; /* Count of functions using the node. 51 uint8_t useCount; /* Count of functions using the node.
52 * node may not be deleted until count 52 * node may not be deleted until count
53 * goes to 0 */ 53 * goes to 0 */
54 Boolean deleted; /* List node should be removed when done */ 54 Boolean deleted; /* List node should be removed when done */
55 union { 55 union {
56 void *datum; /* datum associated with this element */ 56 void *datum; /* datum associated with this element */
57 const GNode *gnode; /* alias, just for debugging */ 57 const GNode *gnode; /* alias, just for debugging */
@@ -532,32 +532,27 @@ Lst_AppendAll(Lst dst, Lst src) @@ -532,32 +532,27 @@ Lst_AppendAll(Lst dst, Lst src)
532 * between Lst_Open() and Lst_Close(). 532 * between Lst_Open() and Lst_Close().
533 * 533 *
534 * The sequential functions access the list in a slightly different way. 534 * The sequential functions access the list in a slightly different way.
535 * CurPtr points to their idea of the current node in the list and they 535 * CurPtr points to their idea of the current node in the list and they
536 * access the list based on it. 536 * access the list based on it.
537 */ 537 */
538 538
539/* Open a list for sequential access. A list can still be searched, etc., 539/* Open a list for sequential access. A list can still be searched, etc.,
540 * without confusing these functions. */ 540 * without confusing these functions. */
541void 541void
542Lst_Open(Lst list) 542Lst_Open(Lst list)
543{ 543{
544 assert(list != NULL); 544 assert(list != NULL);
545 545 assert(!list->isOpen);
546 /* XXX: This assertion fails for NetBSD's "build.sh -j1 tools", somewhere 
547 * between "dependall ===> compat" and "dependall ===> binstall". 
548 * Building without the "-j1" succeeds though. */ 
549 if (DEBUG(LINT) && list->isOpen) 
550 Parse_Error(PARSE_WARNING, "Internal inconsistency: list opened twice"); 
551 546
552 list->isOpen = TRUE; 547 list->isOpen = TRUE;
553 list->lastAccess = LstIsEmpty(list) ? Head : Unknown; 548 list->lastAccess = LstIsEmpty(list) ? Head : Unknown;
554 list->curr = NULL; 549 list->curr = NULL;
555} 550}
556 551
557/* Return the next node for the given list, or NULL if the end has been 552/* Return the next node for the given list, or NULL if the end has been
558 * reached. */ 553 * reached. */
559LstNode 554LstNode
560Lst_Next(Lst list) 555Lst_Next(Lst list)
561{ 556{
562 LstNode node; 557 LstNode node;
563 558

cvs diff -r1.140 -r1.141 src/usr.bin/make/suff.c (expand / switch to unified 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,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $"; 72static char rcsid[] = "$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
78#else 78#else
79__RCSID("$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $"); 79__RCSID("$NetBSD: suff.c,v 1.141 2020/08/31 05:56:02 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * suff.c -- 85 * suff.c --
86 * Functions to maintain suffix lists and find implicit dependents 86 * Functions to maintain suffix lists and find implicit dependents
87 * using suffix transformation rules 87 * using suffix transformation rules
88 * 88 *
89 * Interface: 89 * Interface:
90 * Suff_Init Initialize all things to do with suffixes. 90 * Suff_Init Initialize all things to do with suffixes.
91 * 91 *
92 * Suff_End Cleanup the module 92 * Suff_End Cleanup the module
@@ -220,27 +220,26 @@ static Suff *suffNull; /* The NULL  @@ -220,27 +220,26 @@ static Suff *suffNull; /* The NULL
220static Suff *emptySuff; /* The empty suffix required for POSIX 220static Suff *emptySuff; /* The empty suffix required for POSIX
221 * single-suffix transformation rules */ 221 * single-suffix transformation rules */
222 222
223 223
224static void SuffUnRef(void *, void *); 224static void SuffUnRef(void *, void *);
225static void SuffFree(void *); 225static void SuffFree(void *);
226static void SuffInsert(Lst, Suff *); 226static void SuffInsert(Lst, Suff *);
227static void SuffRemove(Lst, Suff *); 227static void SuffRemove(Lst, Suff *);
228static Boolean SuffParseTransform(char *, Suff **, Suff **); 228static Boolean SuffParseTransform(char *, Suff **, Suff **);
229static int SuffRebuildGraph(void *, void *); 229static int SuffRebuildGraph(void *, void *);
230static int SuffScanTargets(void *, void *); 230static int SuffScanTargets(void *, void *);
231static int SuffAddSrc(void *, void *); 231static int SuffAddSrc(void *, void *);
232static void SuffAddLevel(Lst, Src *); 232static void SuffAddLevel(Lst, Src *);
233static Src *SuffFindCmds(Src *, Lst); 
234static void SuffExpandChildren(LstNode, GNode *); 233static void SuffExpandChildren(LstNode, GNode *);
235static void SuffExpandWildcards(LstNode, GNode *); 234static void SuffExpandWildcards(LstNode, GNode *);
236static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *); 235static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
237static void SuffFindDeps(GNode *, Lst); 236static void SuffFindDeps(GNode *, Lst);
238static void SuffFindArchiveDeps(GNode *, Lst); 237static void SuffFindArchiveDeps(GNode *, Lst);
239static void SuffFindNormalDeps(GNode *, Lst); 238static void SuffFindNormalDeps(GNode *, Lst);
240static int SuffPrintName(void *, void *); 239static int SuffPrintName(void *, void *);
241static int SuffPrintSuff(void *, void *); 240static int SuffPrintSuff(void *, void *);
242static int SuffPrintTrans(void *, void *); 241static int SuffPrintTrans(void *, void *);
243 242
244 /*************** Lst Predicates ****************/ 243 /*************** Lst Predicates ****************/
245/*- 244/*-
246 *----------------------------------------------------------------------- 245 *-----------------------------------------------------------------------
@@ -1222,26 +1221,27 @@ SuffFindCmds(Src *targ, Lst slst) @@ -1222,26 +1221,27 @@ SuffFindCmds(Src *targ, Lst slst)
1222 ret->suff = suff; 1221 ret->suff = suff;
1223 suff->refCount++; 1222 suff->refCount++;
1224 ret->parent = targ; 1223 ret->parent = targ;
1225 ret->node = s; 1224 ret->node = s;
1226 ret->children = 0; 1225 ret->children = 0;
1227 targ->children += 1; 1226 targ->children += 1;
1228#ifdef DEBUG_SRC 1227#ifdef DEBUG_SRC
1229 ret->cp = Lst_Init(); 1228 ret->cp = Lst_Init();
1230 fprintf(debug_file, "3 add %p %p\n", targ, ret); 1229 fprintf(debug_file, "3 add %p %p\n", targ, ret);
1231 Lst_Append(targ->cp, ret); 1230 Lst_Append(targ->cp, ret);
1232#endif 1231#endif
1233 Lst_Append(slst, ret); 1232 Lst_Append(slst, ret);
1234 SUFF_DEBUG1("\tusing existing source %s\n", s->name); 1233 SUFF_DEBUG1("\tusing existing source %s\n", s->name);
 1234 Lst_Close(t->children);
1235 return ret; 1235 return ret;
1236} 1236}
1237 1237
1238/* Expand the names of any children of a given node that contain variable 1238/* Expand the names of any children of a given node that contain variable
1239 * invocations or file wildcards into actual targets. 1239 * invocations or file wildcards into actual targets.
1240 * 1240 *
1241 * The expanded node is removed from the parent's list of children, and the 1241 * The expanded node is removed from the parent's list of children, and the
1242 * parent's unmade counter is decremented, but other nodes may be added. 1242 * parent's unmade counter is decremented, but other nodes may be added.
1243 * 1243 *
1244 * Input: 1244 * Input:
1245 * cln Child to examine 1245 * cln Child to examine
1246 * pgn Parent node being processed 1246 * pgn Parent node being processed
1247 */ 1247 */