From bbfecfe08adba3c0a2ebd589aea8bbfce8bc4011 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Wed, 7 Jun 2023 08:59:54 -0700 Subject: Update uthash and move to H5private.h (#3074) --- src/H5Dmpio.c | 9 ----- src/H5Ipkg.h | 9 ----- src/H5private.h | 10 +++++ src/uthash.h | 115 +++++++++++++++++++++++--------------------------------- 4 files changed, 57 insertions(+), 86 deletions(-) diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c index cc89e44..db4fd62 100644 --- a/src/H5Dmpio.c +++ b/src/H5Dmpio.c @@ -43,15 +43,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/H5Ipkg.h b/src/H5Ipkg.h index 2d1002c..24879c1 100644 --- a/src/H5Ipkg.h +++ b/src/H5Ipkg.h @@ -28,15 +28,6 @@ /* Get package's private header */ #include "H5Iprivate.h" -/* 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" - /**************************/ /* Package Private Macros */ /**************************/ diff --git a/src/H5private.h b/src/H5private.h index ff23370..747c77d 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -251,6 +251,16 @@ #include "dmalloc.h" #endif /* H5_HAVE_DMALLOC_H */ +/* 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 */ +#define HASH_NONFATAL_OOM 1 /* Don't abort() on out-of-memory */ +#include "uthash.h" + /* * NT doesn't define SIGBUS, but since NT only runs on processors * that do not have alignment constraints a SIGBUS would never be diff --git a/src/uthash.h b/src/uthash.h index b738b77..b1e5cbb 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 /* memcmp, memset, strlen */ #include /* ptrdiff_t */ #include /* 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 /* 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 -#elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__) -#include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif -#elif defined(__GNUC__) && !defined(__VXWORKS__) -#include -#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; \ @@ -715,36 +700,28 @@ typedef unsigned char uint8_t; switch (_hj_k) { \ case 11: \ hashv += ((unsigned)_hj_key[10] << 24); \ - H5_ATTR_FALLTHROUGH \ - case 10: \ - hashv += ((unsigned)_hj_key[9] << 16); \ - H5_ATTR_FALLTHROUGH \ - case 9: \ - hashv += ((unsigned)_hj_key[8] << 8); \ - H5_ATTR_FALLTHROUGH \ - case 8: \ - _hj_j += ((unsigned)_hj_key[7] << 24); \ - H5_ATTR_FALLTHROUGH \ - case 7: \ - _hj_j += ((unsigned)_hj_key[6] << 16); \ - H5_ATTR_FALLTHROUGH \ - case 6: \ - _hj_j += ((unsigned)_hj_key[5] << 8); \ - H5_ATTR_FALLTHROUGH \ - case 5: \ - _hj_j += _hj_key[4]; \ - H5_ATTR_FALLTHROUGH \ - case 4: \ - _hj_i += ((unsigned)_hj_key[3] << 24); \ - H5_ATTR_FALLTHROUGH \ - case 3: \ - _hj_i += ((unsigned)_hj_key[2] << 16); \ - H5_ATTR_FALLTHROUGH \ - case 2: \ - _hj_i += ((unsigned)_hj_key[1] << 8); \ - H5_ATTR_FALLTHROUGH \ - case 1: \ - _hj_i += _hj_key[0]; \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 10 : hashv += ((unsigned)_hj_key[9] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 9 : hashv += ((unsigned)_hj_key[8] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 8 : _hj_j += ((unsigned)_hj_key[7] << 24); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 7 : _hj_j += ((unsigned)_hj_key[6] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 6 : _hj_j += ((unsigned)_hj_key[5] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 5 : _hj_j += _hj_key[4]; \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 4 : _hj_i += ((unsigned)_hj_key[3] << 24); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 3 : _hj_i += ((unsigned)_hj_key[2] << 16); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 2 : _hj_i += ((unsigned)_hj_key[1] << 8); \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + case 1 : _hj_i += _hj_key[0]; \ + H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ \ + default:; \ } \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ } while (0) @@ -794,6 +771,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 +878,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 +1165,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; -- cgit v0.12