Sat Aug 29 11:13:43 2020 UTC ()
make(1): merge duplicate code for bmake_strldup


(rillig)
diff -r1.18 -r1.19 src/usr.bin/make/hash.h
diff -r1.269 -r1.270 src/usr.bin/make/parse.c
diff -r1.131 -r1.132 src/usr.bin/make/suff.c

cvs diff -r1.18 -r1.19 src/usr.bin/make/hash.h (expand / switch to unified diff)

--- src/usr.bin/make/hash.h 2020/08/13 03:54:57 1.18
+++ src/usr.bin/make/hash.h 2020/08/29 11:13:43 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: hash.h,v 1.18 2020/08/13 03:54:57 rillig Exp $ */ 1/* $NetBSD: hash.h,v 1.19 2020/08/29 11:13:43 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * 5 *
6 * This code is derived from software contributed to Berkeley by 6 * This code is derived from software contributed to Berkeley by
7 * Adam de Boor. 7 * Adam de Boor.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -81,27 +81,27 @@ @@ -81,27 +81,27 @@
81#ifndef MAKE_HASH_H 81#ifndef MAKE_HASH_H
82#define MAKE_HASH_H 82#define MAKE_HASH_H
83 83
84/* 84/*
85 * The following defines one entry in the hash table. 85 * The following defines one entry in the hash table.
86 */ 86 */
87 87
88typedef struct Hash_Entry { 88typedef struct Hash_Entry {
89 struct Hash_Entry *next; /* Used to link together all the 89 struct Hash_Entry *next; /* Used to link together all the
90 * entries associated with the same 90 * entries associated with the same
91 * bucket. */ 91 * bucket. */
92 void *clientPtr; /* Arbitrary pointer */ 92 void *clientPtr; /* Arbitrary pointer */
93 unsigned namehash; /* hash value of key */ 93 unsigned namehash; /* hash value of key */
94 char name[1]; /* key string */ 94 char name[1]; /* key string, variable length */
95} Hash_Entry; 95} Hash_Entry;
96 96
97typedef struct Hash_Table { 97typedef struct Hash_Table {
98 struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one 98 struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one
99 * for each bucket in the table. */ 99 * for each bucket in the table. */
100 int size; /* Actual size of array. */ 100 int size; /* Actual size of array. */
101 int numEntries; /* Number of entries in the table. */ 101 int numEntries; /* Number of entries in the table. */
102 int mask; /* Used to select bits for hashing. */ 102 int mask; /* Used to select bits for hashing. */
103 int maxchain; /* max length of chain detected */ 103 int maxchain; /* max length of chain detected */
104} Hash_Table; 104} Hash_Table;
105 105
106/* 106/*
107 * The following structure is used by the searching routines 107 * The following structure is used by the searching routines

cvs diff -r1.269 -r1.270 src/usr.bin/make/parse.c (expand / switch to unified diff)

--- src/usr.bin/make/parse.c 2020/08/29 07:52:55 1.269
+++ src/usr.bin/make/parse.c 2020/08/29 11:13:43 1.270
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parse.c,v 1.269 2020/08/29 07:52:55 rillig Exp $ */ 1/* $NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 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: parse.c,v 1.269 2020/08/29 07:52:55 rillig Exp $"; 72static char rcsid[] = "$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 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[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: parse.c,v 1.269 2020/08/29 07:52:55 rillig Exp $"); 79__RCSID("$NetBSD: parse.c,v 1.270 2020/08/29 11:13:43 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * parse.c -- 85 * parse.c --
86 * Functions to parse a makefile. 86 * Functions to parse a makefile.
87 * 87 *
88 * One function, Parse_Init, must be called before any functions 88 * One function, Parse_Init, must be called before any functions
89 * in this module are used. After that, the function Parse_File is the 89 * in this module are used. After that, the function Parse_File is the
90 * main entry point and controls most of the other functions in this 90 * main entry point and controls most of the other functions in this
91 * module. 91 * module.
92 * 92 *
@@ -2385,38 +2385,34 @@ ParseSetIncludedFile(void) @@ -2385,38 +2385,34 @@ ParseSetIncludedFile(void)
2385 * Results: 2385 * Results:
2386 * None 2386 * None
2387 * 2387 *
2388 * Side Effects: 2388 * Side Effects:
2389 * The .PARSEDIR and .PARSEFILE variables are overwritten by the 2389 * The .PARSEDIR and .PARSEFILE variables are overwritten by the
2390 * dirname and basename of the given filename. 2390 * dirname and basename of the given filename.
2391 *--------------------------------------------------------------------- 2391 *---------------------------------------------------------------------
2392 */ 2392 */
2393static void 2393static void
2394ParseSetParseFile(const char *filename) 2394ParseSetParseFile(const char *filename)
2395{ 2395{
2396 char *slash, *dirname; 2396 char *slash, *dirname;
2397 const char *pd, *pf; 2397 const char *pd, *pf;
2398 int len; 
2399 2398
2400 slash = strrchr(filename, '/'); 2399 slash = strrchr(filename, '/');
2401 if (slash == NULL) { 2400 if (slash == NULL) {
2402 Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL); 2401 Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL);
2403 Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL); 2402 Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL);
2404 dirname= NULL; 2403 dirname = NULL;
2405 } else { 2404 } else {
2406 len = slash - filename; 2405 dirname = bmake_strldup(filename, (size_t)(slash - filename));
2407 dirname = bmake_malloc(len + 1); 
2408 memcpy(dirname, filename, len); 
2409 dirname[len] = '\0'; 
2410 Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL); 2406 Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL);
2411 Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL); 2407 Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL);
2412 } 2408 }
2413 if (DEBUG(PARSE)) 2409 if (DEBUG(PARSE))
2414 fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n", 2410 fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n",
2415 __func__, pd, pf); 2411 __func__, pd, pf);
2416 free(dirname); 2412 free(dirname);
2417} 2413}
2418 2414
2419/* 2415/*
2420 * Track the makefiles we read - so makefiles can 2416 * Track the makefiles we read - so makefiles can
2421 * set dependencies on them. 2417 * set dependencies on them.
2422 * Avoid adding anything more than once. 2418 * Avoid adding anything more than once.

cvs diff -r1.131 -r1.132 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/08/29 10:41:12 1.131
+++ src/usr.bin/make/suff.c 2020/08/29 11:13:43 1.132
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.131 2020/08/29 10:41:12 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 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: suff.c,v 1.131 2020/08/29 10:41:12 rillig Exp $"; 72static char rcsid[] = "$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 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[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
78#else 78#else
79__RCSID("$NetBSD: suff.c,v 1.131 2020/08/29 10:41:12 rillig Exp $"); 79__RCSID("$NetBSD: suff.c,v 1.132 2020/08/29 11:13:43 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * suff.c -- 85 * suff.c --
86 * Functions to maintain suffix lists and find implicit dependents 86 * Functions to maintain suffix lists and find implicit dependents
87 * using suffix transformation rules 87 * using suffix transformation rules
88 * 88 *
89 * Interface: 89 * Interface:
90 * Suff_Init Initialize all things to do with suffixes. 90 * Suff_Init Initialize all things to do with suffixes.
91 * 91 *
92 * Suff_End Cleanup the module 92 * Suff_End Cleanup the module
@@ -2010,51 +2010,44 @@ SuffFindNormalDeps(GNode *gn, Lst slst) @@ -2010,51 +2010,44 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
2010 */ 2010 */
2011 bottom = NULL; 2011 bottom = NULL;
2012 targ = NULL; 2012 targ = NULL;
2013 2013
2014 if (!(gn->type & OP_PHONY)) { 2014 if (!(gn->type & OP_PHONY)) {
2015 2015
2016 while (ln != NULL) { 2016 while (ln != NULL) {
2017 /* 2017 /*
2018 * Look for next possible suffix... 2018 * Look for next possible suffix...
2019 */ 2019 */
2020 ln = Lst_FindFrom(sufflist, ln, SuffSuffIsSuffix, &sd); 2020 ln = Lst_FindFrom(sufflist, ln, SuffSuffIsSuffix, &sd);
2021 2021
2022 if (ln != NULL) { 2022 if (ln != NULL) {
2023 int prefLen; /* Length of the prefix */ 2023 const char *eopref;
2024 2024
2025 /* 2025 /*
2026 * Allocate a Src structure to which things can be transformed 2026 * Allocate a Src structure to which things can be transformed
2027 */ 2027 */
2028 targ = bmake_malloc(sizeof(Src)); 2028 targ = bmake_malloc(sizeof(Src));
2029 targ->file = bmake_strdup(gn->name); 2029 targ->file = bmake_strdup(gn->name);
2030 targ->suff = Lst_Datum(ln); 2030 targ->suff = Lst_Datum(ln);
2031 targ->suff->refCount++; 2031 targ->suff->refCount++;
2032 targ->node = gn; 2032 targ->node = gn;
2033 targ->parent = NULL; 2033 targ->parent = NULL;
2034 targ->children = 0; 2034 targ->children = 0;
2035#ifdef DEBUG_SRC 2035#ifdef DEBUG_SRC
2036 targ->cp = Lst_Init(); 2036 targ->cp = Lst_Init();
2037#endif 2037#endif
2038 2038
2039 /* 2039 eopref = eoname - targ->suff->nameLen;
2040 * Allocate room for the prefix, whose end is found by 2040 targ->pref = bmake_strldup(sopref, (size_t)(eopref - sopref));
2041 * subtracting the length of the suffix from 
2042 * the end of the name. 
2043 */ 
2044 prefLen = (eoname - targ->suff->nameLen) - sopref; 
2045 targ->pref = bmake_malloc(prefLen + 1); 
2046 memcpy(targ->pref, sopref, prefLen); 
2047 targ->pref[prefLen] = '\0'; 
2048 2041
2049 /* 2042 /*
2050 * Add nodes from which the target can be made 2043 * Add nodes from which the target can be made
2051 */ 2044 */
2052 SuffAddLevel(srcs, targ); 2045 SuffAddLevel(srcs, targ);
2053 2046
2054 /* 2047 /*
2055 * Record the target so we can nuke it 2048 * Record the target so we can nuke it
2056 */ 2049 */
2057 Lst_Append(targs, targ); 2050 Lst_Append(targs, targ);
2058 2051
2059 /* 2052 /*
2060 * Search from this suffix's successor... 2053 * Search from this suffix's successor...