Update uthash v2.3.0 open source code to deps directory

This commit is contained in:
luwenpeng
2022-08-05 10:24:10 +08:00
parent 772f4d8bd8
commit 209d7ea7cd
6 changed files with 43 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ Copyright (c) 2008-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTARRAY_H #ifndef UTARRAY_H
#define UTARRAY_H #define UTARRAY_H
#define UTARRAY_VERSION 2.1.0 #define UTARRAY_VERSION 2.3.0
#include <stddef.h> /* size_t */ #include <stddef.h> /* size_t */
#include <string.h> /* memset, etc */ #include <string.h> /* memset, etc */
@@ -232,8 +232,9 @@ typedef struct {
/* last we pre-define a few icd for common utarrays of ints and strings */ /* last we pre-define a few icd for common utarrays of ints and strings */
static void utarray_str_cpy(void *dst, const void *src) { static void utarray_str_cpy(void *dst, const void *src) {
char **_src = (char**)src, **_dst = (char**)dst; char *const *srcc = (char *const *)src;
*_dst = (*_src == NULL) ? NULL : strdup(*_src); char **dstc = (char**)dst;
*dstc = (*srcc == NULL) ? NULL : strdup(*srcc);
} }
static void utarray_str_dtor(void *elt) { static void utarray_str_dtor(void *elt) {
char **eltc = (char**)elt; char **eltc = (char**)elt;

68
deps/uthash/uthash.h vendored
View File

@@ -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. All rights reserved.
Redistribution and use in source and binary forms, with or without 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 #ifndef UTHASH_H
#define UTHASH_H #define UTHASH_H
#define UTHASH_VERSION 2.1.0 #define UTHASH_VERSION 2.3.0
#include <string.h> /* memcmp, memset, strlen */ #include <string.h> /* memcmp, memset, strlen */
#include <stddef.h> /* ptrdiff_t */ #include <stddef.h> /* ptrdiff_t */
#include <stdlib.h> /* exit */ #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. /* These macros use decltype or the earlier __typeof GNU extension.
As decltype is only available in newer compilers (VS2010 or gcc 4.3+ As decltype is only available in newer compilers (VS2010 or gcc 4.3+
when compiling c++ source) this code uses whatever method is needed when compiling c++ source) this code uses whatever method is needed
@@ -62,23 +72,6 @@ do {
} while (0) } while (0)
#endif #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 #ifndef uthash_malloc
#define uthash_malloc(sz) malloc(sz) /* malloc fcn */ #define uthash_malloc(sz) malloc(sz) /* malloc fcn */
#endif #endif
@@ -92,15 +85,12 @@ typedef unsigned char uint8_t;
#define uthash_strlen(s) strlen(s) #define uthash_strlen(s) strlen(s)
#endif #endif
#ifdef uthash_memcmp #ifndef HASH_FUNCTION
/* This warning will not catch programs that define uthash_memcmp AFTER including uthash.h. */ #define HASH_FUNCTION(keyptr,keylen,hashv) HASH_JEN(keyptr, keylen, hashv)
#warning "uthash_memcmp is deprecated; please use HASH_KEYCMP instead"
#else
#define uthash_memcmp(a,b,n) memcmp(a,b,n)
#endif #endif
#ifndef HASH_KEYCMP #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 #endif
#ifndef uthash_noexpand_fyi #ifndef uthash_noexpand_fyi
@@ -158,7 +148,7 @@ do {
#define HASH_VALUE(keyptr,keylen,hashv) \ #define HASH_VALUE(keyptr,keylen,hashv) \
do { \ do { \
HASH_FCN(keyptr, keylen, hashv); \ HASH_FUNCTION(keyptr, keylen, hashv); \
} while (0) } while (0)
#define HASH_FIND_BYHASHVALUE(hh,head,keyptr,keylen,hashval,out) \ #define HASH_FIND_BYHASHVALUE(hh,head,keyptr,keylen,hashval,out) \
@@ -408,7 +398,7 @@ do {
do { \ do { \
IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; ) \ IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; ) \
(add)->hh.hashv = (hashval); \ (add)->hh.hashv = (hashval); \
(add)->hh.key = (char*) (keyptr); \ (add)->hh.key = (const void*) (keyptr); \
(add)->hh.keylen = (unsigned) (keylen_in); \ (add)->hh.keylen = (unsigned) (keylen_in); \
if (!(head)) { \ if (!(head)) { \
(add)->hh.next = NULL; \ (add)->hh.next = NULL; \
@@ -590,13 +580,6 @@ do {
#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)
#endif #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. */ /* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */
#define HASH_BER(key,keylen,hashv) \ #define HASH_BER(key,keylen,hashv) \
do { \ do { \
@@ -610,7 +593,9 @@ do {
/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at /* 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) \ #define HASH_SAX(key,keylen,hashv) \
do { \ do { \
unsigned _sx_i; \ unsigned _sx_i; \
@@ -695,7 +680,8 @@ do {
case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); /* FALLTHROUGH */ \ case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); /* FALLTHROUGH */ \
case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); /* FALLTHROUGH */ \ case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); /* FALLTHROUGH */ \
case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); /* FALLTHROUGH */ \ case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); /* FALLTHROUGH */ \
case 1: _hj_i += _hj_key[0]; \ case 1: _hj_i += _hj_key[0]; /* FALLTHROUGH */ \
default: ; \
} \ } \
HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
} while (0) } while (0)
@@ -743,6 +729,8 @@ do {
case 1: hashv += *_sfh_key; \ case 1: hashv += *_sfh_key; \
hashv ^= hashv << 10; \ hashv ^= hashv << 10; \
hashv += hashv >> 1; \ hashv += hashv >> 1; \
break; \
default: ; \
} \ } \
\ \
/* Force "avalanching" of final 127 bits */ \ /* Force "avalanching" of final 127 bits */ \
@@ -764,7 +752,7 @@ do {
} \ } \
while ((out) != NULL) { \ while ((out) != NULL) { \
if ((out)->hh.hashv == (hashval) && (out)->hh.keylen == (keylen_in)) { \ if ((out)->hh.hashv == (hashval) && (out)->hh.keylen == (keylen_in)) { \
if (HASH_KEYCMP((out)->hh.key, keyptr, keylen_in) == 0) { \ if (HASH_KEYCMP((out)->hh.key, keyptr, keylen_in) == 0) { \
break; \ break; \
} \ } \
} \ } \
@@ -850,12 +838,12 @@ do {
struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ struct UT_hash_handle *_he_thh, *_he_hh_nxt; \
UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ UT_hash_bucket *_he_new_buckets, *_he_newbkt; \
_he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
if (!_he_new_buckets) { \ if (!_he_new_buckets) { \
HASH_RECORD_OOM(oomed); \ HASH_RECORD_OOM(oomed); \
} else { \ } else { \
uthash_bzero(_he_new_buckets, \ uthash_bzero(_he_new_buckets, \
2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \
(tbl)->ideal_chain_maxlen = \ (tbl)->ideal_chain_maxlen = \
((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \ ((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \
((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \ ((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \
@@ -1142,7 +1130,7 @@ typedef struct UT_hash_handle {
void *next; /* next element in app order */ void *next; /* next element in app order */
struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
struct UT_hash_handle *hh_next; /* next 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 keylen; /* enclosing struct's key len */
unsigned hashv; /* result of hash-fcn(key) */ unsigned hashv; /* result of hash-fcn(key) */
} UT_hash_handle; } UT_hash_handle;

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2007-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ Copyright (c) 2007-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTLIST_H #ifndef UTLIST_H
#define UTLIST_H #define UTLIST_H
#define UTLIST_VERSION 2.1.0 #define UTLIST_VERSION 2.3.0
#include <assert.h> #include <assert.h>

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2015-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ Copyright (c) 2015-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTRINGBUFFER_H #ifndef UTRINGBUFFER_H
#define UTRINGBUFFER_H #define UTRINGBUFFER_H
#define UTRINGBUFFER_VERSION 2.1.0 #define UTRINGBUFFER_VERSION 2.3.0
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2018-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ Copyright (c) 2018-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTSTACK_H #ifndef UTSTACK_H
#define UTSTACK_H #define UTSTACK_H
#define UTSTACK_VERSION 2.1.0 #define UTSTACK_VERSION 2.3.0
/* /*
* This file contains macros to manipulate a singly-linked list as a stack. * This file contains macros to manipulate a singly-linked list as a stack.
@@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* struct item { * struct item {
* int id; * int id;
* struct item *next; * struct item *next;
* } * };
* *
* struct item *stack = NULL: * struct item *stack = NULL;
* *
* int main() { * int main() {
* int count; * int count;

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ Copyright (c) 2008-2022, Troy D. Hanson https://troydhanson.github.io/uthash/
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTSTRING_H #ifndef UTSTRING_H
#define UTSTRING_H #define UTSTRING_H
#define UTSTRING_VERSION 2.1.0 #define UTSTRING_VERSION 2.3.0
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>