| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.614 2020/10/31 09:57:47 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.615 2020/10/31 11:34:30 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -119,27 +119,27 @@ | | | @@ -119,27 +119,27 @@ |
119 | #include <sys/types.h> | | 119 | #include <sys/types.h> |
120 | #include <regex.h> | | 120 | #include <regex.h> |
121 | #endif | | 121 | #endif |
122 | #include <inttypes.h> | | 122 | #include <inttypes.h> |
123 | #include <limits.h> | | 123 | #include <limits.h> |
124 | #include <time.h> | | 124 | #include <time.h> |
125 | | | 125 | |
126 | #include "make.h" | | 126 | #include "make.h" |
127 | #include "dir.h" | | 127 | #include "dir.h" |
128 | #include "job.h" | | 128 | #include "job.h" |
129 | #include "metachar.h" | | 129 | #include "metachar.h" |
130 | | | 130 | |
131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | | 131 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ |
132 | MAKE_RCSID("$NetBSD: var.c,v 1.614 2020/10/31 09:57:47 rillig Exp $"); | | 132 | MAKE_RCSID("$NetBSD: var.c,v 1.615 2020/10/31 11:34:30 rillig Exp $"); |
133 | | | 133 | |
134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) | | 134 | #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) |
135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) | | 135 | #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) |
136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) | | 136 | #define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) |
137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) | | 137 | #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) |
138 | | | 138 | |
139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, | | 139 | ENUM_FLAGS_RTTI_3(VarEvalFlags, |
140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); | | 140 | VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); |
141 | | | 141 | |
142 | /* | | 142 | /* |
143 | * This lets us tell if we have replaced the original environ | | 143 | * This lets us tell if we have replaced the original environ |
144 | * (which we cannot free). | | 144 | * (which we cannot free). |
145 | */ | | 145 | */ |
| @@ -3652,54 +3652,50 @@ Var_Parse(const char **pp, GNode *ctxt, | | | @@ -3652,54 +3652,50 @@ Var_Parse(const char **pp, GNode *ctxt, |
3652 | * Most modifiers leave this expression in the "undefined" state | | 3652 | * Most modifiers leave this expression in the "undefined" state |
3653 | * (VEF_UNDEF), only a few modifiers like :D, :U, :L, :P turn this | | 3653 | * (VEF_UNDEF), only a few modifiers like :D, :U, :L, :P turn this |
3654 | * undefined expression into a defined expression (VEF_DEF). | | 3654 | * undefined expression into a defined expression (VEF_DEF). |
3655 | * | | 3655 | * |
3656 | * At the end, after applying all modifiers, if the expression | | 3656 | * At the end, after applying all modifiers, if the expression |
3657 | * is still undefined, Var_Parse will return an empty string | | 3657 | * is still undefined, Var_Parse will return an empty string |
3658 | * instead of the actually computed value. */ | | 3658 | * instead of the actually computed value. */ |
3659 | v = VarNew(varname, varname, "", 0); | | 3659 | v = VarNew(varname, varname, "", 0); |
3660 | exprFlags = VEF_UNDEF; | | 3660 | exprFlags = VEF_UNDEF; |
3661 | } else | | 3661 | } else |
3662 | free(varname); | | 3662 | free(varname); |
3663 | } | | 3663 | } |
3664 | | | 3664 | |
3665 | if (v->flags & VAR_IN_USE) { | | 3665 | if (v->flags & VAR_IN_USE) |
3666 | Fatal("Variable %s is recursive.", v->name); | | 3666 | Fatal("Variable %s is recursive.", v->name); |
3667 | /*NOTREACHED*/ | | | |
3668 | } else { | | | |
3669 | v->flags |= VAR_IN_USE; | | | |
3670 | } | | | |
3671 | | | 3667 | |
3672 | /* | | 3668 | /* |
3673 | * Before doing any modification, we have to make sure the value | | 3669 | * Before doing any modification, we have to make sure the value |
3674 | * has been fully expanded. If it looks like recursion might be | | 3670 | * has been fully expanded. If it looks like recursion might be |
3675 | * necessary (there's a dollar sign somewhere in the variable's value) | | 3671 | * necessary (there's a dollar sign somewhere in the variable's value) |
3676 | * we just call Var_Subst to do any other substitutions that are | | 3672 | * we just call Var_Subst to do any other substitutions that are |
3677 | * necessary. Note that the value returned by Var_Subst will have | | 3673 | * necessary. Note that the value returned by Var_Subst will have |
3678 | * been dynamically-allocated, so it will need freeing when we | | 3674 | * been dynamically-allocated, so it will need freeing when we |
3679 | * return. | | 3675 | * return. |
3680 | */ | | 3676 | */ |
3681 | nstr = Buf_GetAll(&v->val, NULL); | | 3677 | nstr = Buf_GetAll(&v->val, NULL); |
3682 | if (strchr(nstr, '$') != NULL && (eflags & VARE_WANTRES)) { | | 3678 | if (strchr(nstr, '$') != NULL && (eflags & VARE_WANTRES)) { |
3683 | VarEvalFlags nested_eflags = eflags; | | 3679 | VarEvalFlags nested_eflags = eflags; |
3684 | if (DEBUG(LINT)) | | 3680 | if (DEBUG(LINT)) |
3685 | nested_eflags &= ~(unsigned)VARE_UNDEFERR; | | 3681 | nested_eflags &= ~(unsigned)VARE_UNDEFERR; |
| | | 3682 | v->flags |= VAR_IN_USE; |
3686 | (void)Var_Subst(nstr, ctxt, nested_eflags, &nstr); | | 3683 | (void)Var_Subst(nstr, ctxt, nested_eflags, &nstr); |
| | | 3684 | v->flags &= ~(unsigned)VAR_IN_USE; |
3687 | /* TODO: handle errors */ | | 3685 | /* TODO: handle errors */ |
3688 | *freePtr = nstr; | | 3686 | *freePtr = nstr; |
3689 | } | | 3687 | } |
3690 | | | 3688 | |
3691 | v->flags &= ~(unsigned)VAR_IN_USE; | | | |
3692 | | | | |
3693 | if (haveModifier || extramodifiers != NULL) { | | 3689 | if (haveModifier || extramodifiers != NULL) { |
3694 | void *extraFree; | | 3690 | void *extraFree; |
3695 | | | 3691 | |
3696 | extraFree = NULL; | | 3692 | extraFree = NULL; |
3697 | if (extramodifiers != NULL) { | | 3693 | if (extramodifiers != NULL) { |
3698 | const char *em = extramodifiers; | | 3694 | const char *em = extramodifiers; |
3699 | nstr = ApplyModifiers(&em, nstr, '(', ')', | | 3695 | nstr = ApplyModifiers(&em, nstr, '(', ')', |
3700 | v, &exprFlags, ctxt, eflags, &extraFree); | | 3696 | v, &exprFlags, ctxt, eflags, &extraFree); |
3701 | } | | 3697 | } |
3702 | | | 3698 | |
3703 | if (haveModifier) { | | 3699 | if (haveModifier) { |
3704 | /* Skip initial colon. */ | | 3700 | /* Skip initial colon. */ |
3705 | p++; | | 3701 | p++; |