Browse Source

Eliminate HASH_FCN; change the handling of HASH_FUNCTION to match HASH_KEYCMP.

The behavior of these two "supported" codepaths has not changed at all:

    #define HASH_FUNCTION foo
    #include <uthash.h>
    HASH_VALUE(...)  // expanded to foo(...)

    #include <uthash.h>
    HASH_VALUE(...)  // expanded to HASH_JEN(...)

However, some pathological codepaths have changed.
The old behavior was that if you had defined `HASH_FUNCTION` before
including "uthash.h", then when you called `HASH_VALUE` it would expand
to `HASH_FCN` which would expand to `HASH_FUNCTION`. But if you hadn't
defined `HASH_FUNCTION` before including "uthash.h", then when you
called `HASH_VALUE` it would expand to `HASH_FCN` which would expand
to `HASH_JEN`.

    #define HASH_FUNCTION foo
    #include <uthash.h>
    #undef HASH_FUNCTION
    #define HASH_FUNCTION bar
    HASH_VALUE(...)  // expanded to bar(...)

    #include <uthash.h>
    #undef HASH_FUNCTION  // unneeded, HASH_FUNCTION is undefined
    #define HASH_FUNCTION bar
    HASH_VALUE(...)  // expanded to HASH_JEN(...)

The new behavior is that `HASH_VALUE` expands to `HASH_FUNCTION`;
and separately, if you don't define `HASH_FUNCTION` before including
"uthash.h", we'll default it to `HASH_JEN`.

    #define HASH_FUNCTION foo
    #include <uthash.h>
    #undef HASH_FUNCTION
    #define HASH_FUNCTION bar
    HASH_VALUE(...)  // expanded to bar(...)

    #include <uthash.h>
    #undef HASH_FUNCTION  // needed, HASH_FUNCTION is defined to HASH_JEN
    #define HASH_FUNCTION bar
    HASH_VALUE(...)  // expanded to bar(...)

This is the way `HASH_KEYCMP` (formerly known as `uthash_memcmp`) has
always worked. Since these two customization points are used in similar
ways, it'll be nice to have their codepaths work alike instead of
subtly different. Also, this gets rid of one level of macro indirection
(`HASH_FCN` no longer exists), hooray!
Arthur O'Dwyer 4 years ago
parent
commit
053bed1245
1 changed files with 5 additions and 8 deletions
  1. 5 8
      src/uthash.h

+ 5 - 8
src/uthash.h

@@ -92,6 +92,10 @@ do {
 #define uthash_memcmp(a,b,n) memcmp(a,b,n)
 #define uthash_memcmp(a,b,n) memcmp(a,b,n)
 #endif
 #endif
 
 
+#ifndef HASH_FUNCTION
+#define HASH_FUNCTION(keyptr,keylen,hashv) HASH_JEN(keyptr, keylen, hashv)
+#endif
+
 #ifndef HASH_KEYCMP
 #ifndef HASH_KEYCMP
 #define HASH_KEYCMP(a,b,n) uthash_memcmp(a,b,n)
 #define HASH_KEYCMP(a,b,n) uthash_memcmp(a,b,n)
 #endif
 #endif
@@ -151,7 +155,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)                 \
@@ -583,13 +587,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 {                                                                             \