Skip to content

Commit 8043418

Browse files
newrenpeff
authored andcommitted
khash: name the structs that khash declares
khash.h lets you instantiate custom hash types that map between two types. These are defined as a struct, as you might expect, and khash typedef's that to kh_foo_t. But it declares the struct anonymously, which doesn't give a name to the struct type itself; there is no "struct kh_foo". This has two small downsides: - when using khash, we declare "kh_foo_t *the_foo". This is unlike our usual naming style, which is "struct kh_foo *the_foo". - you can't forward-declare a typedef of an unnamed struct type in C. So we might do something like this in a header file: struct kh_foo; struct bar { struct kh_foo *the_foo; }; to avoid having to include the header that defines the real kh_foo. But that doesn't work with the typedef'd name. Without the "struct" keyword, the compiler doesn't know we mean that kh_foo is a type. So let's always give khash structs the name that matches our conventions ("struct kh_foo" to match "kh_foo_t"). We'll keep doing the typedef to retain compatibility with existing callers. Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6723899 commit 8043418

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

khash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
6262
static const double __ac_HASH_UPPER = 0.77;
6363

6464
#define __KHASH_TYPE(name, khkey_t, khval_t) \
65-
typedef struct { \
65+
typedef struct kh_##name { \
6666
khint_t n_buckets, size, n_occupied, upper_bound; \
6767
khint32_t *flags; \
6868
khkey_t *keys; \

object-store.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct raw_object_store {
164164
*/
165165
struct object_directory *odb;
166166
struct object_directory **odb_tail;
167-
kh_odb_path_map_t *odb_by_path;
167+
struct kh_odb_path_map *odb_by_path;
168168

169169
int loaded_alternates;
170170

0 commit comments

Comments
 (0)