diff options
author | harti <harti@FreeBSD.org> | 2004-12-16 16:14:16 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2004-12-16 16:14:16 +0000 |
commit | ce24622080c0eb3be79451dd08003d8e95ce7e29 (patch) | |
tree | fdf4034c35002c2f5a941b3dae513d763e63ce80 /usr.bin/make/parse.c | |
parent | c9d76864dd7b7d31e691edce2d40a35711cc3f7c (diff) | |
download | FreeBSD-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/parse.c')
-rw-r--r-- | usr.bin/make/parse.c | 206 |
1 files changed, 90 insertions, 116 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index a945571..4aa3313 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -101,7 +101,10 @@ __FBSDID("$FreeBSD$"); */ #define CONTINUE 1 #define DONE 0 -static Lst *targets; /* targets we're working on */ + +/* targets we're working on */ +static Lst targets = Lst_Initializer(targets); + static Boolean inLine; /* true if currently in a dependency * line or its commands */ static int fatals = 0; @@ -112,10 +115,14 @@ static GNode *mainNode; /* The main target to create. This is the IFile curFile; /* current makefile */ -static Lst *includes; /* stack of IFiles generated by - * #includes */ -Lst *parseIncPath; /* list of directories for "..." includes */ -Lst *sysIncPath; /* list of directories for <...> includes */ +/* stack of IFiles generated by * #includes */ +static Lst includes = Lst_Initializer(includes); + +/* list of directories for "..." includes */ +Lst parseIncPath = Lst_Initializer(parseIncPath); + +/* list of directories for <...> includes */ +Lst sysIncPath = Lst_Initializer(sysIncPath); /*- * specType contains the SPECial TYPE of the current target. It is @@ -322,10 +329,10 @@ ParseLinkSrc(void *pgnp, void *cgnp) GNode *pgn = pgnp; GNode *cgn = cgnp; - if (Lst_Member(pgn->children, cgn) == NULL) { - Lst_AtEnd(pgn->children, cgn); + if (Lst_Member(&pgn->children, cgn) == NULL) { + Lst_AtEnd(&pgn->children, cgn); if (specType == Not) { - Lst_AtEnd(cgn->parents, pgn); + Lst_AtEnd(&cgn->parents, pgn); } pgn->unmade += 1; } @@ -388,14 +395,14 @@ ParseDoOp(void *gnp, void *opp) * anything with their local variables, but better safe than * sorry. */ - Lst_ForEach(gn->parents, ParseLinkSrc, cohort); + Lst_ForEach(&gn->parents, ParseLinkSrc, cohort); cohort->type = OP_DOUBLEDEP|OP_INVISIBLE; - Lst_AtEnd(gn->cohorts, cohort); + Lst_AtEnd(&gn->cohorts, cohort); /* * Replace the node in the targets list with the new copy */ - ln = Lst_Member(targets, gn); + ln = Lst_Member(&targets, gn); Lst_Replace(ln, cohort); gn = cohort; } @@ -436,8 +443,8 @@ ParseAddDep(void *pp, void *sp) * but checking is tedious, and the debugging output can show the * problem */ - Lst_AtEnd(p->successors, s); - Lst_AtEnd(s->preds, p); + Lst_AtEnd(&p->successors, s); + Lst_AtEnd(&s->preds, p); return (0); } else @@ -472,7 +479,7 @@ ParseDoSrc(int tOp, char *src, Lst *allsrc) if (keywd != -1) { int op = parseKeywords[keywd].op; if (op != 0) { - Lst_ForEach(targets, ParseDoOp, &op); + Lst_ForEach(&targets, ParseDoOp, &op); return; } if (parseKeywords[keywd].spec == Wait) { @@ -492,7 +499,7 @@ ParseDoSrc(int tOp, char *src, Lst *allsrc) * invoked if the user didn't specify a target on the command * line. This is to allow #ifmake's to succeed, or something... */ - Lst_AtEnd(create, estrdup(src)); + Lst_AtEnd(&create, estrdup(src)); /* * Add the name to the .TARGETS variable as well, so the user cna * employ that, if desired. @@ -507,8 +514,8 @@ ParseDoSrc(int tOp, char *src, Lst *allsrc) */ gn = Targ_FindNode(src, TARG_CREATE); if (predecessor != NULL) { - Lst_AtEnd(predecessor->successors, gn); - Lst_AtEnd(gn->preds, predecessor); + Lst_AtEnd(&predecessor->successors, gn); + Lst_AtEnd(&gn->preds, predecessor); } /* * The current source now becomes the predecessor for the next one. @@ -532,18 +539,18 @@ ParseDoSrc(int tOp, char *src, Lst *allsrc) if (tOp) { gn->type |= tOp; } else { - Lst_ForEach(targets, ParseLinkSrc, gn); + Lst_ForEach(&targets, ParseLinkSrc, gn); } if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) { GNode *cohort; LstNode *ln; - for (ln=Lst_First(gn->cohorts); ln != NULL; ln = Lst_Succ(ln)){ + for (ln = Lst_First(&gn->cohorts); ln != NULL; ln = Lst_Succ(ln)) { cohort = Lst_Datum(ln); if (tOp) { cohort->type |= tOp; } else { - Lst_ForEach(targets, ParseLinkSrc, cohort); + Lst_ForEach(&targets, ParseLinkSrc, cohort); } } } @@ -669,23 +676,14 @@ ParseDoDependency (char *line) GNode *gn; /* a general purpose temporary node */ int op; /* the operator on the line */ char savec; /* a place to save a character */ - Lst *paths; /* List of search paths to alter when parsing - * a list of .PATH targets */ + Lst paths; /* Search paths to alter when parsing a list of .PATH targets */ int tOp; /* operator from special target */ - Lst *sources; /* list of archive source names after - * expansion */ - Lst *curTargs; /* list of target names to be found and added - * to the targets list */ - Lst *curSrcs; /* list of sources in order */ tOp = 0; specType = Not; waiting = 0; - paths = NULL; - - curTargs = Lst_Init(); - curSrcs = Lst_Init(); + Lst_Init(&paths); do { for (cp = line; @@ -751,7 +749,7 @@ ParseDoDependency (char *line) * went well and FAILURE if there was an error in the * specification. On error, line should remain untouched. */ - if (Arch_ParseArchive(&line, targets, VAR_CMD) != SUCCESS) { + if (Arch_ParseArchive(&line, &targets, VAR_CMD) != SUCCESS) { Parse_Error(PARSE_FATAL, "Error in archive specification: \"%s\"", line); return; @@ -826,13 +824,10 @@ ParseDoDependency (char *line) */ switch (specType) { case ExPath: - if (paths == NULL) { - paths = Lst_Init(); - } - Lst_AtEnd(paths, dirSearchPath); + Lst_AtEnd(&paths, &dirSearchPath); break; case Main: - if (!Lst_IsEmpty(create)) { + if (!Lst_IsEmpty(&create)) { specType = Not; } break; @@ -841,12 +836,12 @@ ParseDoDependency (char *line) case Interrupt: gn = Targ_FindNode(line, TARG_CREATE); gn->type |= OP_NOTMAIN; - Lst_AtEnd(targets, gn); + Lst_AtEnd(&targets, gn); break; case Default: gn = Targ_NewGN(".DEFAULT"); gn->type |= (OP_NOTMAIN|OP_TRANSFORM); - Lst_AtEnd(targets, gn); + Lst_AtEnd(&targets, gn); DEFAULT = gn; break; case NotParallel: @@ -878,12 +873,8 @@ ParseDoDependency (char *line) "Suffix '%s' not defined (yet)", &line[5]); return; - } else { - if (paths == NULL) { - paths = Lst_Init(); - } - Lst_AtEnd(paths, path); - } + } else + Lst_AtEnd(&paths, path); } } @@ -892,6 +883,9 @@ ParseDoDependency (char *line) * the end of the targets list */ if ((specType == Not) && (*line != '\0')) { + /* target names to be found and added to targets list */ + Lst curTargs = Lst_Initializer(curTargs); + if (Dir_HasWildcards(line)) { /* * Targets are to be sought only in the current directory, @@ -899,21 +893,21 @@ ParseDoDependency (char *line) * use Dir_Destroy in the destruction of the path as the * Dir module could have added a directory to the path... */ - Lst *emptyPath = Lst_Init(); + Lst emptyPath = Lst_Initializer(emptyPath); - Dir_Expand(line, emptyPath, curTargs); + Dir_Expand(line, &emptyPath, &curTargs); - Lst_Destroy(emptyPath, Dir_Destroy); + Lst_Destroy(&emptyPath, Dir_Destroy); } else { /* * No wildcards, but we want to avoid code duplication, * so create a list with the word on it. */ - Lst_AtEnd(curTargs, line); + Lst_AtEnd(&curTargs, line); } - while(!Lst_IsEmpty(curTargs)) { - char *targName = Lst_DeQueue(curTargs); + while (!Lst_IsEmpty(&curTargs)) { + char *targName = Lst_DeQueue(&curTargs); if (!Suff_IsTransform (targName)) { gn = Targ_FindNode(targName, TARG_CREATE); @@ -921,7 +915,7 @@ ParseDoDependency (char *line) gn = Suff_AddTransform(targName); } - Lst_AtEnd(targets, gn); + Lst_AtEnd(&targets, gn); } } else if (specType == ExPath && *line != '.' && *line != '\0') { Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line); @@ -952,12 +946,7 @@ ParseDoDependency (char *line) line = cp; } while ((*line != '!') && (*line != ':') && *line); - /* - * Don't need the list of target names anymore... - */ - Lst_Destroy(curTargs, NOFREE); - - if (!Lst_IsEmpty(targets)) { + if (!Lst_IsEmpty(&targets)) { switch (specType) { default: Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); @@ -998,7 +987,7 @@ ParseDoDependency (char *line) cp++; /* Advance beyond operator */ - Lst_ForEach(targets, ParseDoOp, &op); + Lst_ForEach(&targets, ParseDoOp, &op); /* * Get to the first source @@ -1032,7 +1021,7 @@ ParseDoDependency (char *line) beSilent = TRUE; break; case ExPath: - Lst_ForEach(paths, ParseClearPath, NULL); + Lst_ForEach(&paths, ParseClearPath, NULL); break; case Posix: Var_Set("%POSIX", "1003.2", VAR_GLOBAL); @@ -1101,7 +1090,7 @@ ParseDoDependency (char *line) Suff_AddSuffix(line); break; case ExPath: - Lst_ForEach(paths, ParseAddDir, line); + Lst_ForEach(&paths, ParseAddDir, line); break; case Includes: Suff_AddInclude(line); @@ -1124,10 +1113,11 @@ ParseDoDependency (char *line) } line = cp; } - if (paths) { - Lst_Destroy(paths, NOFREE); - } + Lst_Destroy(&paths, NOFREE); + } else { + Lst curSrcs = Lst_Initializer(curSrc); /* list of sources in order */ + while (*line) { /* * The targets take real sources, so we must beware of archive @@ -1150,19 +1140,19 @@ ParseDoDependency (char *line) if (*cp == '(') { GNode *gnp; + /* list of archive source names after expansion */ + Lst sources = Lst_Initializer(sources); - sources = Lst_Init(); - if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) { + if (Arch_ParseArchive(&line, &sources, VAR_CMD) != SUCCESS) { Parse_Error(PARSE_FATAL, "Error in source archive spec \"%s\"", line); return; } - while (!Lst_IsEmpty (sources)) { - gnp = Lst_DeQueue(sources); - ParseDoSrc(tOp, gnp->name, curSrcs); + while (!Lst_IsEmpty(&sources)) { + gnp = Lst_DeQueue(&sources); + ParseDoSrc(tOp, gnp->name, &curSrcs); } - Lst_Destroy(sources, NOFREE); cp = line; } else { if (*cp) { @@ -1170,13 +1160,14 @@ ParseDoDependency (char *line) cp += 1; } - ParseDoSrc(tOp, line, curSrcs); + ParseDoSrc(tOp, line, &curSrcs); } while (*cp && isspace((unsigned char)*cp)) { cp++; } line = cp; } + Lst_Destroy(&curSrcs, NOFREE); } if (mainNode == NULL) { @@ -1186,13 +1177,8 @@ ParseDoDependency (char *line) * the first dependency line that is actually a real target * (i.e. isn't a .USE or .EXEC rule) to be made. */ - Lst_ForEach(targets, ParseFindMain, NULL); + Lst_ForEach(&targets, ParseFindMain, NULL); } - - /* - * Finally, destroy the list of sources - */ - Lst_Destroy(curSrcs, NOFREE); } /*- @@ -1481,7 +1467,7 @@ ParseAddCmd(void *gnp, void *cmd) /* if target already supplied, ignore commands */ if (!(gn->type & OP_HAS_COMMANDS)) - Lst_AtEnd(gn->commands, cmd); + Lst_AtEnd(&gn->commands, cmd); else Parse_Error(PARSE_WARNING, "duplicate script for target \"%s\" ignored", @@ -1510,7 +1496,7 @@ ParseHasCommands(void *gnp) { GNode *gn = gnp; - if (!Lst_IsEmpty(gn->commands)) { + if (!Lst_IsEmpty(&gn->commands)) { gn->type |= OP_HAS_COMMANDS; } } @@ -1533,7 +1519,7 @@ void Parse_AddIncludeDir(char *dir) { - Dir_AddDir(parseIncPath, dir); + Dir_AddDir(&parseIncPath, dir); } /*--------------------------------------------------------------------- @@ -1694,9 +1680,9 @@ ParseDoInclude (char *file) newName = estrdup(file); else newName = str_concat(Fname, file, STR_ADDSLASH); - fullname = Dir_FindFile(newName, parseIncPath); + fullname = Dir_FindFile(newName, &parseIncPath); if (fullname == NULL) { - fullname = Dir_FindFile(newName, dirSearchPath); + fullname = Dir_FindFile(newName, &dirSearchPath); } free(newName); *prefEnd = '/'; @@ -1715,9 +1701,9 @@ ParseDoInclude (char *file) * then on the .PATH search path, if not found in a -I directory. * XXX: Suffix specific? */ - fullname = Dir_FindFile(file, parseIncPath); + fullname = Dir_FindFile(file, &parseIncPath); if (fullname == NULL) { - fullname = Dir_FindFile(file, dirSearchPath); + fullname = Dir_FindFile(file, &dirSearchPath); } } @@ -1726,7 +1712,7 @@ ParseDoInclude (char *file) * Still haven't found the makefile. Look for it on the system * path as a last resort. */ - fullname = Dir_FindFile(file, sysIncPath); + fullname = Dir_FindFile(file, &sysIncPath); } if (fullname == NULL) { @@ -1747,7 +1733,7 @@ ParseDoInclude (char *file) oldFile = emalloc(sizeof (IFile)); memcpy(oldFile, &curFile, sizeof(IFile)); - Lst_AtFront(includes, oldFile); + Lst_AtFront(&includes, oldFile); /* * Once the previous state has been saved, we can get down to reading @@ -1794,7 +1780,7 @@ Parse_FromString(char *str, int lineno) oldFile = emalloc(sizeof(IFile)); memcpy(oldFile, &curFile, sizeof(IFile)); - Lst_AtFront(includes, oldFile); + Lst_AtFront(&includes, oldFile); curFile.F = NULL; curFile.p = emalloc(sizeof (PTR)); @@ -1860,9 +1846,9 @@ ParseTraditionalInclude (char *file) * Search for it first on the -I search path, then on the .PATH * search path, if not found in a -I directory. */ - fullname = Dir_FindFile(file, parseIncPath); + fullname = Dir_FindFile(file, &parseIncPath); if (fullname == NULL) { - fullname = Dir_FindFile(file, dirSearchPath); + fullname = Dir_FindFile(file, &dirSearchPath); } if (fullname == NULL) { @@ -1870,7 +1856,7 @@ ParseTraditionalInclude (char *file) * Still haven't found the makefile. Look for it on the system * path as a last resort. */ - fullname = Dir_FindFile(file, sysIncPath); + fullname = Dir_FindFile(file, &sysIncPath); } if (fullname == NULL) { @@ -1888,7 +1874,7 @@ ParseTraditionalInclude (char *file) oldFile = emalloc(sizeof(IFile)); memcpy(oldFile, &curFile, sizeof(IFile)); - Lst_AtFront(includes, oldFile); + Lst_AtFront(&includes, oldFile); /* * Once the previous state has been saved, we can get down to reading @@ -1934,12 +1920,12 @@ ParseEOF(int opened) { IFile *ifile; /* the state on the top of the includes stack */ - if (Lst_IsEmpty (includes)) { + if (Lst_IsEmpty(&includes)) { Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL); return (DONE); } - ifile = Lst_DeQueue(includes); + ifile = Lst_DeQueue(&includes); free(curFile.fname); if (opened && curFile.F) { fclose(curFile.F); @@ -2349,9 +2335,8 @@ ParseFinishLine(void) { if (inLine) { - Lst_ForEach(targets, Suff_EndTransform, NULL); - Lst_Destroy(targets, ParseHasCommands); - targets = NULL; + Lst_ForEach(&targets, Suff_EndTransform, NULL); + Lst_Destroy(&targets, ParseHasCommands); inLine = FALSE; } } @@ -2443,7 +2428,7 @@ Parse_File(char *name, FILE *stream) * in a dependency spec, add the command to the list of * commands of all targets in the dependency spec */ - Lst_ForEach(targets, ParseAddCmd, cp); + Lst_ForEach(&targets, ParseAddCmd, cp); continue; } else { Parse_Error(PARSE_FATAL, @@ -2494,10 +2479,7 @@ Parse_File(char *name, FILE *stream) /* * Need a non-circular list for the target nodes */ - if (targets) - Lst_Destroy(targets, NOFREE); - - targets = Lst_Init(); + Lst_Destroy(&targets, NOFREE); inLine = TRUE; ParseDoDependency (line); @@ -2538,20 +2520,16 @@ Parse_Init(void) { mainNode = NULL; - parseIncPath = Lst_Init(); - sysIncPath = Lst_Init(); - includes = Lst_Init(); } void Parse_End(void) { - if (targets) - Lst_Destroy(targets, NOFREE); - Lst_Destroy(sysIncPath, Dir_Destroy); - Lst_Destroy(parseIncPath, Dir_Destroy); - Lst_Destroy(includes, NOFREE); /* Should be empty now */ + Lst_Destroy(&targets, NOFREE); + Lst_Destroy(&sysIncPath, Dir_Destroy); + Lst_Destroy(&parseIncPath, Dir_Destroy); + Lst_Destroy(&includes, NOFREE); /* Should be empty now */ } @@ -2569,21 +2547,17 @@ Parse_End(void) * *----------------------------------------------------------------------- */ -Lst * -Parse_MainName(void) +void +Parse_MainName(Lst *listmain) { - Lst *listmain; /* result list */ - - listmain = Lst_Init(); if (mainNode == NULL) { Punt("no target to make."); /*NOTREACHED*/ } else if (mainNode->type & OP_DOUBLEDEP) { Lst_AtEnd(listmain, mainNode); - Lst_Concat(listmain, mainNode->cohorts, LST_CONCNEW); + Lst_Concat(listmain, &mainNode->cohorts, LST_CONCNEW); } else Lst_AtEnd(listmain, mainNode); - return (listmain); } |