diff mbox series

[v3,25/28] khash: name the structs that khash declares

Message ID 6de1eebfea65c8a66bb7270fc7fb550d25d7d3f6.1684218853.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit aaf326e1cd060938c6feea2a366a605fb915f233
Headers show
Series Header cleanups (final splitting of cache.h, and some splitting of other headers) | expand

Commit Message

Elijah Newren May 16, 2023, 6:34 a.m. UTC
From: Elijah Newren <newren@gmail.com>

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 <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 khash.h        | 2 +-
 object-store.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/khash.h b/khash.h
index 56241e6a5c9..a0a08dad8b7 100644
--- a/khash.h
+++ b/khash.h
@@ -62,7 +62,7 @@  static inline khint_t __ac_X31_hash_string(const char *s)
 static const double __ac_HASH_UPPER = 0.77;
 
 #define __KHASH_TYPE(name, khkey_t, khval_t) \
-	typedef struct { \
+	typedef struct kh_##name { \
 		khint_t n_buckets, size, n_occupied, upper_bound; \
 		khint32_t *flags; \
 		khkey_t *keys; \
diff --git a/object-store.h b/object-store.h
index 12415e5ea73..05803a03e92 100644
--- a/object-store.h
+++ b/object-store.h
@@ -164,7 +164,7 @@  struct raw_object_store {
 	 */
 	struct object_directory *odb;
 	struct object_directory **odb_tail;
-	kh_odb_path_map_t *odb_by_path;
+	struct kh_odb_path_map *odb_by_path;
 
 	int loaded_alternates;