Sat Apr 27 17:33:47 2024 UTC (12d)
make: simplify freeing of lists


(rillig)
diff -r1.215 -r1.216 src/usr.bin/make/arch.c
diff -r1.107 -r1.108 src/usr.bin/make/lst.c
diff -r1.104 -r1.105 src/usr.bin/make/lst.h
diff -r1.612 -r1.613 src/usr.bin/make/main.c
diff -r1.207 -r1.208 src/usr.bin/make/meta.c
diff -r1.721 -r1.722 src/usr.bin/make/parse.c
diff -r1.180 -r1.181 src/usr.bin/make/targ.c

cvs diff -r1.215 -r1.216 src/usr.bin/make/arch.c (expand / switch to unified diff)

--- src/usr.bin/make/arch.c 2024/02/07 06:43:02 1.215
+++ src/usr.bin/make/arch.c 2024/04/27 17:33:46 1.216
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 rillig Exp $ */ 1/* $NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 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.
@@ -116,54 +116,53 @@ @@ -116,54 +116,53 @@
116#include <sys/types.h> 116#include <sys/types.h>
117#include <sys/stat.h> 117#include <sys/stat.h>
118#include <sys/time.h> 118#include <sys/time.h>
119#include <sys/param.h> 119#include <sys/param.h>
120 120
121#include <ar.h> 121#include <ar.h>
122#include <utime.h> 122#include <utime.h>
123 123
124#include "make.h" 124#include "make.h"
125#include "dir.h" 125#include "dir.h"
126#include "config.h" 126#include "config.h"
127 127
128/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */ 128/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
129MAKE_RCSID("$NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 rillig Exp $"); 129MAKE_RCSID("$NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 rillig Exp $");
130 130
131typedef struct List ArchList; 131typedef struct List ArchList;
132typedef struct ListNode ArchListNode; 132typedef struct ListNode ArchListNode;
133 133
134static ArchList archives; /* The archives we've already examined */ 134static ArchList archives; /* The archives we've already examined */
135 135
136typedef struct Arch { 136typedef struct Arch {
137 char *name; /* Name of archive */ 137 char *name; /* Name of archive */
138 HashTable members; /* All the members of the archive described 138 HashTable members; /* All the members of the archive described
139 * by <name, struct ar_hdr *> key/value pairs */ 139 * by <name, struct ar_hdr *> key/value pairs */
140 char *fnametab; /* Extended name table strings */ 140 char *fnametab; /* Extended name table strings */
141 size_t fnamesize; /* Size of the string table */ 141 size_t fnamesize; /* Size of the string table */
142} Arch; 142} Arch;
143 143
144static FILE *ArchFindMember(const char *, const char *, 144static FILE *ArchFindMember(const char *, const char *,
145 struct ar_hdr *, const char *); 145 struct ar_hdr *, const char *);
146#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__) 146#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
147#define SVR4ARCHIVES 147#define SVR4ARCHIVES
148static int ArchSVR4Entry(Arch *, char *, size_t, FILE *); 148static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
149#endif 149#endif
150 150
151 151
152#ifdef CLEANUP 152#ifdef CLEANUP
153static void 153static void
154ArchFree(void *ap) 154ArchFree(Arch *a)
155{ 155{
156 Arch *a = ap; 
157 HashIter hi; 156 HashIter hi;
158 157
159 /* Free memory from hash entries */ 158 /* Free memory from hash entries */
160 HashIter_Init(&hi, &a->members); 159 HashIter_Init(&hi, &a->members);
161 while (HashIter_Next(&hi) != NULL) 160 while (HashIter_Next(&hi) != NULL)
162 free(hi.entry->value); 161 free(hi.entry->value);
163 162
164 free(a->name); 163 free(a->name);
165 free(a->fnametab); 164 free(a->fnametab);
166 HashTable_Done(&a->members); 165 HashTable_Done(&a->members);
167 free(a); 166 free(a);
168} 167}
169#endif 168#endif
@@ -1060,27 +1059,31 @@ Arch_LibOODate(GNode *gn) @@ -1060,27 +1059,31 @@ Arch_LibOODate(GNode *gn)
1060 1059
1061/* Initialize the archives module. */ 1060/* Initialize the archives module. */
1062void 1061void
1063Arch_Init(void) 1062Arch_Init(void)
1064{ 1063{
1065 Lst_Init(&archives); 1064 Lst_Init(&archives);
1066} 1065}
1067 1066
1068/* Clean up the archives module. */ 1067/* Clean up the archives module. */
1069void 1068void
1070Arch_End(void) 1069Arch_End(void)
1071{ 1070{
1072#ifdef CLEANUP 1071#ifdef CLEANUP
1073 Lst_DoneCall(&archives, ArchFree); 1072 ArchListNode *ln;
 1073
 1074 for (ln = archives.first; ln != NULL; ln = ln->next)
 1075 ArchFree(ln->datum);
 1076 Lst_Done(&archives);
1074#endif 1077#endif
1075} 1078}
1076 1079
1077bool 1080bool
1078Arch_IsLib(GNode *gn) 1081Arch_IsLib(GNode *gn)
1079{ 1082{
1080 static const char armag[] = "!<arch>\n"; 1083 static const char armag[] = "!<arch>\n";
1081 char buf[sizeof armag - 1]; 1084 char buf[sizeof armag - 1];
1082 int fd; 1085 int fd;
1083 1086
1084 if ((fd = open(gn->path, O_RDONLY)) == -1) 1087 if ((fd = open(gn->path, O_RDONLY)) == -1)
1085 return false; 1088 return false;
1086 1089

cvs diff -r1.107 -r1.108 src/usr.bin/make/lst.c (expand / switch to unified diff)

--- src/usr.bin/make/lst.c 2023/12/29 20:43:58 1.107
+++ src/usr.bin/make/lst.c 2024/04/27 17:33:46 1.108
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $ */ 1/* $NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 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.
@@ -24,59 +24,59 @@ @@ -24,59 +24,59 @@
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
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 "make.h" 35#include "make.h"
36 36
37MAKE_RCSID("$NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $"); 37MAKE_RCSID("$NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 rillig Exp $");
38 38
39static ListNode * 39static ListNode *
40LstNodeNew(ListNode *prev, ListNode *next, void *datum) 40LstNodeNew(ListNode *prev, ListNode *next, void *datum)
41{ 41{
42 ListNode *ln = bmake_malloc(sizeof *ln); 42 ListNode *ln = bmake_malloc(sizeof *ln);
43 43
44 ln->prev = prev; 44 ln->prev = prev;
45 ln->next = next; 45 ln->next = next;
46 ln->datum = datum; 46 ln->datum = datum;
47 47
48 return ln; 48 return ln;
49} 49}
50 50
51void 51void
52Lst_Done(List *list) 52Lst_Done(List *list)
53{ 53{
54 ListNode *ln, *next; 54 ListNode *ln, *next;
55 55
56 for (ln = list->first; ln != NULL; ln = next) { 56 for (ln = list->first; ln != NULL; ln = next) {
57 next = ln->next; 57 next = ln->next;
58 free(ln); 58 free(ln);
59 } 59 }
60} 60}
61 61
62void 62void
63Lst_DoneCall(List *list, LstFreeProc freeProc) 63Lst_DoneFree(List *list)
64{ 64{
65 ListNode *ln, *next; 65 ListNode *ln, *next;
66 66
67 for (ln = list->first; ln != NULL; ln = next) { 67 for (ln = list->first; ln != NULL; ln = next) {
68 next = ln->next; 68 next = ln->next;
69 freeProc(ln->datum); 69 free(ln->datum);
70 free(ln); 70 free(ln);
71 } 71 }
72} 72}
73 73
74/* Insert a new node with the datum before the given node. */ 74/* Insert a new node with the datum before the given node. */
75void 75void
76Lst_InsertBefore(List *list, ListNode *ln, void *datum) 76Lst_InsertBefore(List *list, ListNode *ln, void *datum)
77{ 77{
78 ListNode *newNode; 78 ListNode *newNode;
79 79
80 assert(datum != NULL); 80 assert(datum != NULL);
81 81
82 newNode = LstNodeNew(ln->prev, ln, datum); 82 newNode = LstNodeNew(ln->prev, ln, datum);

cvs diff -r1.104 -r1.105 src/usr.bin/make/lst.h (expand / switch to unified diff)

--- src/usr.bin/make/lst.h 2023/12/29 20:43:58 1.104
+++ src/usr.bin/make/lst.h 2024/04/27 17:33:46 1.105
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.h,v 1.104 2023/12/29 20:43:58 rillig Exp $ */ 1/* $NetBSD: lst.h,v 1.105 2024/04/27 17:33:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * 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.
@@ -88,33 +88,30 @@ typedef struct List List; @@ -88,33 +88,30 @@ typedef struct List List;
88typedef struct ListNode ListNode; 88typedef struct ListNode ListNode;
89 89
90struct ListNode { 90struct ListNode {
91 ListNode *prev; /* previous node in list, or NULL */ 91 ListNode *prev; /* previous node in list, or NULL */
92 ListNode *next; /* next node in list, or NULL */ 92 ListNode *next; /* next node in list, or NULL */
93 void *datum; /* datum associated with this element */ 93 void *datum; /* datum associated with this element */
94}; 94};
95 95
96struct List { 96struct List {
97 ListNode *first; 97 ListNode *first;
98 ListNode *last; 98 ListNode *last;
99}; 99};
100 100
101/* Free the datum of a node, called before freeing the node itself. */ 101/* Free the list nodes. */
102typedef void LstFreeProc(void *); 
103 
104/* Free the list nodes, but not the list itself. */ 
105void Lst_Done(List *); 102void Lst_Done(List *);
106/* Free the list nodes, freeing the node data using the given function. */ 103/* Free the list nodes, as well as each node's datum. */
107void Lst_DoneCall(List *, LstFreeProc); 104void Lst_DoneFree(List *);
108 105
109#define LST_INIT { NULL, NULL } 106#define LST_INIT { NULL, NULL }
110 107
111/* Initialize a list, without memory allocation. */ 108/* Initialize a list, without memory allocation. */
112MAKE_INLINE void 109MAKE_INLINE void
113Lst_Init(List *list) 110Lst_Init(List *list)
114{ 111{
115 list->first = NULL; 112 list->first = NULL;
116 list->last = NULL; 113 list->last = NULL;
117} 114}
118 115
119/* Get information about a list */ 116/* Get information about a list */
120 117

cvs diff -r1.612 -r1.613 src/usr.bin/make/main.c (expand / switch to unified diff)

--- src/usr.bin/make/main.c 2024/03/10 02:53:37 1.612
+++ src/usr.bin/make/main.c 2024/04/27 17:33:46 1.613
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $ */ 1/* $NetBSD: main.c,v 1.613 2024/04/27 17:33:46 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.
@@ -101,27 +101,27 @@ @@ -101,27 +101,27 @@
101 101
102#include <errno.h> 102#include <errno.h>
103#include <signal.h> 103#include <signal.h>
104#include <stdarg.h> 104#include <stdarg.h>
105#include <time.h> 105#include <time.h>
106 106
107#include "make.h" 107#include "make.h"
108#include "dir.h" 108#include "dir.h"
109#include "job.h" 109#include "job.h"
110#include "pathnames.h" 110#include "pathnames.h"
111#include "trace.h" 111#include "trace.h"
112 112
113/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ 113/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
114MAKE_RCSID("$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $"); 114MAKE_RCSID("$NetBSD: main.c,v 1.613 2024/04/27 17:33:46 rillig Exp $");
115#if defined(MAKE_NATIVE) 115#if defined(MAKE_NATIVE)
116__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " 116__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
117 "The Regents of the University of California. " 117 "The Regents of the University of California. "
118 "All rights reserved."); 118 "All rights reserved.");
119#endif 119#endif
120 120
121CmdOpts opts; 121CmdOpts opts;
122time_t now; /* Time at start of make */ 122time_t now; /* Time at start of make */
123GNode *defaultNode; /* .DEFAULT node */ 123GNode *defaultNode; /* .DEFAULT node */
124bool allPrecious; /* .PRECIOUS given on a line by itself */ 124bool allPrecious; /* .PRECIOUS given on a line by itself */
125bool deleteOnError; /* .DELETE_ON_ERROR: set */ 125bool deleteOnError; /* .DELETE_ON_ERROR: set */
126 126
127static int maxJobTokens; /* -j argument */ 127static int maxJobTokens; /* -j argument */
@@ -1189,27 +1189,27 @@ ReadBuiltinRules(void) @@ -1189,27 +1189,27 @@ ReadBuiltinRules(void)
1189 _PATH_DEFSYSMK, 1189 _PATH_DEFSYSMK,
1190 &sysMkFiles); 1190 &sysMkFiles);
1191 if (Lst_IsEmpty(&sysMkFiles)) 1191 if (Lst_IsEmpty(&sysMkFiles))
1192 Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK); 1192 Fatal("%s: no system rules (%s).", progname, _PATH_DEFSYSMK);
1193 1193
1194 for (ln = sysMkFiles.first; ln != NULL; ln = ln->next) 1194 for (ln = sysMkFiles.first; ln != NULL; ln = ln->next)
1195 if (ReadMakefile(ln->datum)) 1195 if (ReadMakefile(ln->datum))
1196 break; 1196 break;
1197 1197
1198 if (ln == NULL) 1198 if (ln == NULL)
1199 Fatal("%s: cannot open %s.", 1199 Fatal("%s: cannot open %s.",
1200 progname, (const char *)sysMkFiles.first->datum); 1200 progname, (const char *)sysMkFiles.first->datum);
1201 1201
1202 Lst_DoneCall(&sysMkFiles, free); 1202 Lst_DoneFree(&sysMkFiles);
1203} 1203}
1204 1204
1205static void 1205static void
1206InitMaxJobs(void) 1206InitMaxJobs(void)
1207{ 1207{
1208 char *value; 1208 char *value;
1209 int n; 1209 int n;
1210 1210
1211 if (forceJobs || opts.compatMake || 1211 if (forceJobs || opts.compatMake ||
1212 !Var_Exists(SCOPE_GLOBAL, ".MAKE.JOBS")) 1212 !Var_Exists(SCOPE_GLOBAL, ".MAKE.JOBS"))
1213 return; 1213 return;
1214 1214
1215 value = Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_WANTRES); 1215 value = Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_WANTRES);
@@ -1554,29 +1554,29 @@ main_Run(void) @@ -1554,29 +1554,29 @@ main_Run(void)
1554 /* print the values of any variables requested by the user */ 1554 /* print the values of any variables requested by the user */
1555 doPrintVars(); 1555 doPrintVars();
1556 return false; 1556 return false;
1557 } else { 1557 } else {
1558 return runTargets(); 1558 return runTargets();
1559 } 1559 }
1560} 1560}
1561 1561
1562/* Clean up after making the targets. */ 1562/* Clean up after making the targets. */
1563static void 1563static void
1564main_CleanUp(void) 1564main_CleanUp(void)
1565{ 1565{
1566#ifdef CLEANUP 1566#ifdef CLEANUP
1567 Lst_DoneCall(&opts.variables, free); 1567 Lst_DoneFree(&opts.variables);
1568 Lst_DoneCall(&opts.makefiles, free); 1568 Lst_DoneFree(&opts.makefiles);
1569 Lst_DoneCall(&opts.create, free); 1569 Lst_DoneFree(&opts.create);
1570#endif 1570#endif
1571 1571
1572 if (DEBUG(GRAPH2)) 1572 if (DEBUG(GRAPH2))
1573 Targ_PrintGraph(2); 1573 Targ_PrintGraph(2);
1574 1574
1575 Trace_Log(MAKEEND, NULL); 1575 Trace_Log(MAKEEND, NULL);
1576 1576
1577 if (enterFlagObj) 1577 if (enterFlagObj)
1578 printf("%s: Leaving directory `%s'\n", progname, objdir); 1578 printf("%s: Leaving directory `%s'\n", progname, objdir);
1579 if (opts.enterFlag) 1579 if (opts.enterFlag)
1580 printf("%s: Leaving directory `%s'\n", progname, curdir); 1580 printf("%s: Leaving directory `%s'\n", progname, curdir);
1581 1581
1582#ifdef USE_META 1582#ifdef USE_META

cvs diff -r1.207 -r1.208 src/usr.bin/make/meta.c (expand / switch to unified diff)

--- src/usr.bin/make/meta.c 2023/12/17 09:02:26 1.207
+++ src/usr.bin/make/meta.c 2024/04/27 17:33:46 1.208
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: meta.c,v 1.207 2023/12/17 09:02:26 rillig Exp $ */ 1/* $NetBSD: meta.c,v 1.208 2024/04/27 17:33:46 rillig Exp $ */
2 2
3/* 3/*
4 * Implement 'meta' mode. 4 * Implement 'meta' mode.
5 * Adapted from John Birrell's patches to FreeBSD make. 5 * Adapted from John Birrell's patches to FreeBSD make.
6 * --sjg 6 * --sjg
7 */ 7 */
8/* 8/*
9 * Copyright (c) 2009-2016, Juniper Networks, Inc. 9 * Copyright (c) 2009-2016, Juniper Networks, Inc.
10 * Portions Copyright (c) 2009, John Birrell. 10 * Portions Copyright (c) 2009, John Birrell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -1585,27 +1585,27 @@ meta_oodate(GNode *gn, bool oodate) @@ -1585,27 +1585,27 @@ meta_oodate(GNode *gn, bool oodate)
1585 (cp > gn->path)) { 1585 (cp > gn->path)) {
1586 if (strncmp(curdir, gn->path, (size_t)(cp - gn->path)) != 0) { 1586 if (strncmp(curdir, gn->path, (size_t)(cp - gn->path)) != 0) {
1587 cp = NULL; /* not in .CURDIR */ 1587 cp = NULL; /* not in .CURDIR */
1588 } 1588 }
1589 } 1589 }
1590 if (cp == NULL) { 1590 if (cp == NULL) {
1591 DEBUG1(META, "%s: required but missing\n", fname); 1591 DEBUG1(META, "%s: required but missing\n", fname);
1592 oodate = true; 1592 oodate = true;
1593 needOODATE = true; /* assume the worst */ 1593 needOODATE = true; /* assume the worst */
1594 } 1594 }
1595 } 1595 }
1596 } 1596 }
1597 1597
1598 Lst_DoneCall(&missingFiles, free); 1598 Lst_DoneFree(&missingFiles);
1599 1599
1600 if (oodate && needOODATE) { 1600 if (oodate && needOODATE) {
1601 /* 1601 /*
1602 * Target uses .OODATE which is empty; or we wouldn't be here. 1602 * Target uses .OODATE which is empty; or we wouldn't be here.
1603 * We have decided it is oodate, so .OODATE needs to be set. 1603 * We have decided it is oodate, so .OODATE needs to be set.
1604 * All we can sanely do is set it to .ALLSRC. 1604 * All we can sanely do is set it to .ALLSRC.
1605 */ 1605 */
1606 Var_Delete(gn, OODATE); 1606 Var_Delete(gn, OODATE);
1607 Var_Set(gn, OODATE, GNode_VarAllsrc(gn)); 1607 Var_Set(gn, OODATE, GNode_VarAllsrc(gn));
1608 } 1608 }
1609 1609
1610 oodate_out: 1610 oodate_out:
1611 FStr_Done(&dname); 1611 FStr_Done(&dname);

