Mon Aug 31 19:09:19 2020 UTC ()
make(1): inline a local variable in VarUniq

Just to eliminate any remote possibility of aliasing and thereby
forgetting to update all involved variables.


(rillig)
diff -r1.481 -r1.482 src/usr.bin/make/var.c

cvs diff -r1.481 -r1.482 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/08/31 19:05:53 1.481
+++ src/usr.bin/make/var.c 2020/08/31 19:09:19 1.482
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.481 2020/08/31 19:05:53 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.482 2020/08/31 19:09:19 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.481 2020/08/31 19:05:53 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.482 2020/08/31 19:09:19 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.481 2020/08/31 19:05:53 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.482 2020/08/31 19:09:19 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. 91 * yet exist.
92 * 92 *
@@ -1599,33 +1599,32 @@ Words_JoinFree(Words words) @@ -1599,33 +1599,32 @@ Words_JoinFree(Words words)
1599 Buf_AddStr(&buf, words.words[i]); 1599 Buf_AddStr(&buf, words.words[i]);
1600 } 1600 }
1601 1601
1602 Words_Free(words); 1602 Words_Free(words);
1603 1603
1604 return Buf_Destroy(&buf, FALSE); 1604 return Buf_Destroy(&buf, FALSE);
1605} 1605}
1606 1606
1607/* Remove adjacent duplicate words. */ 1607/* Remove adjacent duplicate words. */
1608static char * 1608static char *
1609VarUniq(const char *str) 1609VarUniq(const char *str)
1610{ 1610{
1611 Words words = Str_Words(str, FALSE); 1611 Words words = Str_Words(str, FALSE);
1612 char **av = words.words; 
1613 1612
1614 if (words.len > 1) { 1613 if (words.len > 1) {
1615 size_t i, j; 1614 size_t i, j;
1616 for (j = 0, i = 1; i < words.len; i++) 1615 for (j = 0, i = 1; i < words.len; i++)
1617 if (strcmp(av[i], av[j]) != 0 && (++j != i)) 1616 if (strcmp(words.words[i], words.words[j]) != 0 && (++j != i))
1618 av[j] = av[i]; 1617 words.words[j] = words.words[i];
1619 words.len = j + 1; 1618 words.len = j + 1;
1620 } 1619 }
1621 1620
1622 return Words_JoinFree(words); 1621 return Words_JoinFree(words);
1623} 1622}
1624 1623
1625 1624
1626/*- 1625/*-
1627 * Parse a part of a modifier such as the "from" and "to" in :S/from/to/ 1626 * Parse a part of a modifier such as the "from" and "to" in :S/from/to/
1628 * or the "var" or "replacement" in :@var@replacement+${var}@, up to and 1627 * or the "var" or "replacement" in :@var@replacement+${var}@, up to and
1629 * including the next unescaped delimiter. The delimiter, as well as the 1628 * including the next unescaped delimiter. The delimiter, as well as the
1630 * backslash or the dollar, can be escaped with a backslash. 1629 * backslash or the dollar, can be escaped with a backslash.
1631 * 1630 *