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

[PATCH 1/2] oidmap: make oidmap_free independent of struct layout

From
Abhishek Kumar <abhishekkumar8222@gmail.com>
Date
Apr 8, 2020, 04:06 UTC
Message-ID
<20200408040659.14511-1-abhishekkumar8222@gmail.com>

c8e424c introduced hashmap_free_entries, which can free any struct pointer, regardless of the hashmap_entry field offset.

oidmap does not make use of this flexibilty, hardcoding the offset to zero instead. Let's fix this by passing struct type and member to hashmap_free_entries.

Additionally, removes an erroneous semi-colon at the end of hashmap_free_entries macro.

Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com>
---
 hashmap.h | 2 +-
 oidmap.c  | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/hashmap.h b/hashmap.h
index 79ae9f80de..6d0a65a39f 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -245,7 +245,7 @@ void hashmap_free_(struct hashmap *map, ssize_t offset);
  * where @member is the hashmap_entry struct used to associate with @map
  */
 #define hashmap_free_entries(map, type, member) \
-	hashmap_free_(map, offsetof(type, member));
+	hashmap_free_(map, offsetof(type, member))
 
 /* hashmap_entry functions */
 
diff --git a/oidmap.c b/oidmap.c
index 423aa014a3..65d63787a8 100644
--- a/oidmap.c
+++ b/oidmap.c
@@ -26,8 +26,10 @@ void oidmap_free(struct oidmap *map, int free_entries)
 	if (!map)
 		return;
 
-	/* TODO: make oidmap itself not depend on struct layouts */
-	hashmap_free_(&map->map, free_entries ? 0 : -1);
+	if (free_entries)
+		hashmap_free_entries(&map->map, struct oidmap_entry, internal_entry);
+	else
+		hashmap_free(&map->map);
 }
 
 void *oidmap_get(const struct oidmap *map, const struct object_id *key)
-- 
2.26.0
Next: Abhishek Kumar
Message 1 of 10 in “oidmap: make oidmap_free independent of struct layout”
  1. 1/2 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 8, 2020
  2. 2/2 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 8, 2020
  3. Junio C HamanoApr 8, 2020
  4. 1/2 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 8, 2020
  5. 2/2 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 8, 2020
  6. Jeff KingApr 8, 2020
  7. Jeff KingApr 8, 2020
  8. 1/3 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 25, 2020
  9. 2/3 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 25, 2020
  10. 3/3 oidmap: return oidmap_entry pointersAbhishek Kumar, Apr 25, 2020

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.