khash: move khash include into implementation files The current map implementations directly include the "khash.h" headers into their own headers to make available a set of static functions, defines et cetera. Besides leaking the complete khash namespace into files wherever khashes are used, this also triggers Clang's -Wunused-function warnings when some of the static functions are not being used at all. Fix the issue by moving the includes into the respective map implementation files. Add forward declares for all the map types to make them known.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
diff --git a/src/idxmap.c b/src/idxmap.c
index 45f0c22..05a7b2f 100644
--- a/src/idxmap.c
+++ b/src/idxmap.c
@@ -7,6 +7,16 @@
#include "idxmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
+__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
+
/* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */
static kh_inline khint_t idxentry_hash(const git_index_entry *e)
{
@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map)
kh_destroy(idx, map);
}
+void git_idxmap_icase_free(git_idxmap_icase *map)
+{
+ kh_destroy(idxicase, map);
+}
+
void git_idxmap_clear(git_idxmap *map)
{
kh_clear(idx, map);
}
+void git_idxmap_icase_clear(git_idxmap_icase *map)
+{
+ kh_clear(idxicase, map);
+}
+
void git_idxmap_delete_at(git_idxmap *map, size_t idx)
{
kh_del(idx, map, idx);
diff --git a/src/idxmap.h b/src/idxmap.h
index 7fed8b9..215a245 100644
--- a/src/idxmap.h
+++ b/src/idxmap.h
@@ -9,23 +9,10 @@
#include "common.h"
-#include <ctype.h>
#include "git2/index.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
-__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
-
-typedef khash_t(idx) git_idxmap;
-typedef khash_t(idxicase) git_idxmap_icase;
-
-typedef khiter_t git_idxmap_iter;
+typedef struct kh_idx_s git_idxmap;
+typedef struct kh_idxicase_s git_idxmap_icase;
int git_idxmap_alloc(git_idxmap **map);
int git_idxmap_icase_alloc(git_idxmap_icase **map);
@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx);
void git_idxmap_resize(git_idxmap *map, size_t size);
void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size);
void git_idxmap_free(git_idxmap *map);
+void git_idxmap_icase_free(git_idxmap_icase *map);
void git_idxmap_clear(git_idxmap *map);
+void git_idxmap_icase_clear(git_idxmap_icase *map);
void git_idxmap_delete_at(git_idxmap *map, size_t idx);
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
diff --git a/src/offmap.c b/src/offmap.c
index e6e5cfe..d0fa9f0 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -7,6 +7,15 @@
#include "offmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(off, git_off_t, void *)
+
__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
git_offmap *git_offmap_alloc(void)
diff --git a/src/offmap.h b/src/offmap.h
index 82ebfb7..c688093 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -11,15 +11,7 @@
#include "git2/types.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(off, git_off_t, void *)
-typedef khash_t(off) git_offmap;
+typedef struct kh_off_s git_offmap;
git_offmap *git_offmap_alloc(void);
void git_offmap_free(git_offmap *map);
diff --git a/src/oidmap.c b/src/oidmap.c
index a2051f8..c42e5c2 100644
--- a/src/oidmap.c
+++ b/src/oidmap.c
@@ -7,6 +7,15 @@
#include "oidmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(oid, const git_oid *, void *)
+
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
{
khint_t h;
diff --git a/src/oidmap.h b/src/oidmap.h
index f34c034..a417907 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -11,15 +11,7 @@
#include "git2/oid.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(oid, const git_oid *, void *)
-typedef khash_t(oid) git_oidmap;
+typedef struct kh_oid_s git_oidmap;
git_oidmap *git_oidmap_alloc(void);
void git_oidmap_free(git_oidmap *map);
diff --git a/src/strmap.c b/src/strmap.c
index 0c35357..cee7f69 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -7,6 +7,15 @@
#include "strmap.h"
+#define kmalloc git__malloc
+#define kcalloc git__calloc
+#define krealloc git__realloc
+#define kreallocarray git__reallocarray
+#define kfree git__free
+#include "khash.h"
+
+__KHASH_TYPE(str, const char *, void *)
+
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
int git_strmap_alloc(git_strmap **map)
diff --git a/src/strmap.h b/src/strmap.h
index 7856494..2649acb 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -9,16 +9,7 @@
#include "common.h"
-#define kmalloc git__malloc
-#define kcalloc git__calloc
-#define krealloc git__realloc
-#define kreallocarray git__reallocarray
-#define kfree git__free
-#include "khash.h"
-
-__KHASH_TYPE(str, const char *, void *)
-typedef khash_t(str) git_strmap;
-typedef khiter_t git_strmap_iter;
+typedef struct kh_str_s git_strmap;
int git_strmap_alloc(git_strmap **map);
void git_strmap_free(git_strmap *map);