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: only allocate the name of an included fil...



details:   https://anonhg.NetBSD.org/src/rev/ac1ea26eb309
branches:  trunk
changeset: 1026644:ac1ea26eb309
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Dec 03 23:29:30 2021 +0000

description:
make: only allocate the name of an included file if necessary

The string passed to IncludeFile is only used during that function call,
it is not stored anywhere.

No functional change.

diffstat:

 usr.bin/make/parse.c |  24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)

diffs (59 lines):

diff -r d790c8625c15 -r ac1ea26eb309 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Fri Dec 03 23:13:29 2021 +0000
+++ b/usr.bin/make/parse.c      Fri Dec 03 23:29:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.567 2021/12/03 23:29:30 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.567 2021/12/03 23:29:30 rillig Exp $");
 
 /* types and constants */
 
@@ -2123,7 +2123,7 @@
  * line options.
  */
 static void
-IncludeFile(char *file, bool isSystem, bool depinc, bool silent)
+IncludeFile(const char *file, bool isSystem, bool depinc, bool silent)
 {
        struct loadedfile *lf;
        char *fullname;         /* full pathname of file */
@@ -2237,8 +2237,8 @@
 static void
 ParseInclude(char *directive)
 {
-       char endc;              /* the character which ends the file spec */
-       char *p, *xfile;
+       char endc;              /* '>' or '"' */
+       char *p;
        bool silent = directive[0] != 'i';
        FStr file;
 
@@ -2269,11 +2269,15 @@
 
        *p = '\0';
 
-       (void)Var_Subst(file.str, SCOPE_CMDLINE, VARE_WANTRES, &xfile);
-       /* TODO: handle errors */
-
-       IncludeFile(xfile, endc == '>', directive[0] == 'd', silent);
-       free(xfile);
+       if (strchr(file.str, '$') != NULL) {
+               char *xfile;
+               Var_Subst(file.str, SCOPE_CMDLINE, VARE_WANTRES, &xfile);
+               /* TODO: handle errors */
+               file = FStr_InitOwn(xfile);
+       }
+
+       IncludeFile(file.str, endc == '>', directive[0] == 'd', silent);
+       FStr_Done(&file);
 }
 
 /*



Home | Main Index | Thread Index | Old Index