summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/for.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-12-16 16:14:16 +0000
committerharti <harti@FreeBSD.org>2004-12-16 16:14:16 +0000
commitce24622080c0eb3be79451dd08003d8e95ce7e29 (patch)
treefdf4034c35002c2f5a941b3dae513d763e63ce80 /usr.bin/make/for.c
parentc9d76864dd7b7d31e691edce2d40a35711cc3f7c (diff)
downloadFreeBSD-src-ce24622080c0eb3be79451dd08003d8e95ce7e29.zip
FreeBSD-src-ce24622080c0eb3be79451dd08003d8e95ce7e29.tar.gz
Instead of dynamically allocating list heads allocated them statically
now that their size is only two pointers. This eliminates a lot of calls to Lst_Init and from there to malloc together with many calls to Lst_Destroy (in places where the list is obviously empty). This also reduces the chance to leave a list uninitilized so we can remove more NULL pointer checks and probably eliminates a couple of memory leaks.
Diffstat (limited to 'usr.bin/make/for.c')
-rw-r--r--usr.bin/make/for.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c
index e2df76c..a083630 100644
--- a/usr.bin/make/for.c
+++ b/usr.bin/make/for.c
@@ -72,7 +72,7 @@ __FBSDID("$FreeBSD$");
static int forLevel = 0; /* Nesting level */
static char *forVar; /* Iteration variable */
static Buffer forBuf; /* Commands in loop */
-static Lst *forLst; /* List of items */
+static Lst forLst; /* List of items */
/*
* State of a for loop.
@@ -80,7 +80,7 @@ static Lst *forLst; /* List of items */
typedef struct _For {
Buffer buf; /* Unexpanded buffer */
char* var; /* Index name */
- Lst *lst; /* List of variables */
+ Lst lst; /* List of variables */
int lineno; /* Line # */
} For;
@@ -168,14 +168,14 @@ For_Eval(char *line)
/*
* Make a list with the remaining words
*/
- forLst = Lst_Init();
+ Lst_Init(&forLst);
buf = Buf_Init(0);
sub = Var_Subst(NULL, ptr, VAR_CMD, FALSE);
#define ADDWORD() \
Buf_AddBytes(buf, ptr - wrd, (Byte *)wrd), \
Buf_AddByte(buf, (Byte)'\0'), \
- Lst_AtFront(forLst, Buf_GetAll(buf, &varlen)), \
+ Lst_AtFront(&forLst, Buf_GetAll(buf, &varlen)), \
Buf_Destroy(buf, FALSE)
for (ptr = sub; *ptr && isspace((unsigned char)*ptr); ptr++)
@@ -277,19 +277,22 @@ For_Run(int lineno)
{
For arg;
- if (forVar == NULL || forBuf == NULL || forLst == NULL)
+ if (forVar == NULL || forBuf == NULL)
return;
arg.var = forVar;
arg.buf = forBuf;
- arg.lst = forLst;
+
+ /* move the forLst to the arg to get it free for nested for's */
+ Lst_Init(&arg.lst);
+ Lst_Concat(&arg.lst, &forLst, LST_CONCLINK);
+
arg.lineno = lineno;
forVar = NULL;
forBuf = NULL;
- forLst = NULL;
- Lst_ForEach(arg.lst, ForExec, &arg);
+ Lst_ForEach(&arg.lst, ForExec, &arg);
free(arg.var);
- Lst_Destroy(arg.lst, free);
+ Lst_Destroy(&arg.lst, free);
Buf_Destroy(arg.buf, TRUE);
}
OpenPOWER on IntegriCloud