git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 20/20] hashmap_entry: remove first member requirement from docs

From
EWEric Wong <e@80x24.org>
Date
Oct 6, 2019, 23:30 UTC
Message-ID
<20191006233043.3516-21-e@80x24.org>
In-Reply-To
<20191006233043.3516-1-e@80x24.org>

Comments stating that "struct hashmap_entry" must be the first member in a struct are no longer valid.

Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Eric Wong <e@80x24.org>
---
 attr.c                  | 2 +-
 builtin/fetch.c         | 2 +-
 hashmap.h               | 4 ++--
 merge-recursive.h       | 4 ++--
 ref-filter.c            | 2 +-
 refs.c                  | 2 +-
 remote.h                | 2 +-
 sub-process.h           | 2 +-
 t/helper/test-hashmap.c | 1 +
 9 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/attr.c b/attr.c
index 15f0efdf60..e5c951db69 100644
--- a/attr.c
+++ b/attr.c
@@ -62,7 +62,7 @@ static struct attr_hashmap g_attr_hashmap;
 
 /* The container for objects stored in "struct attr_hashmap" */
 struct attr_hash_entry {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 	const char *key; /* the key; memory should be owned by value */
 	size_t keylen; /* length of the key */
 	void *value; /* the stored value */
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 09f7170616..a3154a4edb 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -251,7 +251,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
 }
 
 struct refname_hash_entry {
-	struct hashmap_entry ent; /* must be the first member */
+	struct hashmap_entry ent;
 	struct object_id oid;
 	int ignore;
 	char refname[FLEX_ARRAY];
diff --git a/hashmap.h b/hashmap.h
index bf4a05937d..bd2701549f 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -13,7 +13,7 @@
  *
  * struct hashmap map;
  * struct long2string {
- *     struct hashmap_entry ent; // must be the first member!
+ *     struct hashmap_entry ent;
  *     long key;
  *     char value[FLEX_ARRAY];   // be careful with allocating on stack!
  * };
@@ -141,7 +141,7 @@ static inline unsigned int oidhash(const struct object_id *oid)
 
 /*
  * struct hashmap_entry is an opaque structure representing an entry in the
- * hash table, which must be used as first member of user data structures.
+ * hash table.
  * Ideally it should be followed by an int-sized member to prevent unused
  * memory on 64-bit systems due to alignment.
  */
diff --git a/merge-recursive.h b/merge-recursive.h
index c2b7bb65c6..daa742568e 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -50,7 +50,7 @@ struct merge_options {
  *                       in get_directory_renames() for details
  */
 struct dir_rename_entry {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 	char *dir;
 	unsigned non_unique_new_dir:1;
 	struct strbuf new_dir;
@@ -58,7 +58,7 @@ struct dir_rename_entry {
 };
 
 struct collision_entry {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 	char *target_file;
 	struct string_list source_files;
 	unsigned reported_already:1;
diff --git a/ref-filter.c b/ref-filter.c
index 0950b789e3..5c10a343c6 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -79,7 +79,7 @@ static struct expand_data {
 } oi, oi_deref;
 
 struct ref_to_worktree_entry {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 	struct worktree *wt; /* key is wt->head_ref */
 };
 
diff --git a/refs.c b/refs.c
index 2d3eb40f39..1ab0bb54d3 100644
--- a/refs.c
+++ b/refs.c
@@ -1772,7 +1772,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
 
 struct ref_store_hash_entry
 {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 
 	struct ref_store *refs;
 
diff --git a/remote.h b/remote.h
index 83e885672b..0e1d2b245b 100644
--- a/remote.h
+++ b/remote.h
@@ -14,7 +14,7 @@ enum {
 };
 
 struct remote {
-	struct hashmap_entry ent;  /* must be first */
+	struct hashmap_entry ent;
 
 	const char *name;
 	int origin, configured_in_repo;
diff --git a/sub-process.h b/sub-process.h
index 0d12708b8c..e85f21fa1a 100644
--- a/sub-process.h
+++ b/sub-process.h
@@ -24,7 +24,7 @@
 
 /* Members should not be accessed directly. */
 struct subprocess_entry {
-	struct hashmap_entry ent; /* must be the first member! */
+	struct hashmap_entry ent;
 	const char *cmd;
 	struct child_process process;
 };
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
index cc577c8956..f38706216f 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
@@ -5,6 +5,7 @@
 
 struct test_entry
 {
+	int padding; /* hashmap entry no longer needs to be the first member */
 	struct hashmap_entry ent;
 	/* key and value as two \0-terminated strings */
 	char key[FLEX_ARRAY];
Previous: Eric WongNext: Junio C Hamano
Message 21 of 30 in “hashmap bug/safety/ease-of-use fixes”
  1. 00/20 hashmap bug/safety/ease-of-use fixesEric Wong, Oct 6, 2019
  2. 01/20 diff: use hashmap_entry_init on moved_entry.entEric Wong, Oct 6, 2019
  3. 02/20 coccicheck: detect hashmap_entry.hash assignmentEric Wong, Oct 6, 2019
  4. 04/20 hashmap_entry_init takes "struct hashmap_entry *"Eric Wong, Oct 6, 2019
  5. 03/20 packfile: use hashmap_entry in delta_base_cache_entryEric Wong, Oct 6, 2019
  6. 05/20 hashmap_get_next takes "const struct hashmap_entry *"Eric Wong, Oct 6, 2019
  7. 06/20 hashmap_add takes "struct hashmap_entry *"Eric Wong, Oct 6, 2019
  8. 07/20 hashmap_get takes "const struct hashmap_entry *"Eric Wong, Oct 6, 2019
  9. 08/20 hashmap_remove takes "const struct hashmap_entry *"Eric Wong, Oct 6, 2019
  10. 09/20 hashmap_put takes "struct hashmap_entry *"Eric Wong, Oct 6, 2019
  11. 10/20 introduce container_of macroEric Wong, Oct 6, 2019
  12. 11/20 hashmap_get_next returns "struct hashmap_entry *"Eric Wong, Oct 6, 2019
  13. 12/20 hashmap: use *_entry APIs to wrap container_ofEric Wong, Oct 6, 2019
  14. 13/20 hashmap_get{,_from_hash} return "struct hashmap_entry *"Eric Wong, Oct 6, 2019
  15. 14/20 hashmap_cmp_fn takes hashmap_entry paramsEric Wong, Oct 6, 2019
  16. 15/20 hashmap: use *_entry APIs for iterationEric Wong, Oct 6, 2019
  17. 16/20 hashmap: hashmap_{put,remove} return hashmap_entry *Eric Wong, Oct 6, 2019
  18. 17/20 hashmap: introduce hashmap_free_entriesEric Wong, Oct 6, 2019
  19. 18/20 OFFSETOF_VAR macro to simplify hashmap iteratorsEric Wong, Oct 6, 2019
  20. 19/20 hashmap: remove type arg from hashmap_{get,put,remove}_entryEric Wong, Oct 6, 2019
  21. 20/20 hashmap_entry: remove first member requirement from docsEric Wong, Oct 6, 2019
  22. Junio C HamanoOct 7, 2019
  23. 21/20 convert: drop invalid comment for subprocess_entryEric Wong, Oct 7, 2019
  24. Junio C HamanoOct 8, 2019
  25. Eric WongOct 8, 2019
  26. Junio C HamanoOct 7, 2019
  27. Johannes SchindelinOct 8, 2019
  28. Derrick StoleeOct 8, 2019
  29. Derrick StoleeOct 8, 2019
  30. Junio C HamanoOct 9, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.