]> code.delx.au - pulseaudio/commitdiff
hashmap: Add pa_hashmap_remove_and_free()
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Wed, 26 Mar 2014 15:39:47 +0000 (17:39 +0200)
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>
Thu, 17 Apr 2014 07:02:42 +0000 (10:02 +0300)
src/pulsecore/hashmap.c
src/pulsecore/hashmap.h

index acac1e06ab0de6dfa7d9a44b63e516309e80fa20..2cc03cbab91f26206462acaaf61a01d12a517e2d 100644 (file)
@@ -207,6 +207,19 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) {
     return data;
 }
 
+int pa_hashmap_remove_and_free(pa_hashmap *h, const void *key) {
+    void *data;
+
+    pa_assert(h);
+
+    data = pa_hashmap_remove(h, key);
+
+    if (data && h->value_free_func)
+        h->value_free_func(data);
+
+    return data ? 0 : -1;
+}
+
 void pa_hashmap_remove_all(pa_hashmap *h) {
     pa_assert(h);
 
index e42732ae9990a292e6a529ea153cd1216ce8cc56..8042f7bd9d87ea4747c1b48803662067233c8040 100644 (file)
@@ -52,6 +52,13 @@ void* pa_hashmap_get(pa_hashmap *h, const void *key);
 /* Returns the data of the entry while removing */
 void* pa_hashmap_remove(pa_hashmap *h, const void *key);
 
+/* Removes the entry and frees the entry data. Returns a negative value if the
+ * entry is not found. FIXME: This function shouldn't be needed.
+ * pa_hashmap_remove() should free the entry data, and the current semantics of
+ * pa_hashmap_remove() should be implemented by a function called
+ * pa_hashmap_steal(). */
+int pa_hashmap_remove_and_free(pa_hashmap *h, const void *key);
+
 /* Remove all entries but don't free the hashmap */
 void pa_hashmap_remove_all(pa_hashmap *h);