cvs diff -r1.721 -r1.722 src/usr.bin/make/parse.c (expand / switch to unified diff)

--- src/usr.bin/make/parse.c 2024/04/23 22:51:28 1.721
+++ src/usr.bin/make/parse.c 2024/04/27 17:33:46 1.722
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $ */ 1/* $NetBSD: parse.c,v 1.722 2024/04/27 17:33:46 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.
@@ -95,27 +95,27 @@ @@ -95,27 +95,27 @@
95 */ 95 */
96 96
97#include <sys/types.h> 97#include <sys/types.h>
98#include <sys/stat.h> 98#include <sys/stat.h>
99#include <errno.h> 99#include <errno.h>
100#include <stdarg.h> 100#include <stdarg.h>
101 101
102#include "make.h" 102#include "make.h"
103#include "dir.h" 103#include "dir.h"
104#include "job.h" 104#include "job.h"
105#include "pathnames.h" 105#include "pathnames.h"
106 106
107/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ 107/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
108MAKE_RCSID("$NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $"); 108MAKE_RCSID("$NetBSD: parse.c,v 1.722 2024/04/27 17:33:46 rillig Exp $");
109 109
110/* Detects a multiple-inclusion guard in a makefile. */ 110/* Detects a multiple-inclusion guard in a makefile. */
111typedef enum { 111typedef enum {
112 GS_START, /* at the beginning of the file */ 112 GS_START, /* at the beginning of the file */
113 GS_COND, /* after the guard condition */ 113 GS_COND, /* after the guard condition */
114 GS_DONE, /* after the closing .endif */ 114 GS_DONE, /* after the closing .endif */
115 GS_NO /* the file is not guarded */ 115 GS_NO /* the file is not guarded */
116} GuardState; 116} GuardState;
117 117
118/* A file being parsed. */ 118/* A file being parsed. */
119typedef struct IncludedFile { 119typedef struct IncludedFile {
120 FStr name; /* absolute or relative to the cwd */ 120 FStr name; /* absolute or relative to the cwd */
121 unsigned lineno; /* 1-based */ 121 unsigned lineno; /* 1-based */
@@ -2956,27 +2956,27 @@ Parse_Init(void) @@ -2956,27 +2956,27 @@ Parse_Init(void)
2956 sysIncPath = SearchPath_New(); 2956 sysIncPath = SearchPath_New();
2957 defSysIncPath = SearchPath_New(); 2957 defSysIncPath = SearchPath_New();
2958 Vector_Init(&includes, sizeof(IncludedFile)); 2958 Vector_Init(&includes, sizeof(IncludedFile));
2959 HashTable_Init(&guards); 2959 HashTable_Init(&guards);
2960} 2960}
2961 2961
2962/* Clean up the parsing module. */ 2962/* Clean up the parsing module. */
2963void 2963void
2964Parse_End(void) 2964Parse_End(void)
2965{ 2965{
2966#ifdef CLEANUP 2966#ifdef CLEANUP
2967 HashIter hi; 2967 HashIter hi;
2968 2968
2969 Lst_DoneCall(&targCmds, free); 2969 Lst_DoneFree(&targCmds);
2970 assert(targets == NULL); 2970 assert(targets == NULL);
2971 SearchPath_Free(defSysIncPath); 2971 SearchPath_Free(defSysIncPath);
2972 SearchPath_Free(sysIncPath); 2972 SearchPath_Free(sysIncPath);
2973 SearchPath_Free(parseIncPath); 2973 SearchPath_Free(parseIncPath);
2974 assert(includes.len == 0); 2974 assert(includes.len == 0);
2975 Vector_Done(&includes); 2975 Vector_Done(&includes);
2976 HashIter_Init(&hi, &guards); 2976 HashIter_Init(&hi, &guards);
2977 while (HashIter_Next(&hi) != NULL) { 2977 while (HashIter_Next(&hi) != NULL) {
2978 Guard *guard = hi.entry->value; 2978 Guard *guard = hi.entry->value;
2979 free(guard->name); 2979 free(guard->name);
2980 free(guard); 2980 free(guard);
2981 } 2981 }
2982 HashTable_Done(&guards); 2982 HashTable_Done(&guards);

cvs diff -r1.180 -r1.181 src/usr.bin/make/targ.c (expand / switch to unified diff)

--- src/usr.bin/make/targ.c 2024/03/10 02:53:37 1.180
+++ src/usr.bin/make/targ.c 2024/04/27 17:33:47 1.181
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $ */ 1/* $NetBSD: targ.c,v 1.181 2024/04/27 17:33:47 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.
@@ -97,55 +97,60 @@ @@ -97,55 +97,60 @@
97 * 97 *
98 * Debugging: 98 * Debugging:
99 * Targ_PrintGraph 99 * Targ_PrintGraph
100 * Print out the entire graph, all variables and 100 * Print out the entire graph, all variables and
101 * statistics for the directory cache. 101 * statistics for the directory cache.
102 */ 102 */
103 103
104#include <time.h> 104#include <time.h>
105 105
106#include "make.h" 106#include "make.h"
107#include "dir.h" 107#include "dir.h"
108 108
109/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ 109/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
110MAKE_RCSID("$NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $"); 110MAKE_RCSID("$NetBSD: targ.c,v 1.181 2024/04/27 17:33:47 rillig Exp $");
111 111
112/* 112/*
113 * All target nodes that appeared on the left-hand side of one of the 113 * All target nodes that appeared on the left-hand side of one of the
114 * dependency operators ':', '::', '!'. 114 * dependency operators ':', '::', '!'.
115 */ 115 */
116static GNodeList allTargets = LST_INIT; 116static GNodeList allTargets = LST_INIT;
117static HashTable allTargetsByName; 117static HashTable allTargetsByName;
118 118
119#ifdef CLEANUP 119#ifdef CLEANUP
120static GNodeList allNodes = LST_INIT; 120static GNodeList allNodes = LST_INIT;
121 121
122static void GNode_Free(void *); 122static void GNode_Free(GNode *);
123#endif 123#endif
124 124
125void 125void
126Targ_Init(void) 126Targ_Init(void)
127{ 127{
128 HashTable_Init(&allTargetsByName); 128 HashTable_Init(&allTargetsByName);
129} 129}
130 130
131void 131void
132Targ_End(void) 132Targ_End(void)
133{ 133{
 134#ifdef CLEANUP
 135 GNodeListNode *ln;
 136#endif
134 Targ_Stats(); 137 Targ_Stats();
135#ifdef CLEANUP 138#ifdef CLEANUP
136 Lst_Done(&allTargets); 139 Lst_Done(&allTargets);
137 HashTable_Done(&allTargetsByName); 140 HashTable_Done(&allTargetsByName);
138 Lst_DoneCall(&allNodes, GNode_Free); 141 for (ln = allNodes.first; ln != NULL; ln = ln->next)
 142 GNode_Free(ln->datum);
 143 Lst_Done(&allNodes);
139#endif 144#endif
140} 145}
141 146
142void 147void
143Targ_Stats(void) 148Targ_Stats(void)
144{ 149{
145 HashTable_DebugStats(&allTargetsByName, "targets"); 150 HashTable_DebugStats(&allTargetsByName, "targets");
146} 151}
147 152
148/* 153/*
149 * Return the list of all targets, which are all nodes that appear on the 154 * Return the list of all targets, which are all nodes that appear on the
150 * left-hand side of a dependency declaration such as "target: source". 155 * left-hand side of a dependency declaration such as "target: source".
151 * The returned list does not contain pure sources. 156 * The returned list does not contain pure sources.
@@ -202,30 +207,28 @@ GNode_New(const char *name) @@ -202,30 +207,28 @@ GNode_New(const char *name)
202 gn->fname = NULL; 207 gn->fname = NULL;
203 gn->lineno = 0; 208 gn->lineno = 0;
204 gn->exit_status = 0; 209 gn->exit_status = 0;
205 210
206#ifdef CLEANUP 211#ifdef CLEANUP
207 Lst_Append(&allNodes, gn); 212 Lst_Append(&allNodes, gn);
208#endif 213#endif
209 214
210 return gn; 215 return gn;
211} 216}
212 217
213#ifdef CLEANUP 218#ifdef CLEANUP
214static void 219static void
215GNode_Free(void *gnp) 220GNode_Free(GNode *gn)
216{ 221{
217 GNode *gn = gnp; 
218 
219 free(gn->name); 222 free(gn->name);
220 free(gn->uname); 223 free(gn->uname);
221 free(gn->path); 224 free(gn->path);
222 225
223 /* Don't free gn->youngestChild since it is not owned by this node. */ 226 /* Don't free gn->youngestChild since it is not owned by this node. */
224 227
225 /* 228 /*
226 * In the following lists, only free the list nodes, but not the 229 * In the following lists, only free the list nodes, but not the
227 * GNodes in them since these are not owned by this node. 230 * GNodes in them since these are not owned by this node.
228 */ 231 */
229 Lst_Done(&gn->implicitParents); 232 Lst_Done(&gn->implicitParents);
230 Lst_Done(&gn->parents); 233 Lst_Done(&gn->parents);
231 Lst_Done(&gn->children); 234 Lst_Done(&gn->children);