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: use simpler memory management for parsing...



details:   https://anonhg.NetBSD.org/src/rev/8ad3b54eb408
branches:  trunk
changeset: 1027595:8ad3b54eb408
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 12 22:41:47 2021 +0000

description:
make: use simpler memory management for parsing archive members

No functional change.

diffstat:

 usr.bin/make/arch.c |  33 ++++++++++++++++-----------------
 1 files changed, 16 insertions(+), 17 deletions(-)

diffs (106 lines):

diff -r a12696061b66 -r 8ad3b54eb408 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sun Dec 12 22:20:52 2021 +0000
+++ b/usr.bin/make/arch.c       Sun Dec 12 22:41:47 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.204 2021/11/28 19:51:06 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.205 2021/12/12 22:41:47 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.204 2021/11/28 19:51:06 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.205 2021/12/12 22:41:47 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -202,7 +202,7 @@
        char *cp;               /* Pointer into line */
        GNode *gn;              /* New node */
        MFStr libName;          /* Library-part of specification */
-       char *memName;          /* Member-part of specification */
+       FStr mem;               /* Member-part of specification */
        char saveChar;          /* Ending delimiter of member-name */
        bool expandLibName;     /* Whether the parsed libName contains
                                 * variable expressions that need to be
@@ -253,7 +253,7 @@
 
                pp_skip_whitespace(&cp);
 
-               memName = cp;
+               mem = FStr_InitRefer(cp);
                while (*cp != '\0' && *cp != ')' && !ch_isspace(*cp)) {
                        if (*cp == '$') {
                                /* Expand nested variable expressions. */
@@ -294,7 +294,7 @@
                /*
                 * If we didn't move anywhere, we must be done
                 */
-               if (cp == memName)
+               if (cp == mem.str)
                        break;
 
                saveChar = *cp;
@@ -315,22 +315,22 @@
                 */
                if (doSubst) {
                        char *fullName;
-                       char *p;
-                       char *unexpandedMemName = memName;
+                       char *p, *expandedMem;
+                       const char *unexpandedMem = mem.str;
 
-                       (void)Var_Subst(memName, scope, VARE_UNDEFERR,
-                           &memName);
+                       (void)Var_Subst(mem.str, scope, VARE_UNDEFERR,
+                           &expandedMem);
                        /* TODO: handle errors */
+                       mem = FStr_InitOwn(expandedMem);
 
                        /*
                         * Now form an archive spec and recurse to deal with
                         * nested variables and multi-word variable values.
                         */
-                       fullName = FullName(libName.str, memName);
+                       fullName = FullName(libName.str, mem.str);
                        p = fullName;
 
-                       if (strchr(memName, '$') != NULL &&
-                           strcmp(memName, unexpandedMemName) == 0) {
+                       if (strcmp(mem.str, unexpandedMem) == 0) {
                                /*
                                 * Must contain dynamic sources, so we can't
                                 * deal with it now. Just create an ARCHV node
@@ -350,9 +350,9 @@
                        free(fullName);
                        /* XXX: does unexpandedMemName leak? */
 
-               } else if (Dir_HasWildcards(memName)) {
+               } else if (Dir_HasWildcards(mem.str)) {
                        StringList members = LST_INIT;
-                       SearchPath_Expand(&dirSearchPath, memName, &members);
+                       SearchPath_Expand(&dirSearchPath, mem.str, &members);
 
                        while (!Lst_IsEmpty(&members)) {
                                char *member = Lst_Dequeue(&members);
@@ -368,7 +368,7 @@
                        Lst_Done(&members);
 
                } else {
-                       char *fullname = FullName(libName.str, memName);
+                       char *fullname = FullName(libName.str, mem.str);
                        gn = Targ_GetNode(fullname);
                        free(fullname);
 
@@ -382,8 +382,7 @@
                        gn->type |= OP_ARCHV;
                        Lst_Append(gns, gn);
                }
-               if (doSubst)
-                       free(memName);
+               FStr_Done(&mem);
 
                *cp = saveChar;
        }



Home | Main Index | Thread Index | Old Index