Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Tielen committed Aug 10, 2023
1 parent f0ba1fc commit 3676283
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 96 deletions.
18 changes: 13 additions & 5 deletions include/sdb/cwisstable.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@
CWISS_GCC_ALLOW("-Wunused-function") \
CWISS_GCC_ALLOW("-Wunused-parameter") \
CWISS_GCC_ALLOW("-Wcast-qual") \
CWISS_GCC_ALLOW("-Wmissing-field-initializers") \
CWISS_GCC_ALLOW("-Wtypedef-redefinition")
CWISS_GCC_ALLOW("-Wmissing-field-initializers")
#define CWISS_END CWISS_GCC_POP

/// `CWISS_HAVE_SSE2` is nonzero if we have SSE2 support.
Expand Down Expand Up @@ -201,11 +200,20 @@
/// quite believe in it.
#if CWISS_IS_MSVC
#define CWISS_alignas(align_) __declspec(align(align_))
#define alignof __alignof

#else
#include <stdalign.h>

#ifdef alignas
#define CWISS_alignas(align_) alignas(align_)
#else
#define CWISS_alignas(align_) __attribute__((aligned(align_)))
#endif

#endif

#ifndef alignof
#define alignof __alignof
#endif

/// `CWISS_HAVE_BUILTIN` will, in Clang, detect whether a Clang language
Expand Down Expand Up @@ -1639,7 +1647,7 @@ typedef struct {
///
/// See the header documentation for more information.
#define CWISS_DECLARE_NODE_MAP_POLICY(kPolicy_, K_, V_, obj_copy, obj_dtor, key_hash, key_eq) \
typedef struct kPolicy_##_entry_t { \
typedef struct kPolicy_##_entry_t { \
K_ k; \
V_ v; \
} kPolicy_##_Entry; \
Expand Down Expand Up @@ -2674,7 +2682,7 @@ CWISS_BEGIN_EXTERN
/// See header documentation for examples of generated API.
#define CWISS_DECLARE_NODE_HASHMAP(HashMap_, K_, V_, a,b,c,d) \
CWISS_DECLARE_NODE_MAP_POLICY(HashMap_##_kPolicy, K_, V_, a,b,c,d); \
CWISS_DECLARE_HASHMAP_WITH(HashMap_, K_, V_, HashMap_##_kPolicy)
CWISS_DECLARE_HASHMAP_WITH(HashMap_, K_, V_, HashMap_##_kPolicy)

#define CWISS_DECLARE_NODE_HASHMAP_DEFAULT(HashMap_, K_, V_) \
typedef struct { \
Expand Down
1 change: 0 additions & 1 deletion include/sdb/ht_pu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern "C" {
typedef uint64_t ut64;

typedef struct HtPU_t HtPU;
typedef struct HtPU_entry_t HtPU_Entry;

typedef bool (*HtPUForEachCallback)(void *user, const void *key, const ut64 value);

Expand Down
1 change: 0 additions & 1 deletion include/sdb/ht_su.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extern "C" {
typedef uint64_t ut64;

typedef struct HtSU_t HtSU;
typedef struct HtSU_entry_t HtSU_Entry;

typedef bool (*HtSUForEachCallback)(void *user, const char *key, const ut64 value);

Expand Down
2 changes: 0 additions & 2 deletions include/sdb/ht_uu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ extern "C" {
#endif

typedef struct HtUU_t HtUU;
typedef struct HtUU_entry_t HtUU_Entry;

typedef bool (*HtUUForEachCallback)(void *user, const ut64 key, const ut64 value);

SDB_API HtUU* ht_uu_new0(void);
Expand Down
51 changes: 24 additions & 27 deletions src/ht_pu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,43 @@
#include "sdb/heap.h"
#include "sdb/cwisstable.h"

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtypedef-redefinition"
#endif
CWISS_DECLARE_FLAT_HASHMAP_DEFAULT(HtPU, void*, ut64);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
CWISS_DECLARE_FLAT_HASHMAP_DEFAULT(HtPU_, void*, ut64);

Check notice

Code scanning / CodeQL

Unused static function Note

Static function HtPU__contains is unreachable
Static function HtPU__cfind is unreachable
Static function HtPU__find_hinted is unreachable
Static function HtPU__cfind_hinted is unreachable
Static function HtPU__deferred_insert is unreachable
Static function HtPU__clear is unreachable
Static function HtPU__capacity is unreachable
Static function HtPU__size is unreachable
Static function HtPU__empty is unreachable
Static function HtPU__rehash is unreachable
Static function HtPU__reserve is unreachable
Static function HtPU__Iter_const is unreachable
Static function HtPU__Iter_next is unreachable
Static function HtPU__iter is unreachable
Static function HtPU__dup is unreachable
Static function HtPU__policy is unreachable

struct HtPU_t {
HtPU_ inner;
};

SDB_API HtPU* ht_pu_new0(void) {
HtPU *hm = sdb_gh_calloc (1, sizeof (HtPU));
HtPU *hm = (HtPU*) sdb_gh_calloc (1, sizeof (HtPU));
if (hm) {
*hm = HtPU_new (0);
hm->inner = HtPU__new (0);
}
return hm;
}

SDB_API void ht_pu_free(HtPU *hm) {
if (hm) {
HtPU_destroy (hm);
HtPU__destroy (&hm->inner);
sdb_gh_free (hm);
}
}

SDB_API bool ht_pu_insert(HtPU *hm, void *key, ut64 value) {
assert (hm);

HtPU_Entry entry = { .key = key, .val = value };
HtPU_Insert result = HtPU_insert (hm, &entry);
HtPU__Entry entry = { .key = key, .val = value };
HtPU__Insert result = HtPU__insert (&hm->inner, &entry);
return result.inserted;
}

SDB_API bool ht_pu_update(HtPU *hm, void *key, ut64 value) {
assert (hm);

HtPU_Entry entry = { .key = key, .val = value };
HtPU_Insert insert_result = HtPU_insert (hm, &entry);
HtPU__Entry entry = { .key = key, .val = value };
HtPU__Insert insert_result = HtPU__insert (&hm->inner, &entry);
const bool should_update = !insert_result.inserted;
if (should_update) {
HtPU_Entry *existing_entry = HtPU_Iter_get (&insert_result.iter);
HtPU__Entry *existing_entry = HtPU__Iter_get (&insert_result.iter);
existing_entry->val = value;
}

Expand All @@ -55,27 +52,27 @@ SDB_API bool ht_pu_update(HtPU *hm, void *key, ut64 value) {
SDB_API bool ht_pu_update_key(HtPU *hm, void *old_key, void *new_key) {
assert (hm);

HtPU_Iter iter = HtPU_find (hm, &old_key);
HtPU_Entry *entry = HtPU_Iter_get (&iter);
HtPU__Iter iter = HtPU__find (&hm->inner, &old_key);
HtPU__Entry *entry = HtPU__Iter_get (&iter);
if (!entry) {
return false;
}

// First try inserting the new key
HtPU_Entry new_entry = { .key = new_key, .val = entry->val };
HtPU_Insert result = HtPU_insert (hm, &new_entry);
HtPU__Entry new_entry = { .key = new_key, .val = entry->val };
HtPU__Insert result = HtPU__insert (&hm->inner, &new_entry);
if (!result.inserted) {
return false;
}

// Then remove entry for the old key
HtPU_erase_at (iter);
HtPU__erase_at (iter);
return true;
}

SDB_API bool ht_pu_delete(HtPU *hm, void *key) {
assert (hm);
return HtPU_erase (hm, &key);
return HtPU__erase (&hm->inner, &key);
}

SDB_API ut64 ht_pu_find(HtPU *hm, void *key, bool* found) {
Expand All @@ -84,8 +81,8 @@ SDB_API ut64 ht_pu_find(HtPU *hm, void *key, bool* found) {
*found = false;
}

HtPU_Iter iter = HtPU_find (hm, &key);
HtPU_Entry *entry = HtPU_Iter_get (&iter);
HtPU__Iter iter = HtPU__find (&hm->inner, &key);
HtPU__Entry *entry = HtPU__Iter_get (&iter);
if (!entry) {
return 0;
}
Expand All @@ -101,9 +98,9 @@ SDB_API ut64 ht_pu_find(HtPU *hm, void *key, bool* found) {
// cb should not modify the hashtable.
SDB_API void ht_pu_foreach(HtPU *hm, HtPUForEachCallback cb, void *user) {
assert (hm);
HtPU_CIter iter;
const HtPU_Entry *entry;
for (iter = HtPU_citer (hm); (entry = HtPU_CIter_get (&iter)) != NULL; HtPU_CIter_next (&iter)) {
HtPU__CIter iter;
const HtPU__Entry *entry;
for (iter = HtPU__citer (&hm->inner); (entry = HtPU__CIter_get (&iter)) != NULL; HtPU__CIter_next (&iter)) {
if (!cb (user, entry->key, entry->val)) {
return;
}
Expand Down
61 changes: 28 additions & 33 deletions src/ht_su.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
#include "sdb/ht_su.h"
#include "sdb/heap.h"
#include "sdb/sdb.h"
#include "../../../libr/include/cwisstable.h" // XXX use cwisstable from sdb itself

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtypedef-redefinition"
#endif
#include "sdb/cwisstable.h"

static inline void string_copy(void *dst, const void *src);
static inline void string_dtor(void *val);
static inline size_t string_hash(const void *val);
static inline bool string_eq(const void *a, const void *b);

CWISS_DECLARE_FLAT_HASHMAP(HtSU, char*, float, string_copy, string_dtor, string_hash, string_eq);
CWISS_DECLARE_FLAT_HASHMAP(HtSU_, char*, float, string_copy, string_dtor, string_hash, string_eq);

Check notice

Code scanning / CodeQL

Unused static function Note

Static function HtSU__contains is unreachable
Static function HtSU__cfind is unreachable
Static function HtSU__find_hinted is unreachable
Static function HtSU__cfind_hinted is unreachable
Static function HtSU__deferred_insert is unreachable
Static function HtSU__clear is unreachable
Static function HtSU__capacity is unreachable
Static function HtSU__size is unreachable
Static function HtSU__empty is unreachable
Static function HtSU__rehash is unreachable
Static function HtSU__reserve is unreachable
Static function HtSU__Iter_const is unreachable
Static function HtSU__Iter_next is unreachable
Static function HtSU__iter is unreachable
Static function HtSU__dup is unreachable
Static function HtSU__policy is unreachable

struct HtSU_t {
HtSU_ inner;
};

static inline void string_copy(void *dst_, const void *src_) {
const HtSU_Entry *src = src_;
HtSU_Entry *dst = dst_;
const HtSU__Entry *src = (const HtSU__Entry *) src_;
HtSU__Entry *dst = (HtSU__Entry *) dst_;

const size_t len = strlen (src->key);
dst->key = sdb_gh_malloc (len + 1);
dst->key = (char*) sdb_gh_malloc (len + 1);
dst->val = src->val;
memcpy (dst->key, src->key, len + 1);
}
Expand All @@ -47,21 +46,17 @@ static inline bool string_eq(const void *a, const void *b) {
return strcmp (ap, bp) == 0;
}

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

SDB_API HtSU* ht_su_new0(void) {
HtSU *hm = sdb_gh_calloc (1, sizeof (HtSU));
HtSU *hm = (HtSU*) sdb_gh_calloc (1, sizeof (HtSU));
if (hm) {
*hm = HtSU_new (0);
hm->inner = HtSU__new (0);
}
return hm;
}

SDB_API void ht_su_free(HtSU *hm) {
if (hm) {
HtSU_destroy (hm);
HtSU__destroy (&hm->inner);
sdb_gh_free (hm);
}
}
Expand All @@ -74,8 +69,8 @@ SDB_API bool ht_su_insert(HtSU *hm, const char *key, ut64 value) {
return false;
}

HtSU_Entry entry = { .key = key_copy, .val = value };
HtSU_Insert result = HtSU_insert (hm, &entry);
HtSU__Entry entry = { .key = key_copy, .val = value };
HtSU__Insert result = HtSU__insert (&hm->inner, &entry);
if (!result.inserted) {
sdb_gh_free (key_copy);
return false;
Expand All @@ -91,12 +86,12 @@ SDB_API bool ht_su_update(HtSU *hm, const char *key, ut64 value) {
return false;
}

HtSU_Entry entry = { .key = key_copy, .val = value };
HtSU_Insert insert_result = HtSU_insert (hm, &entry);
HtSU__Entry entry = { .key = key_copy, .val = value };
HtSU__Insert insert_result = HtSU__insert (&hm->inner, &entry);
if (!insert_result.inserted) {
sdb_gh_free (key_copy);

HtSU_Entry *existing_entry = HtSU_Iter_get (&insert_result.iter);
HtSU__Entry *existing_entry = HtSU__Iter_get (&insert_result.iter);
existing_entry->val = value;
}

Expand All @@ -107,8 +102,8 @@ SDB_API bool ht_su_update(HtSU *hm, const char *key, ut64 value) {
SDB_API bool ht_su_update_key(HtSU *hm, const char *old_key, const char *new_key) {
assert (hm && old_key && new_key);

HtSU_Iter iter = HtSU_find (hm, (const HtSU_Key*) &old_key);
HtSU_Entry *entry = HtSU_Iter_get (&iter);
HtSU__Iter iter = HtSU__find (&hm->inner, (const HtSU__Key*) &old_key);
HtSU__Entry *entry = HtSU__Iter_get (&iter);
if (!entry) {
return false;
}
Expand All @@ -124,21 +119,21 @@ SDB_API bool ht_su_update_key(HtSU *hm, const char *old_key, const char *new_key
}

// First try inserting the new key
HtSU_Entry new_entry = { .key = key_copy, .val = entry->val };
HtSU_Insert result = HtSU_insert (hm, &new_entry);
HtSU__Entry new_entry = { .key = key_copy, .val = entry->val };
HtSU__Insert result = HtSU__insert (&hm->inner, &new_entry);
if (!result.inserted) {
sdb_gh_free (key_copy);
return false;
}

// Then remove entry for the old key
HtSU_erase_at (iter);
HtSU__erase_at (iter);
return true;
}

SDB_API bool ht_su_delete(HtSU *hm, const char *key) {
assert (hm && key);
return HtSU_erase (hm, (const HtSU_Key*) &key);
return HtSU__erase (&hm->inner, (const HtSU__Key*) &key);
}

SDB_API ut64 ht_su_find(HtSU *hm, const char *key, bool* found) {
Expand All @@ -148,8 +143,8 @@ SDB_API ut64 ht_su_find(HtSU *hm, const char *key, bool* found) {
*found = false;
}

HtSU_Iter iter = HtSU_find (hm, (const HtSU_Key*) &key);
HtSU_Entry *entry = HtSU_Iter_get (&iter);
HtSU__Iter iter = HtSU__find (&hm->inner, (const HtSU__Key*) &key);
HtSU__Entry *entry = HtSU__Iter_get (&iter);
if (!entry) {
return 0;
}
Expand All @@ -165,10 +160,10 @@ SDB_API ut64 ht_su_find(HtSU *hm, const char *key, bool* found) {
// cb should not modify the hashtable.
SDB_API void ht_su_foreach(HtSU *hm, HtSUForEachCallback cb, void *user) {
assert (hm);
HtSU_CIter iter;
const HtSU_Entry *entry;
HtSU__CIter iter;
const HtSU__Entry *entry;

for (iter = HtSU_citer (hm); (entry = HtSU_CIter_get (&iter)) != NULL; HtSU_CIter_next (&iter)) {
for (iter = HtSU__citer (&hm->inner); (entry = HtSU__CIter_get (&iter)) != NULL; HtSU__CIter_next (&iter)) {
if (!cb (user, entry->key, entry->val)) {
return;
}
Expand Down
Loading

0 comments on commit 3676283

Please sign in to comment.