Module Name: src
Committed By: rillig
Date: Sat Apr 27 17:33:47 UTC 2024
Modified Files:
src/usr.bin/make: arch.c lst.c lst.h main.c meta.c parse.c targ.c
Log Message:
make: simplify freeing of lists
To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/make/arch.c
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/make/lst.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/make/lst.h
cvs rdiff -u -r1.612 -r1.613 src/usr.bin/make/main.c
cvs rdiff -u -r1.207 -r1.208 src/usr.bin/make/meta.c
cvs rdiff -u -r1.721 -r1.722 src/usr.bin/make/parse.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/make/targ.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.215 src/usr.bin/make/arch.c:1.216
--- src/usr.bin/make/arch.c:1.215 Wed Feb 7 06:43:02 2024
+++ src/usr.bin/make/arch.c Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.215 2024/02/07 06:43:02 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 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.215 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.216 2024/04/27 17:33:46 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
@@ -151,9 +151,8 @@ static int ArchSVR4Entry(Arch *, char *,
#ifdef CLEANUP
static void
-ArchFree(void *ap)
+ArchFree(Arch *a)
{
- Arch *a = ap;
HashIter hi;
/* Free memory from hash entries */
@@ -1070,7 +1069,11 @@ void
Arch_End(void)
{
#ifdef CLEANUP
- Lst_DoneCall(&archives, ArchFree);
+ ArchListNode *ln;
+
+ for (ln = archives.first; ln != NULL; ln = ln->next)
+ ArchFree(ln->datum);
+ Lst_Done(&archives);
#endif
}
Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.107 src/usr.bin/make/lst.c:1.108
--- src/usr.bin/make/lst.c:1.107 Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/lst.c Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
#include "make.h"
-MAKE_RCSID("$NetBSD: lst.c,v 1.107 2023/12/29 20:43:58 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.108 2024/04/27 17:33:46 rillig Exp $");
static ListNode *
LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -60,13 +60,13 @@ Lst_Done(List *list)
}
void
-Lst_DoneCall(List *list, LstFreeProc freeProc)
+Lst_DoneFree(List *list)
{
ListNode *ln, *next;
for (ln = list->first; ln != NULL; ln = next) {
next = ln->next;
- freeProc(ln->datum);
+ free(ln->datum);
free(ln);
}
}
Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.104 src/usr.bin/make/lst.h:1.105
--- src/usr.bin/make/lst.h:1.104 Fri Dec 29 20:43:58 2023
+++ src/usr.bin/make/lst.h Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.104 2023/12/29 20:43:58 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.105 2024/04/27 17:33:46 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -98,13 +98,10 @@ struct List {
ListNode *last;
};
-/* Free the datum of a node, called before freeing the node itself. */
-typedef void LstFreeProc(void *);
-
-/* Free the list nodes, but not the list itself. */
+/* Free the list nodes. */
void Lst_Done(List *);
-/* Free the list nodes, freeing the node data using the given function. */
-void Lst_DoneCall(List *, LstFreeProc);
+/* Free the list nodes, as well as each node's datum. */
+void Lst_DoneFree(List *);
#define LST_INIT { NULL, NULL }
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.612 src/usr.bin/make/main.c:1.613
--- src/usr.bin/make/main.c:1.612 Sun Mar 10 02:53:37 2024
+++ src/usr.bin/make/main.c Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $ */
+/* $NetBSD: main.c,v 1.613 2024/04/27 17:33:46 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.612 2024/03/10 02:53:37 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.613 2024/04/27 17:33:46 rillig Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1199,7 +1199,7 @@ ReadBuiltinRules(void)
Fatal("%s: cannot open %s.",
progname, (const char *)sysMkFiles.first->datum);
- Lst_DoneCall(&sysMkFiles, free);
+ Lst_DoneFree(&sysMkFiles);
}
static void
@@ -1564,9 +1564,9 @@ static void
main_CleanUp(void)
{
#ifdef CLEANUP
- Lst_DoneCall(&opts.variables, free);
- Lst_DoneCall(&opts.makefiles, free);
- Lst_DoneCall(&opts.create, free);
+ Lst_DoneFree(&opts.variables);
+ Lst_DoneFree(&opts.makefiles);
+ Lst_DoneFree(&opts.create);
#endif
if (DEBUG(GRAPH2))
Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.207 src/usr.bin/make/meta.c:1.208
--- src/usr.bin/make/meta.c:1.207 Sun Dec 17 09:02:26 2023
+++ src/usr.bin/make/meta.c Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.207 2023/12/17 09:02:26 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.208 2024/04/27 17:33:46 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -1595,7 +1595,7 @@ meta_oodate(GNode *gn, bool oodate)
}
}
- Lst_DoneCall(&missingFiles, free);
+ Lst_DoneFree(&missingFiles);
if (oodate && needOODATE) {
/*
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.721 src/usr.bin/make/parse.c:1.722
--- src/usr.bin/make/parse.c:1.721 Tue Apr 23 22:51:28 2024
+++ src/usr.bin/make/parse.c Sat Apr 27 17:33:46 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.722 2024/04/27 17:33:46 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.722 2024/04/27 17:33:46 rillig Exp $");
/* Detects a multiple-inclusion guard in a makefile. */
typedef enum {
@@ -2966,7 +2966,7 @@ Parse_End(void)
#ifdef CLEANUP
HashIter hi;
- Lst_DoneCall(&targCmds, free);
+ Lst_DoneFree(&targCmds);
assert(targets == NULL);
SearchPath_Free(defSysIncPath);
SearchPath_Free(sysIncPath);
Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.180 src/usr.bin/make/targ.c:1.181
--- src/usr.bin/make/targ.c:1.180 Sun Mar 10 02:53:37 2024
+++ src/usr.bin/make/targ.c Sat Apr 27 17:33:47 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $ */
+/* $NetBSD: targ.c,v 1.181 2024/04/27 17:33:47 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
#include "dir.h"
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.181 2024/04/27 17:33:47 rillig Exp $");
/*
* All target nodes that appeared on the left-hand side of one of the
@@ -119,7 +119,7 @@ static HashTable allTargetsByName;
#ifdef CLEANUP
static GNodeList allNodes = LST_INIT;
-static void GNode_Free(void *);
+static void GNode_Free(GNode *);
#endif
void
@@ -131,11 +131,16 @@ Targ_Init(void)
void
Targ_End(void)
{
+#ifdef CLEANUP
+ GNodeListNode *ln;
+#endif
Targ_Stats();
#ifdef CLEANUP
Lst_Done(&allTargets);
HashTable_Done(&allTargetsByName);
- Lst_DoneCall(&allNodes, GNode_Free);
+ for (ln = allNodes.first; ln != NULL; ln = ln->next)
+ GNode_Free(ln->datum);
+ Lst_Done(&allNodes);
#endif
}
@@ -212,10 +217,8 @@ GNode_New(const char *name)
#ifdef CLEANUP
static void
-GNode_Free(void *gnp)
+GNode_Free(GNode *gn)
{
- GNode *gn = gnp;
-
free(gn->name);
free(gn->uname);
free(gn->path);