freebsd-src/contrib/bmake/hash.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

336 lines
9.5 KiB
C
Raw Normal View History

Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
/* $NetBSD: hash.c,v 1.79 2024/07/07 09:37:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
/* Hash tables with string keys and pointer values. */
#include "make.h"
/* "@(#)hash.c 8.1 (Berkeley) 6/6/93" */
Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
MAKE_RCSID("$NetBSD: hash.c,v 1.79 2024/07/07 09:37:00 rillig Exp $");
/*
* The ratio of # entries to # buckets at which we rebuild the table to
* make it larger.
*/
#define rebuildLimit 3
/* This hash function matches Gosling's Emacs and java.lang.String. */
static unsigned int
Hash_String(const char *key, const char **out_keyEnd)
{
unsigned int h;
const char *p;
h = 0;
for (p = key; *p != '\0'; p++)
h = 31 * h + (unsigned char)*p;
*out_keyEnd = p;
return h;
}
/* This hash function matches Gosling's Emacs and java.lang.String. */
unsigned int
Hash_Substring(Substring key)
{
unsigned int h;
const char *p;
h = 0;
for (p = key.start; p != key.end; p++)
h = 31 * h + (unsigned char)*p;
return h;
}
static HashEntry *
HashTable_Find(HashTable *t, Substring key, unsigned int h)
{
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
HashEntry *he;
size_t keyLen = Substring_Length(key);
#ifdef DEBUG_HASH_LOOKUP
DEBUG4(HASH, "HashTable_Find: %p h=%08x key=%.*s\n",
t, h, (int)keyLen, key.start);
#endif
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
for (he = t->buckets[h & t->bucketsMask]; he != NULL; he = he->next) {
if (he->hash == h &&
strncmp(he->key, key.start, keyLen) == 0 &&
he->key[keyLen] == '\0')
break;
}
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
return he;
}
/* Set up the hash table. */
void
HashTable_Init(HashTable *t)
{
unsigned int n = 16, i;
HashEntry **buckets = bmake_malloc(sizeof *buckets * n);
for (i = 0; i < n; i++)
buckets[i] = NULL;
t->buckets = buckets;
t->bucketsSize = n;
t->numEntries = 0;
t->bucketsMask = n - 1;
}
/*
* Remove everything from the hash table and free up the memory for the keys
* of the hash table, but not for the values associated to these keys.
*/
void
HashTable_Done(HashTable *t)
{
HashEntry **buckets = t->buckets;
size_t i, n = t->bucketsSize;
for (i = 0; i < n; i++) {
HashEntry *he = buckets[i];
while (he != NULL) {
HashEntry *next = he->next;
free(he);
he = next;
}
}
free(t->buckets);
#ifdef CLEANUP
t->buckets = NULL;
#endif
}
/* Find the entry corresponding to the key, or return NULL. */
HashEntry *
HashTable_FindEntry(HashTable *t, const char *key)
{
const char *keyEnd;
unsigned int h = Hash_String(key, &keyEnd);
return HashTable_Find(t, Substring_Init(key, keyEnd), h);
}
/* Find the value corresponding to the key, or return NULL. */
void *
HashTable_FindValue(HashTable *t, const char *key)
{
HashEntry *he = HashTable_FindEntry(t, key);
return he != NULL ? he->value : NULL;
}
/*
* Find the value corresponding to the key and the precomputed hash,
* or return NULL.
*/
void *
HashTable_FindValueBySubstringHash(HashTable *t, Substring key, unsigned int h)
{
HashEntry *he = HashTable_Find(t, key, h);
return he != NULL ? he->value : NULL;
}
Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
static unsigned
HashTable_MaxChain(const HashTable *t)
{
unsigned b, cl, max_cl = 0;
for (b = 0; b < t->bucketsSize; b++) {
const HashEntry *he = t->buckets[b];
for (cl = 0; he != NULL; he = he->next)
cl++;
if (cl > max_cl)
max_cl = cl;
}
return max_cl;
}
/*
* Make the hash table larger. Any bucket numbers from the old table become
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
* invalid; the hash values stay valid though.
*/
static void
HashTable_Enlarge(HashTable *t)
{
unsigned int oldSize = t->bucketsSize;
HashEntry **oldBuckets = t->buckets;
unsigned int newSize = 2 * oldSize;
unsigned int newMask = newSize - 1;
HashEntry **newBuckets = bmake_malloc(sizeof *newBuckets * newSize);
size_t i;
for (i = 0; i < newSize; i++)
newBuckets[i] = NULL;
for (i = 0; i < oldSize; i++) {
HashEntry *he = oldBuckets[i];
while (he != NULL) {
HashEntry *next = he->next;
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
he->next = newBuckets[he->hash & newMask];
newBuckets[he->hash & newMask] = he;
he = next;
}
}
free(oldBuckets);
t->bucketsSize = newSize;
t->bucketsMask = newMask;
t->buckets = newBuckets;
DEBUG4(HASH, "HashTable_Enlarge: %p size=%d entries=%d maxchain=%d\n",
Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
(void *)t, t->bucketsSize, t->numEntries, HashTable_MaxChain(t));
}
/*
* Find or create an entry corresponding to the key.
* Return in out_isNew whether a new entry has been created.
*/
HashEntry *
HashTable_CreateEntry(HashTable *t, const char *key, bool *out_isNew)
{
const char *keyEnd;
unsigned int h = Hash_String(key, &keyEnd);
HashEntry *he = HashTable_Find(t, Substring_Init(key, keyEnd), h);
if (he != NULL) {
if (out_isNew != NULL)
*out_isNew = false;
return he;
}
if (t->numEntries >= rebuildLimit * t->bucketsSize)
HashTable_Enlarge(t);
he = bmake_malloc(sizeof *he + (size_t)(keyEnd - key));
he->value = NULL;
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
he->hash = h;
memcpy(he->key, key, (size_t)(keyEnd - key) + 1);
he->next = t->buckets[h & t->bucketsMask];
t->buckets[h & t->bucketsMask] = he;
t->numEntries++;
if (out_isNew != NULL)
*out_isNew = true;
return he;
}
void
HashTable_Set(HashTable *t, const char *key, void *value)
{
HashEntry *he = HashTable_CreateEntry(t, key, NULL);
HashEntry_Set(he, value);
}
/* Delete the entry from the table, don't free the value of the entry. */
void
HashTable_DeleteEntry(HashTable *t, HashEntry *he)
{
Import bmake-20240108 Interesting/relevant changes since bmake-20230909 * VERSION (_MAKE_VERSION): 20240106 Merge with NetBSD make, pick up o fix duplicate progname when reporting an unknown target o unit tests for Cmd_Exec using temp file * VERSION (_MAKE_VERSION): 20240105 Merge with NetBSD make, pick up o main.c: Cmd_Exec write cmd to a file if too big avoid blowing commandline/env limits * VERSION (_MAKE_VERSION): 20240101 o util.c: flesh out more of strftime * configure.in: add --with-bmake-strftime it is not a full implementation but enough to pass all the unit-tests. * parse.c: LoadFile do not append \n to empty buffer. * VERSION (_MAKE_VERSION): 20231230 Merge with NetBSD make, pick up o simplify memory allocation for string buffers o fix declared types of list nodes o suff.c: clean up freeing of suffixes o var.c: simplify debug message for the ':@var@...@' modifier clean up variable handling * VERSION (_MAKE_VERSION): 20231226 Merge with NetBSD make, pick up o compat.c: ensure make's output is correctly ordered with that of the target when not going to a tty o main.c: check for shellPath whether to call Shell_Init() * VERSION (_MAKE_VERSION): 20231224 Merge with NetBSD make, pick up o compat.c: check for shellPath whether to call Shell_Init() tweak the unit test to detect the bug thus fixed. o make.1: do not claim .SHELL is only used by jobs mode. * VERSION (_MAKE_VERSION): 20231220 Merge with NetBSD make, pick up o str.c: speed up pattern matching in the ':M' modifier o var.c: fix confusing debug logging when deleting a variable use consistent debug messages style when ignoring variables * VERSION (_MAKE_VERSION): 20231210 Merge with NetBSD make, pick up o var.c: avoid segfault on empty :C match expression explain in debug log why variable assignment is ignored. * VERSION (_MAKE_VERSION): 20231208 Merge with NetBSD make, pick up o var.c: ensure fromCmd is set correctly for variables set on command line. * VERSION (_MAKE_VERSION): 20231124 Merge with NetBSD make, pick up o main.c: cleanup processing of -j fix lint warning about strchr o var.c: more accurate error message for invalid ':mtime' argument cleanup :[...] modifier avoid reading beyond substring when comparing o unit-tests cover all cases of :mtime, test and explain exporting of variables o cleanup comments * bsd.after-import.mk (ECHO_TAG): FreeBSD no longer uses $FreeBSD$ tag, so avoid adding it. mk/ChangeLog since bmake-20230909 * dirdeps.mk: for MAKE_VERSION 20240105 we do not have the same limits on command line length, so skip export of lists to env. * jobs.mk: avoid C suffix in JOB_MAX_C if factor is floating point. This keeps JOB_MAX numeric incase another makefile does comparisons. * gendirdeps.mk: if META_XTRAS is passed to us, add to META_FILES
2024-01-14 01:16:25 +00:00
HashEntry **ref = &t->buckets[he->hash & t->bucketsMask];
Import bmake-20240625 Intersting/relevant changes since bmake-20240520 ChangeLog since bmake-20240520 2024-06-25 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240625 Merge with NetBSD make, pick up o job.c: ensure shellPath is always duped, avoid upsetting free() 2024-06-16 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240616 Merge with NetBSD make, pick up o clean up collection of context information for error messages o in warnings, move the word "warning" to the front o var.c: throw an error on attempt to override an internal read-only variable 2024-06-10 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240610 Merge with NetBSD make, pick up o for.c: remove redundant shortcut for building the .for loop body 2024-06-02 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240602 Merge with NetBSD make, pick up o rename some VarEvalMode constants to better match debug names. o var.c: avoid out-of-bounds read when parsing indirect modifiers. 2024-06-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240601 Merge with NetBSD make, pick up o add .export-all rather than allow .export with no argument which can happen accidentally. o if lua is available, run check-expect.lua after unit-tests o main.c: use snprintf rather than strncpy fix memory leak when purging realpath cache. 2024-05-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240528 Merge with NetBSD make, pick up o fix a number of memory leaks o replace magic numbers with POSIX FILENO constants o hash.c: remove dead code from HashTable_DeleteEntry o main.c: when complaining about unusable .OBJDIR call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true. o parse.c: use fewer technical terms in debug message for dependency mk/ChangeLog since bmake-20240520 2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240616 * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have computed build dirs, since some filters cannot be easily expressed via DEP_DIRDEPS_FILTER. 2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS until after we a finished with it if building a cache.
2024-06-29 01:16:32 +01:00
for (; *ref != he; ref = &(*ref)->next)
continue;
*ref = he->next;
free(he);
t->numEntries--;
}
/*
Import bmake-20240625 Intersting/relevant changes since bmake-20240520 ChangeLog since bmake-20240520 2024-06-25 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240625 Merge with NetBSD make, pick up o job.c: ensure shellPath is always duped, avoid upsetting free() 2024-06-16 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240616 Merge with NetBSD make, pick up o clean up collection of context information for error messages o in warnings, move the word "warning" to the front o var.c: throw an error on attempt to override an internal read-only variable 2024-06-10 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240610 Merge with NetBSD make, pick up o for.c: remove redundant shortcut for building the .for loop body 2024-06-02 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240602 Merge with NetBSD make, pick up o rename some VarEvalMode constants to better match debug names. o var.c: avoid out-of-bounds read when parsing indirect modifiers. 2024-06-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240601 Merge with NetBSD make, pick up o add .export-all rather than allow .export with no argument which can happen accidentally. o if lua is available, run check-expect.lua after unit-tests o main.c: use snprintf rather than strncpy fix memory leak when purging realpath cache. 2024-05-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240528 Merge with NetBSD make, pick up o fix a number of memory leaks o replace magic numbers with POSIX FILENO constants o hash.c: remove dead code from HashTable_DeleteEntry o main.c: when complaining about unusable .OBJDIR call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true. o parse.c: use fewer technical terms in debug message for dependency mk/ChangeLog since bmake-20240520 2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240616 * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have computed build dirs, since some filters cannot be easily expressed via DEP_DIRDEPS_FILTER. 2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS until after we a finished with it if building a cache.
2024-06-29 01:16:32 +01:00
* Place the next entry from the hash table in hi->entry, or return false if
* the end of the table is reached.
*/
Import bmake-20240625 Intersting/relevant changes since bmake-20240520 ChangeLog since bmake-20240520 2024-06-25 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240625 Merge with NetBSD make, pick up o job.c: ensure shellPath is always duped, avoid upsetting free() 2024-06-16 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240616 Merge with NetBSD make, pick up o clean up collection of context information for error messages o in warnings, move the word "warning" to the front o var.c: throw an error on attempt to override an internal read-only variable 2024-06-10 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240610 Merge with NetBSD make, pick up o for.c: remove redundant shortcut for building the .for loop body 2024-06-02 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240602 Merge with NetBSD make, pick up o rename some VarEvalMode constants to better match debug names. o var.c: avoid out-of-bounds read when parsing indirect modifiers. 2024-06-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240601 Merge with NetBSD make, pick up o add .export-all rather than allow .export with no argument which can happen accidentally. o if lua is available, run check-expect.lua after unit-tests o main.c: use snprintf rather than strncpy fix memory leak when purging realpath cache. 2024-05-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240528 Merge with NetBSD make, pick up o fix a number of memory leaks o replace magic numbers with POSIX FILENO constants o hash.c: remove dead code from HashTable_DeleteEntry o main.c: when complaining about unusable .OBJDIR call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true. o parse.c: use fewer technical terms in debug message for dependency mk/ChangeLog since bmake-20240520 2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240616 * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have computed build dirs, since some filters cannot be easily expressed via DEP_DIRDEPS_FILTER. 2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS until after we a finished with it if building a cache.
2024-06-29 01:16:32 +01:00
bool
HashIter_Next(HashIter *hi)
{
HashTable *t = hi->table;
HashEntry *he = hi->entry;
HashEntry **buckets = t->buckets;
unsigned int bucketsSize = t->bucketsSize;
if (he != NULL)
he = he->next; /* skip the most recently returned entry */
while (he == NULL) { /* find the next nonempty chain */
if (hi->nextBucket >= bucketsSize)
Import bmake-20240625 Intersting/relevant changes since bmake-20240520 ChangeLog since bmake-20240520 2024-06-25 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240625 Merge with NetBSD make, pick up o job.c: ensure shellPath is always duped, avoid upsetting free() 2024-06-16 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240616 Merge with NetBSD make, pick up o clean up collection of context information for error messages o in warnings, move the word "warning" to the front o var.c: throw an error on attempt to override an internal read-only variable 2024-06-10 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240610 Merge with NetBSD make, pick up o for.c: remove redundant shortcut for building the .for loop body 2024-06-02 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240602 Merge with NetBSD make, pick up o rename some VarEvalMode constants to better match debug names. o var.c: avoid out-of-bounds read when parsing indirect modifiers. 2024-06-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240601 Merge with NetBSD make, pick up o add .export-all rather than allow .export with no argument which can happen accidentally. o if lua is available, run check-expect.lua after unit-tests o main.c: use snprintf rather than strncpy fix memory leak when purging realpath cache. 2024-05-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240528 Merge with NetBSD make, pick up o fix a number of memory leaks o replace magic numbers with POSIX FILENO constants o hash.c: remove dead code from HashTable_DeleteEntry o main.c: when complaining about unusable .OBJDIR call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true. o parse.c: use fewer technical terms in debug message for dependency mk/ChangeLog since bmake-20240520 2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240616 * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have computed build dirs, since some filters cannot be easily expressed via DEP_DIRDEPS_FILTER. 2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS until after we a finished with it if building a cache.
2024-06-29 01:16:32 +01:00
return false;
he = buckets[hi->nextBucket++];
}
hi->entry = he;
Import bmake-20240625 Intersting/relevant changes since bmake-20240520 ChangeLog since bmake-20240520 2024-06-25 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240625 Merge with NetBSD make, pick up o job.c: ensure shellPath is always duped, avoid upsetting free() 2024-06-16 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240616 Merge with NetBSD make, pick up o clean up collection of context information for error messages o in warnings, move the word "warning" to the front o var.c: throw an error on attempt to override an internal read-only variable 2024-06-10 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240610 Merge with NetBSD make, pick up o for.c: remove redundant shortcut for building the .for loop body 2024-06-02 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240602 Merge with NetBSD make, pick up o rename some VarEvalMode constants to better match debug names. o var.c: avoid out-of-bounds read when parsing indirect modifiers. 2024-06-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240601 Merge with NetBSD make, pick up o add .export-all rather than allow .export with no argument which can happen accidentally. o if lua is available, run check-expect.lua after unit-tests o main.c: use snprintf rather than strncpy fix memory leak when purging realpath cache. 2024-05-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240528 Merge with NetBSD make, pick up o fix a number of memory leaks o replace magic numbers with POSIX FILENO constants o hash.c: remove dead code from HashTable_DeleteEntry o main.c: when complaining about unusable .OBJDIR call PrintOnError if MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is true. o parse.c: use fewer technical terms in debug message for dependency mk/ChangeLog since bmake-20240520 2024-06-22 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240616 * dirdeps.mk: apply DEP_DIRDEPS_BUILD_DIR_FILTER after we have computed build dirs, since some filters cannot be easily expressed via DEP_DIRDEPS_FILTER. 2024-05-31 Simon J Gerraty <sjg@beast.crufty.net> * dirdeps.mk: move reset of DIRDEPS_EXPORT_VARS until after we a finished with it if building a cache.
2024-06-29 01:16:32 +01:00
return true;
}
void
Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
HashTable_DebugStats(const HashTable *t, const char *name)
{
Import bmake-20240711 Intersting/relevant changes since bmake-20240625 ChangeLog since bmake-20240625 2024-07-13 Simon J Gerraty <sjg@beast.crufty.net> * cleanup redundant differences from NetBSD make o parse.c: no longer uses mmap o var.c: check __STDC_VERSION__ not __STDC__ 2024-07-12 Simon J Gerraty <sjg@beast.crufty.net> * Apply some patches from NetBSD pkgsrc to reduce divergence o meta.c: requires sys/select.h if available o var.c: ensure SIZE_MAX has a value o util.c: ensure SA_RESTART is defined * configure.in: use *ksh* rather than just *ksh to match ksh shell specification. * unit-tests/Makefile: expand BROKEN_TESTS for ksh and mksh in particular 2024-07-11 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240711 Merge with NetBSD make, pick up o compat.c: allow Compat_RunCommand to also handle very long commands by writing to a temp file when needed. o main.c: extract the temp file logic recently added to Cmd_Exec to Cmd_Argv so it can be leveraged by Compat_RunCommand. 2024-07-09 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240709 Merge with NetBSD make, pick up o error out on parse/evaluation errors in shell commands o var.c: error out on syntax errors in ':M' and ':N' modifiers 2024-07-07 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240707 Merge with NetBSD make, pick up o only generate code for cleanup functions in CLEANUP mode o hash.c: don't track hash table chain lengths during lookup unless debugging o main.c: move initialization of variable scopes to targ.c o var.c: remove Var_End as it is now unnecessary 2024-07-06 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240706 Merge with NetBSD make, pick up o reduce lint comments about ARGSUSED o cond.c: error out on conditions containing the operators '&' and '|' o str.c: error out on a matching malformed matching pattern '[[' o var.c: in error messages, distinguish parsing from evaluating in error messages for anonymous variables, log the value error out on unclosed expressions during parse time 2024-07-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240704 Merge with NetBSD make, pick up o add more context information to error messages o main.c: on error, print the targets to be made add detailed exit status to message for failed sub-commands o var.c: error out on the "Bad modifier" error message 2024-07-01 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240701 Merge with NetBSD make, pick up o var.c: add :tt for Title case 2024-06-30 Simon J Gerraty <sjg@beast.crufty.net> * configure.in: 20240630 further refine check for whether TZ=Europe/Berlin works * VERSION (_MAKE_VERSION): 20240630 Merge with NetBSD make, pick up o job.c: reduce use of UNCONST o main.c: add detailed exit status to message for failed sub-commands o var.c: error out on some more syntax errors add more context to "returned non-zero status" message
2024-07-20 20:41:55 +01:00
DEBUG4(HASH, "HashTable \"%s\": size=%u entries=%u maxchain=%u\n",
name, t->bucketsSize, t->numEntries, HashTable_MaxChain(t));
}