diff --git a/src/Makefile b/src/Makefile index 29f9fad10..e228a4ff2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -270,7 +270,7 @@ $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) -dict-benchmark: dict.c zmalloc.c sds.c siphash.c +dict-benchmark: dict.cpp zmalloc.c sds.c siphash.c $(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS) # Because the jemalloc.h header is generated as a part of the jemalloc build, diff --git a/src/dict.c b/src/dict.cpp similarity index 98% rename from src/dict.c rename to src/dict.cpp index 9b5aba452..2cfc25334 100644 --- a/src/dict.c +++ b/src/dict.cpp @@ -84,11 +84,11 @@ uint8_t *dictGetHashFunctionSeed(void) { /* The default hashing function uses SipHash implementation * in siphash.c. */ -uint64_t siphash(const uint8_t *in, const size_t inlen, const uint8_t *k); -uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k); +extern "C" uint64_t siphash(const uint8_t *in, const size_t inlen, const uint8_t *k); +extern "C" uint64_t siphash_nocase(const uint8_t *in, const size_t inlen, const uint8_t *k); uint64_t dictGenHashFunction(const void *key, int len) { - return siphash(key,len,dict_hash_function_seed); + return siphash((const uint8_t*)key,len,dict_hash_function_seed); } uint64_t dictGenCaseHashFunction(const unsigned char *buf, int len) { @@ -111,7 +111,7 @@ static void _dictReset(dictht *ht) dict *dictCreate(dictType *type, void *privDataPtr) { - dict *d = zmalloc(sizeof(*d), MALLOC_SHARED); + dict *d = (dict*)zmalloc(sizeof(*d), MALLOC_SHARED); _dictInit(d,type,privDataPtr); return d; @@ -160,7 +160,7 @@ int dictExpand(dict *d, unsigned long size) /* Allocate the new hash table and initialize all pointers to NULL */ n.size = realsize; n.sizemask = realsize-1; - n.table = zcalloc(realsize*sizeof(dictEntry*), MALLOC_SHARED); + n.table = (dictEntry**)zcalloc(realsize*sizeof(dictEntry*), MALLOC_SHARED); n.used = 0; /* Is this the first initialization? If so it's not really a rehashing @@ -307,7 +307,7 @@ dictEntry *dictAddRaw(dict *d, void *key, dictEntry **existing) * system it is more likely that recently added entries are accessed * more frequently. */ ht = dictIsRehashing(d) ? &d->ht[1] : &d->ht[0]; - entry = zmalloc(sizeof(*entry), MALLOC_SHARED); + entry = (dictEntry*)zmalloc(sizeof(*entry), MALLOC_SHARED); entry->next = ht->table[index]; ht->table[index] = entry; ht->used++; @@ -541,7 +541,7 @@ long long dictFingerprint(dict *d) { dictIterator *dictGetIterator(dict *d) { - dictIterator *iter = zmalloc(sizeof(*iter), MALLOC_LOCAL); + dictIterator *iter = (dictIterator*)zmalloc(sizeof(*iter), MALLOC_LOCAL); iter->d = d; iter->table = 0; diff --git a/src/redisassert.h b/src/redisassert.h index 61ab35a14..e120cb6e1 100644 --- a/src/redisassert.h +++ b/src/redisassert.h @@ -40,10 +40,18 @@ #include /* for _exit() */ +#ifdef __cplusplus +extern "C" { +#endif + #define assert(_e) ((_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),_exit(1))) #define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),_exit(1) -void _serverAssert(char *estr, char *file, int line); +void _serverAssert(const char *estr, const char *file, int line); void _serverPanic(const char *file, int line, const char *msg, ...); +#ifdef __cplusplus +} +#endif + #endif