summaryrefslogtreecommitdiff
path: root/src/shared/hashmap.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2015-04-10 11:15:12 +0200
committerAnthony G. Basile <blueness@gentoo.org>2015-04-12 18:16:35 -0400
commitc9853d8cda5d28e27ea4ef61630ddab88d85f68f (patch)
treeb8532299229b4dbc7e706cd22430df079c16f0fd /src/shared/hashmap.c
parent461300d949a1a50a665d69ba68c03160e65e6bf4 (diff)
hashmap: return NULL from destructor
We _always_ return NULL from destructors to allow direct assignments to the variable holding the object. Especially on hashmaps, which treat NULL as empty hashmap, this is pretty neat. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/hashmap.c')
-rw-r--r--src/shared/hashmap.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index 9cfdc60930..084743e4fb 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -864,38 +864,41 @@ static void hashmap_free_no_clear(HashmapBase *h) {
free(h);
}
-void internal_hashmap_free(HashmapBase *h) {
+HashmapBase *internal_hashmap_free(HashmapBase *h) {
/* Free the hashmap, but nothing in it */
- if (!h)
- return;
+ if (h) {
+ internal_hashmap_clear(h);
+ hashmap_free_no_clear(h);
+ }
- internal_hashmap_clear(h);
- hashmap_free_no_clear(h);
+ return NULL;
}
-void internal_hashmap_free_free(HashmapBase *h) {
+HashmapBase *internal_hashmap_free_free(HashmapBase *h) {
/* Free the hashmap and all data objects in it, but not the
* keys */
- if (!h)
- return;
+ if (h) {
+ internal_hashmap_clear_free(h);
+ hashmap_free_no_clear(h);
+ }
- internal_hashmap_clear_free(h);
- hashmap_free_no_clear(h);
+ return NULL;
}
-void hashmap_free_free_free(Hashmap *h) {
+Hashmap *hashmap_free_free_free(Hashmap *h) {
/* Free the hashmap and all data and key objects in it */
- if (!h)
- return;
+ if (h) {
+ hashmap_clear_free_free(h);
+ hashmap_free_no_clear(HASHMAP_BASE(h));
+ }
- hashmap_clear_free_free(h);
- hashmap_free_no_clear(HASHMAP_BASE(h));
+ return NULL;
}
void internal_hashmap_clear(HashmapBase *h) {