summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2022-07-25 17:38:57 (GMT)
committerGitHub <noreply@github.com>2022-07-25 17:38:57 (GMT)
commitb0240030f5dd1c3da65fd66b76fcdfe13604489c (patch)
treea2a659b1e6759bfc6fc8301bca7ab6632504a0cf /src
parentdf1ce61f1b4884681c00b342a8651e4d48a91881 (diff)
downloadhdf5-b0240030f5dd1c3da65fd66b76fcdfe13604489c.zip
hdf5-b0240030f5dd1c3da65fd66b76fcdfe13604489c.tar.gz
hdf5-b0240030f5dd1c3da65fd66b76fcdfe13604489c.tar.bz2
Updates uthash and makes some tweaks (#1928)
* Updates uthash from 2.1.0 to 2.3.0 * Moves uthash include and related to H5private.h * Defines HASH_NONFATAL_OOM so that out-of-memory doesn't abort() * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/H5Dmpio.c9
-rw-r--r--src/H5private.h1
-rw-r--r--src/uthash.h96
3 files changed, 38 insertions, 68 deletions
diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c
index 9a4bccf..9107a3a 100644
--- a/src/H5Dmpio.c
+++ b/src/H5Dmpio.c
@@ -44,15 +44,6 @@
#include "H5Sprivate.h" /* Dataspaces */
#include "H5VMprivate.h" /* Vector */
-/* uthash is an external, header-only hash table implementation.
- *
- * We include the file directly in src/ and #define a few functions
- * to use our internal memory calls.
- */
-#define uthash_malloc(sz) H5MM_malloc(sz)
-#define uthash_free(ptr, sz) H5MM_free(ptr) /* Ignoring sz is intentional */
-#include "uthash.h"
-
#ifdef H5_HAVE_PARALLEL
/****************/
diff --git a/src/H5private.h b/src/H5private.h
index 53ed809..e09cdbd 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -146,6 +146,7 @@
*/
#define uthash_malloc(sz) H5MM_malloc(sz)
#define uthash_free(ptr, sz) H5MM_free(ptr) /* Ignoring sz is intentional */
+#define HASH_NONFATAL_OOM 1 /* Don't abort() on out-of-memory */
#include "uthash.h"
/*
diff --git a/src/uthash.h b/src/uthash.h
index ea99839..f259ba2 100644
--- a/src/uthash.h
+++ b/src/uthash.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
+Copyright (c) 2003-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -24,12 +24,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTHASH_H
#define UTHASH_H
-#define UTHASH_VERSION 2.1.0
+#define UTHASH_VERSION 2.3.0
#include <string.h> /* memcmp, memset, strlen */
#include <stddef.h> /* ptrdiff_t */
#include <stdlib.h> /* exit */
+#if defined(HASH_DEFINE_OWN_STDINT) && HASH_DEFINE_OWN_STDINT
+/* This codepath is provided for backward compatibility, but I plan to remove it. */
+#warning "HASH_DEFINE_OWN_STDINT is deprecated; please use HASH_NO_STDINT instead"
+typedef unsigned int uint32_t;
+typedef unsigned char uint8_t;
+#elif defined(HASH_NO_STDINT) && HASH_NO_STDINT
+#else
+#include <stdint.h> /* uint8_t, uint32_t */
+#endif
+
/* These macros use decltype or the earlier __typeof GNU extension.
As decltype is only available in newer compilers (VS2010 or gcc 4.3+
when compiling c++ source) this code uses whatever method is needed
@@ -62,23 +72,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
} while (0)
#endif
-/* a number of the hash function use uint32_t which isn't defined on Pre VS2010 */
-#if defined(_WIN32)
-#if defined(_MSC_VER) && _MSC_VER >= 1600
-#include <stdint.h>
-#elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-#endif
-#elif defined(__GNUC__) && !defined(__VXWORKS__)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-#endif
-
#ifndef uthash_malloc
#define uthash_malloc(sz) malloc(sz) /* malloc fcn */
#endif
@@ -92,15 +85,12 @@ typedef unsigned char uint8_t;
#define uthash_strlen(s) strlen(s)
#endif
-#ifdef uthash_memcmp
-/* This warning will not catch programs that define uthash_memcmp AFTER including uthash.h. */
-#warning "uthash_memcmp is deprecated; please use HASH_KEYCMP instead"
-#else
-#define uthash_memcmp(a, b, n) memcmp(a, b, n)
+#ifndef HASH_FUNCTION
+#define HASH_FUNCTION(keyptr, keylen, hashv) HASH_JEN(keyptr, keylen, hashv)
#endif
#ifndef HASH_KEYCMP
-#define HASH_KEYCMP(a, b, n) uthash_memcmp(a, b, n)
+#define HASH_KEYCMP(a, b, n) memcmp(a, b, n)
#endif
#ifndef uthash_noexpand_fyi
@@ -163,7 +153,7 @@ typedef unsigned char uint8_t;
#define HASH_VALUE(keyptr, keylen, hashv) \
do { \
- HASH_FCN(keyptr, keylen, hashv); \
+ HASH_FUNCTION(keyptr, keylen, hashv); \
} while (0)
#define HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, hashval, out) \
@@ -420,7 +410,7 @@ typedef unsigned char uint8_t;
do { \
IF_HASH_NONFATAL_OOM(int _ha_oomed = 0;) \
(add)->hh.hashv = (hashval); \
- (add)->hh.key = (char *)(keyptr); \
+ (add)->hh.key = (const void *)(keyptr); \
(add)->hh.keylen = (unsigned)(keylen_in); \
if (!(head)) { \
(add)->hh.next = NULL; \
@@ -604,13 +594,6 @@ typedef unsigned char uint8_t;
#define HASH_EMIT_KEY(hh, head, keyptr, fieldlen)
#endif
-/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */
-#ifdef HASH_FUNCTION
-#define HASH_FCN HASH_FUNCTION
-#else
-#define HASH_FCN HASH_JEN
-#endif
-
/* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */
#define HASH_BER(key, keylen, hashv) \
do { \
@@ -623,7 +606,9 @@ typedef unsigned char uint8_t;
} while (0)
/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at
- * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
+ * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+ * (archive link: https://archive.is/Ivcan )
+ */
#define HASH_SAX(key, keylen, hashv) \
do { \
unsigned _sx_i; \
@@ -714,37 +699,28 @@ typedef unsigned char uint8_t;
hashv += (unsigned)(keylen); \
switch (_hj_k) { \
case 11: \
- hashv += ((unsigned)_hj_key[10] << 24); \
- H5_ATTR_FALLTHROUGH \
+ hashv += ((unsigned)_hj_key[10] << 24); /* FALLTHROUGH */ \
case 10: \
- hashv += ((unsigned)_hj_key[9] << 16); \
- H5_ATTR_FALLTHROUGH \
+ hashv += ((unsigned)_hj_key[9] << 16); /* FALLTHROUGH */ \
case 9: \
- hashv += ((unsigned)_hj_key[8] << 8); \
- H5_ATTR_FALLTHROUGH \
+ hashv += ((unsigned)_hj_key[8] << 8); /* FALLTHROUGH */ \
case 8: \
- _hj_j += ((unsigned)_hj_key[7] << 24); \
- H5_ATTR_FALLTHROUGH \
+ _hj_j += ((unsigned)_hj_key[7] << 24); /* FALLTHROUGH */ \
case 7: \
- _hj_j += ((unsigned)_hj_key[6] << 16); \
- H5_ATTR_FALLTHROUGH \
+ _hj_j += ((unsigned)_hj_key[6] << 16); /* FALLTHROUGH */ \
case 6: \
- _hj_j += ((unsigned)_hj_key[5] << 8); \
- H5_ATTR_FALLTHROUGH \
+ _hj_j += ((unsigned)_hj_key[5] << 8); /* FALLTHROUGH */ \
case 5: \
- _hj_j += _hj_key[4]; \
- H5_ATTR_FALLTHROUGH \
+ _hj_j += _hj_key[4]; /* FALLTHROUGH */ \
case 4: \
- _hj_i += ((unsigned)_hj_key[3] << 24); \
- H5_ATTR_FALLTHROUGH \
+ _hj_i += ((unsigned)_hj_key[3] << 24); /* FALLTHROUGH */ \
case 3: \
- _hj_i += ((unsigned)_hj_key[2] << 16); \
- H5_ATTR_FALLTHROUGH \
+ _hj_i += ((unsigned)_hj_key[2] << 16); /* FALLTHROUGH */ \
case 2: \
- _hj_i += ((unsigned)_hj_key[1] << 8); \
- H5_ATTR_FALLTHROUGH \
+ _hj_i += ((unsigned)_hj_key[1] << 8); /* FALLTHROUGH */ \
case 1: \
- _hj_i += _hj_key[0]; \
+ _hj_i += _hj_key[0]; /* FALLTHROUGH */ \
+ default:; \
} \
HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
} while (0)
@@ -794,6 +770,8 @@ typedef unsigned char uint8_t;
hashv += *_sfh_key; \
hashv ^= hashv << 10; \
hashv += hashv >> 1; \
+ break; \
+ default:; \
} \
\
/* Force "avalanching" of final 127 bits */ \
@@ -899,12 +877,12 @@ typedef unsigned char uint8_t;
struct UT_hash_handle *_he_thh, *_he_hh_nxt; \
UT_hash_bucket * _he_new_buckets, *_he_newbkt; \
_he_new_buckets = \
- (UT_hash_bucket *)uthash_malloc(2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
+ (UT_hash_bucket *)uthash_malloc(sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
if (!_he_new_buckets) { \
HASH_RECORD_OOM(oomed); \
} \
else { \
- uthash_bzero(_he_new_buckets, 2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \
+ uthash_bzero(_he_new_buckets, sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
(tbl)->ideal_chain_maxlen = \
((tbl)->num_items >> ((tbl)->log2_num_buckets + 1U)) + \
((((tbl)->num_items & (((tbl)->num_buckets * 2U) - 1U)) != 0U) ? 1U : 0U); \
@@ -1186,7 +1164,7 @@ typedef struct UT_hash_handle {
void * next; /* next element in app order */
struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
struct UT_hash_handle *hh_next; /* next hh in bucket order */
- void * key; /* ptr to enclosing struct's key */
+ const void * key; /* ptr to enclosing struct's key */
unsigned keylen; /* enclosing struct's key len */
unsigned hashv; /* result of hash-fcn(key) */
} UT_hash_handle;