summaryrefslogtreecommitdiff
path: root/src/strmap.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-03-20 09:01:18 +0100
committerPatrick Steinhardt <ps@pks.im>2017-03-20 09:01:18 +0100
commit94af9155cf908f402e07408d900177280c2e90bb (patch)
tree492d150ff5713cb967b3d1ebdde1404a359516aa /src/strmap.h
parent77c8ee74ff0f0ef4462fd6e963bc993c7a9721b3 (diff)
downloadlibgit2-94af9155cf908f402e07408d900177280c2e90bb.tar.gz
map: remove `*map_free` macros
The `map_free` functions were not implemented as functions but instead as macros which also set the map to NULL. While this is most certainly sensible in most cases, we should prefer the more obvious behavior, namingly leaving the map pointer intact. Furthermore, this macro has been refactored incorrectly during the map-refactorings: the two statements are not actually grouped together by a `do { ... } while (0)` block, as it is required for macros to match the behavior of functions more closely. This has led to at least one subtle nesting error in `pack-objects.c`. The following code block ``` if (pb->object_ix) git_oidmap_free(pb->object_ix); ``` would be expanded to ``` if (pb->object_ix) git_oidmap__free(pb->object_ix); pb->object_ix = NULL; ``` which is not what one woudl expect. While it is not a bug here as it would simply become a no-op, the wrong implementation could lead to bugs in other occasions. Fix this by simply removing the macro altogether and replacing it with real function calls. This leaves the burden of setting the pointer to NULL afterwards to the caller, but this is actually expected and behaves like other `free` functions.
Diffstat (limited to 'src/strmap.h')
-rw-r--r--src/strmap.h4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/strmap.h b/src/strmap.h
index 389702c9b..802b92494 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -21,9 +21,7 @@ typedef khash_t(str) git_strmap;
typedef khiter_t git_strmap_iter;
int git_strmap_alloc(git_strmap **map);
-
-#define git_strmap_free(h) git_strmap__free(h); (h) = NULL
-void git_strmap__free(git_strmap *map);
+void git_strmap_free(git_strmap *map);
void git_strmap_clear(git_strmap *map);
size_t git_strmap_num_entries(git_strmap *map);