Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): indent targ.c with tabs instead of spaces
details: https://anonhg.NetBSD.org/src/rev/afb96c20ec61
branches: trunk
changeset: 946638:afb96c20ec61
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Dec 05 15:35:34 2020 +0000
description:
make(1): indent targ.c with tabs instead of spaces
Explain the tricky details of GNode_Free.
Invert a condition in Targ_PrintNode to reduce the overall indentation.
diffstat:
usr.bin/make/targ.c | 504 +++++++++++++++++++++++++++------------------------
1 files changed, 271 insertions(+), 233 deletions(-)
diffs (truncated from 728 to 300 lines):
diff -r 15c97cf10e1d -r afb96c20ec61 usr.bin/make/targ.c
--- a/usr.bin/make/targ.c Sat Dec 05 15:31:18 2020 +0000
+++ b/usr.bin/make/targ.c Sat Dec 05 15:35:34 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: targ.c,v 1.149 2020/12/04 14:39:56 rillig Exp $ */
+/* $NetBSD: targ.c,v 1.150 2020/12/05 15:35:34 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -119,7 +119,7 @@
#include "dir.h"
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: targ.c,v 1.149 2020/12/04 14:39:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.150 2020/12/05 15:35:34 rillig Exp $");
/*
* All target nodes that appeared on the left-hand side of one of the
@@ -137,24 +137,24 @@
void
Targ_Init(void)
{
- HashTable_Init(&allTargetsByName);
+ HashTable_Init(&allTargetsByName);
}
void
Targ_End(void)
{
- Targ_Stats();
+ Targ_Stats();
#ifdef CLEANUP
- Lst_Done(&allTargets);
- HashTable_Done(&allTargetsByName);
- Lst_DoneCall(&allNodes, GNode_Free);
+ Lst_Done(&allTargets);
+ HashTable_Done(&allTargetsByName);
+ Lst_DoneCall(&allNodes, GNode_Free);
#endif
}
void
Targ_Stats(void)
{
- HashTable_DebugStats(&allTargetsByName, "targets");
+ HashTable_DebugStats(&allTargetsByName, "targets");
}
/*
@@ -165,10 +165,11 @@
GNodeList *
Targ_List(void)
{
- return &allTargets;
+ return &allTargets;
}
-/* Create a new graph node, but don't register it anywhere.
+/*
+ * Create a new graph node, but don't register it anywhere.
*
* Graph nodes that appear on the left-hand side of a dependency line such
* as "target: source" are called targets. XXX: In some cases (like the
@@ -185,68 +186,95 @@
GNode *
GNode_New(const char *name)
{
- GNode *gn;
+ GNode *gn;
- gn = bmake_malloc(sizeof *gn);
- gn->name = bmake_strdup(name);
- gn->uname = NULL;
- gn->path = NULL;
- gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
- gn->flags = 0;
- gn->made = UNMADE;
- gn->unmade = 0;
- gn->mtime = 0;
- gn->youngestChild = NULL;
- Lst_Init(&gn->implicitParents);
- Lst_Init(&gn->parents);
- Lst_Init(&gn->children);
- Lst_Init(&gn->order_pred);
- Lst_Init(&gn->order_succ);
- Lst_Init(&gn->cohorts);
- gn->cohort_num[0] = '\0';
- gn->unmade_cohorts = 0;
- gn->centurion = NULL;
- gn->checked_seqno = 0;
- HashTable_Init(&gn->vars);
- Lst_Init(&gn->commands);
- gn->suffix = NULL;
- gn->fname = NULL;
- gn->lineno = 0;
+ gn = bmake_malloc(sizeof *gn);
+ gn->name = bmake_strdup(name);
+ gn->uname = NULL;
+ gn->path = NULL;
+ gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
+ gn->flags = 0;
+ gn->made = UNMADE;
+ gn->unmade = 0;
+ gn->mtime = 0;
+ gn->youngestChild = NULL;
+ Lst_Init(&gn->implicitParents);
+ Lst_Init(&gn->parents);
+ Lst_Init(&gn->children);
+ Lst_Init(&gn->order_pred);
+ Lst_Init(&gn->order_succ);
+ Lst_Init(&gn->cohorts);
+ gn->cohort_num[0] = '\0';
+ gn->unmade_cohorts = 0;
+ gn->centurion = NULL;
+ gn->checked_seqno = 0;
+ HashTable_Init(&gn->vars);
+ Lst_Init(&gn->commands);
+ gn->suffix = NULL;
+ gn->fname = NULL;
+ gn->lineno = 0;
#ifdef CLEANUP
- Lst_Append(&allNodes, gn);
+ Lst_Append(&allNodes, gn);
#endif
- return gn;
+ return gn;
}
#ifdef CLEANUP
static void
GNode_Free(void *gnp)
{
- GNode *gn = gnp;
+ GNode *gn = gnp;
+
+ free(gn->name);
+ free(gn->uname);
+ free(gn->path);
+
+ /* Don't free gn->youngestChild since it is not owned by this node. */
+
+ /*
+ * In the following lists, only free the list nodes, but not the
+ * GNodes in them since these are not owned by this node.
+ */
+ Lst_Done(&gn->implicitParents);
+ Lst_Done(&gn->parents);
+ Lst_Done(&gn->children);
+ Lst_Done(&gn->order_pred);
+ Lst_Done(&gn->order_succ);
+ Lst_Done(&gn->cohorts);
- free(gn->name);
- free(gn->uname);
- free(gn->path);
- /* gn->youngestChild is not owned by this node. */
- Lst_Done(&gn->implicitParents); /* Do not free the nodes themselves, */
- Lst_Done(&gn->parents); /* as they are not owned by this node. */
- Lst_Done(&gn->children); /* likewise */
- Lst_Done(&gn->order_pred); /* likewise */
- Lst_Done(&gn->order_succ); /* likewise */
- Lst_Done(&gn->cohorts); /* likewise */
- HashTable_Done(&gn->vars); /* Do not free the variables themselves,
- * even though they are owned by this node.
- * XXX: they should probably be freed. */
- Lst_Done(&gn->commands); /* Do not free the commands themselves,
- * as they may be shared with other nodes. */
- /* gn->suffix is not owned by this node. */
- /* XXX: gn->suffix should be unreferenced here. This requires a thorough
- * check that the reference counting is done correctly in all places,
- * otherwise a suffix might be freed too early. */
+ /*
+ * Do not free the variables themselves, even though they are owned
+ * by this node.
+ *
+ * XXX: For the nodes that represent targets or sources (and not
+ * VAR_GLOBAL), it should be safe to free the variables as well,
+ * since each node manages the memory for all its variables itself.
+ *
+ * XXX: The GNodes that are only used as variable contexts (VAR_CMD,
+ * VAR_GLOBAL, VAR_INTERNAL) are not freed at all (see Var_End, where
+ * they are not mentioned). These might be freed at all, if their
+ * variable values are indeed not used anywhere else (see Trace_Init
+ * for the only suspicious use).
+ */
+ HashTable_Done(&gn->vars);
- free(gn);
+ /*
+ * Do not free the commands themselves, as they may be shared with
+ * other nodes.
+ */
+ Lst_Done(&gn->commands);
+
+ /*
+ * gn->suffix is not owned by this node.
+ *
+ * XXX: gn->suffix should be unreferenced here. This requires a
+ * thorough check that the reference counting is done correctly in
+ * all places, otherwise a suffix might be freed too early.
+ */
+
+ free(gn);
}
#endif
@@ -254,23 +282,23 @@
GNode *
Targ_FindNode(const char *name)
{
- return HashTable_FindValue(&allTargetsByName, name);
+ return HashTable_FindValue(&allTargetsByName, name);
}
/* Get the existing global node, or create it. */
GNode *
Targ_GetNode(const char *name)
{
- Boolean isNew;
- HashEntry *he = HashTable_CreateEntry(&allTargetsByName, name, &isNew);
- if (!isNew)
- return HashEntry_Get(he);
+ Boolean isNew;
+ HashEntry *he = HashTable_CreateEntry(&allTargetsByName, name, &isNew);
+ if (!isNew)
+ return HashEntry_Get(he);
- {
- GNode *gn = Targ_NewInternalNode(name);
- HashEntry_Set(he, gn);
- return gn;
- }
+ {
+ GNode *gn = Targ_NewInternalNode(name);
+ HashEntry_Set(he, gn);
+ return gn;
+ }
}
/*
@@ -282,13 +310,13 @@
GNode *
Targ_NewInternalNode(const char *name)
{
- GNode *gn = GNode_New(name);
- Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
- Lst_Append(&allTargets, gn);
- DEBUG1(TARG, "Adding \"%s\" to all targets.\n", gn->name);
- if (doing_depend)
- gn->flags |= FROM_DEPEND;
- return gn;
+ GNode *gn = GNode_New(name);
+ Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
+ Lst_Append(&allTargets, gn);
+ DEBUG1(TARG, "Adding \"%s\" to all targets.\n", gn->name);
+ if (doing_depend)
+ gn->flags |= FROM_DEPEND;
+ return gn;
}
/*
@@ -297,26 +325,30 @@
*/
GNode *Targ_GetEndNode(void)
{
- /* Save the node locally to avoid having to search for it all the time. */
- static GNode *endNode = NULL;
- if (endNode == NULL) {
- endNode = Targ_GetNode(".END");
- endNode->type = OP_SPECIAL;
- }
- return endNode;
+ /*
+ * Save the node locally to avoid having to search for it all
+ * the time.
+ */
+ static GNode *endNode = NULL;
+
+ if (endNode == NULL) {
+ endNode = Targ_GetNode(".END");
+ endNode->type = OP_SPECIAL;
+ }
+ return endNode;
}
/* Add the named nodes to the list, creating them as necessary. */
void
Targ_FindList(GNodeList *gns, StringList *names)
{
- StringListNode *ln;
+ StringListNode *ln;
- for (ln = names->first; ln != NULL; ln = ln->next) {
- const char *name = ln->datum;
- GNode *gn = Targ_GetNode(name);
- Lst_Append(gns, gn);
- }
+ for (ln = names->first; ln != NULL; ln = ln->next) {
Home |
Main Index |
Thread Index |
Old Index