]> code.delx.au - pulseaudio/commitdiff
hashmap: Use pa_free_cb_t instead of pa_free2_cb_t
authorTanu Kaskinen <tanuk@iki.fi>
Tue, 12 Feb 2013 19:36:53 +0000 (21:36 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Fri, 15 Feb 2013 23:12:21 +0000 (01:12 +0200)
The previous patch removed module-gconf's dependency on the userdata
pointer of the free callback, and that was the only place where the
userdata pointer of pa_free2_cb_t was used, so now there's no need for
pa_free2_cb_t in pa_hashmap_free(). Using pa_free_cb_t instead allows
removing a significant amount of repetitive code.

41 files changed:
src/modules/alsa/alsa-mixer.c
src/modules/alsa/module-alsa-card.c
src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/module-bluetooth-discover.c
src/modules/bluetooth/module-bluetooth-proximity.c
src/modules/dbus/iface-card.c
src/modules/dbus/iface-core.c
src/modules/dbus/iface-device.c
src/modules/gconf/module-gconf.c
src/modules/macosx/module-bonjour-publish.c
src/modules/module-augment-properties.c
src/modules/module-card-restore.c
src/modules/module-console-kit.c
src/modules/module-device-manager.c
src/modules/module-filter-apply.c
src/modules/module-role-cork.c
src/modules/module-stream-restore.c
src/modules/module-suspend-on-idle.c
src/modules/module-systemd-login.c
src/modules/module-udev-detect.c
src/modules/module-zeroconf-discover.c
src/modules/module-zeroconf-publish.c
src/modules/raop/module-raop-discover.c
src/modules/rtp/headerlist.c
src/modules/rtp/module-rtp-recv.c
src/pulse/context.c
src/pulse/proplist.c
src/pulsecore/card.c
src/pulsecore/core.c
src/pulsecore/database-simple.c
src/pulsecore/device-port.c
src/pulsecore/hashmap.c
src/pulsecore/hashmap.h
src/pulsecore/memblock.c
src/pulsecore/modargs.c
src/pulsecore/mutex-win32.c
src/pulsecore/protocol-dbus.c
src/pulsecore/protocol-native.c
src/pulsecore/sink-input.c
src/pulsecore/sink.c
src/pulsecore/source.c

index 761aae10eba5bb28ee0491f45b1e6ad3a423df72..395ee2c8a428c50409c11d9b090785fbd48fb854 100644 (file)
@@ -530,7 +530,7 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
     pa_assert(ps);
 
     if (ps->paths)
-        pa_hashmap_free(ps->paths, NULL, NULL);
+        pa_hashmap_free(ps->paths, NULL);
 
     pa_xfree(ps);
 }
@@ -3300,50 +3300,20 @@ static void profile_free(pa_alsa_profile *p) {
 void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
     pa_assert(ps);
 
-    if (ps->input_paths) {
-        pa_alsa_path *p;
-
-        while ((p = pa_hashmap_steal_first(ps->input_paths)))
-            pa_alsa_path_free(p);
-
-        pa_hashmap_free(ps->input_paths, NULL, NULL);
-    }
-
-    if (ps->output_paths) {
-        pa_alsa_path *p;
-
-        while ((p = pa_hashmap_steal_first(ps->output_paths)))
-            pa_alsa_path_free(p);
-
-        pa_hashmap_free(ps->output_paths, NULL, NULL);
-    }
+    if (ps->input_paths)
+        pa_hashmap_free(ps->input_paths, (pa_free_cb_t) pa_alsa_path_free);
 
-    if (ps->profiles) {
-        pa_alsa_profile *p;
+    if (ps->output_paths)
+        pa_hashmap_free(ps->output_paths, (pa_free_cb_t) pa_alsa_path_free);
 
-        while ((p = pa_hashmap_steal_first(ps->profiles)))
-            profile_free(p);
-
-        pa_hashmap_free(ps->profiles, NULL, NULL);
-    }
+    if (ps->profiles)
+        pa_hashmap_free(ps->profiles, (pa_free_cb_t) profile_free);
 
-    if (ps->mappings) {
-        pa_alsa_mapping *m;
-
-        while ((m = pa_hashmap_steal_first(ps->mappings)))
-            mapping_free(m);
+    if (ps->mappings)
+        pa_hashmap_free(ps->mappings, (pa_free_cb_t) mapping_free);
 
-        pa_hashmap_free(ps->mappings, NULL, NULL);
-    }
-
-    if (ps->decibel_fixes) {
-        pa_alsa_decibel_fix *db_fix;
-
-        while ((db_fix = pa_hashmap_steal_first(ps->decibel_fixes)))
-            decibel_fix_free(db_fix);
-
-        pa_hashmap_free(ps->decibel_fixes, NULL, NULL);
-    }
+    if (ps->decibel_fixes)
+        pa_hashmap_free(ps->decibel_fixes, (pa_free_cb_t) decibel_fix_free);
 
     pa_xfree(ps);
 }
@@ -4415,8 +4385,8 @@ void pa_alsa_profile_set_probe(
 
     paths_drop_unsupported(ps->input_paths);
     paths_drop_unsupported(ps->output_paths);
-    pa_hashmap_free(broken_inputs, NULL, NULL);
-    pa_hashmap_free(broken_outputs, NULL, NULL);
+    pa_hashmap_free(broken_inputs, NULL);
+    pa_hashmap_free(broken_outputs, NULL);
 
     ps->probed = TRUE;
 }
index 366f4ba463f70c46f1d7bbc5179bd51cf7f509e1..3c995f8f2529e8e726e53810818a6ccb721fa3e3 100644 (file)
@@ -744,7 +744,7 @@ void pa__done(pa_module*m) {
     if (u->mixer_handle)
         snd_mixer_close(u->mixer_handle);
     if (u->jacks)
-        pa_hashmap_free(u->jacks, NULL, NULL);
+        pa_hashmap_free(u->jacks, NULL);
 
     if (u->card && u->card->sinks) {
         pa_sink *s;
index 8fa1631a4c15c670526331be806e30b856ec10d8..7a9f7e9fefb75013b4d7664ac73a93e9b989d9fc 100644 (file)
@@ -1736,12 +1736,12 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
 
     if (y->devices) {
         remove_all_devices(y);
-        pa_hashmap_free(y->devices, NULL, NULL);
+        pa_hashmap_free(y->devices, NULL);
     }
 
     if (y->transports) {
         pa_assert(pa_hashmap_isempty(y->transports));
-        pa_hashmap_free(y->transports, NULL, NULL);
+        pa_hashmap_free(y->transports, NULL);
     }
 
     if (y->connection) {
index eb59bebe46490209123e205b4491a077a83365bd..cbd56ccc425b95c6c760e200d29c542228dce29d 100644 (file)
@@ -184,7 +184,7 @@ void pa__done(pa_module* m) {
             pa_xfree(mi);
         }
 
-        pa_hashmap_free(u->hashmap, NULL, NULL);
+        pa_hashmap_free(u->hashmap, NULL);
     }
 
     if (u->modargs)
index 7f90951ae7aaf9efad28a48b269f348141aff6e9..b55dfdb13209d32d485bf33b18848ba8919c5e83 100644 (file)
@@ -466,14 +466,8 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->bondings) {
-        struct bonding *b;
-
-        while ((b = pa_hashmap_steal_first(u->bondings)))
-            bonding_free(b);
-
-        pa_hashmap_free(u->bondings, NULL, NULL);
-    }
+    if (u->bondings)
+        pa_hashmap_free(u->bondings, (pa_free_cb_t) bonding_free);
 
     if (u->dbus_connection) {
         update_matches(u, false);
index 1313e71bf20ef92cb6706208336abf8a18783e62..945f5bb76bed54b927b96a0619825c4bd852def2 100644 (file)
@@ -543,14 +543,6 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
     return c;
 }
 
-static void profile_free_cb(void *p, void *userdata) {
-    pa_dbusiface_card_profile *profile = p;
-
-    pa_assert(profile);
-
-    pa_dbusiface_card_profile_free(profile);
-}
-
 void pa_dbusiface_card_free(pa_dbusiface_card *c) {
     pa_assert(c);
 
@@ -558,7 +550,7 @@ void pa_dbusiface_card_free(pa_dbusiface_card *c) {
 
     pa_hook_slot_free(c->card_profile_added_slot);
 
-    pa_hashmap_free(c->profiles, profile_free_cb, NULL);
+    pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_dbusiface_card_profile_free);
     pa_proplist_free(c->proplist);
     pa_dbus_protocol_unref(c->dbus_protocol);
     pa_subscription_free(c->subscription);
index 97a46a58da635943baca9f4137700ba06b6ff6db..a9716bc333a38efb08b838f59ef439b0eac1439b 100644 (file)
@@ -2089,54 +2089,6 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
     return c;
 }
 
-static void free_card_cb(void *p, void *userdata) {
-    pa_dbusiface_card *c = p;
-
-    pa_assert(c);
-
-    pa_dbusiface_card_free(c);
-}
-
-static void free_device_cb(void *p, void *userdata) {
-    pa_dbusiface_device *d = p;
-
-    pa_assert(d);
-
-    pa_dbusiface_device_free(d);
-}
-
-static void free_stream_cb(void *p, void *userdata) {
-    pa_dbusiface_stream *s = p;
-
-    pa_assert(s);
-
-    pa_dbusiface_stream_free(s);
-}
-
-static void free_sample_cb(void *p, void *userdata) {
-    pa_dbusiface_sample *s = p;
-
-    pa_assert(s);
-
-    pa_dbusiface_sample_free(s);
-}
-
-static void free_module_cb(void *p, void *userdata) {
-    pa_dbusiface_module *m = p;
-
-    pa_assert(m);
-
-    pa_dbusiface_module_free(m);
-}
-
-static void free_client_cb(void *p, void *userdata) {
-    pa_dbusiface_client *c = p;
-
-    pa_assert(c);
-
-    pa_dbusiface_client_free(c);
-}
-
 void pa_dbusiface_core_free(pa_dbusiface_core *c) {
     pa_assert(c);
 
@@ -2145,16 +2097,16 @@ void pa_dbusiface_core_free(pa_dbusiface_core *c) {
     /* Note that the order of freeing is important below.
      * Do not change it for the sake of tidiness without checking! */
     pa_subscription_free(c->subscription);
-    pa_hashmap_free(c->cards, free_card_cb, NULL);
-    pa_hashmap_free(c->sinks_by_path, NULL, NULL);
-    pa_hashmap_free(c->sinks_by_index, free_device_cb, NULL);
-    pa_hashmap_free(c->sources_by_path, NULL, NULL);
-    pa_hashmap_free(c->sources_by_index, free_device_cb, NULL);
-    pa_hashmap_free(c->playback_streams, free_stream_cb, NULL);
-    pa_hashmap_free(c->record_streams, free_stream_cb, NULL);
-    pa_hashmap_free(c->samples, free_sample_cb, NULL);
-    pa_hashmap_free(c->modules, free_module_cb, NULL);
-    pa_hashmap_free(c->clients, free_client_cb, NULL);
+    pa_hashmap_free(c->cards, (pa_free_cb_t) pa_dbusiface_card_free);
+    pa_hashmap_free(c->sinks_by_path, NULL);
+    pa_hashmap_free(c->sinks_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
+    pa_hashmap_free(c->sources_by_path, NULL);
+    pa_hashmap_free(c->sources_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
+    pa_hashmap_free(c->playback_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
+    pa_hashmap_free(c->record_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
+    pa_hashmap_free(c->samples, (pa_free_cb_t) pa_dbusiface_sample_free);
+    pa_hashmap_free(c->modules, (pa_free_cb_t) pa_dbusiface_module_free);
+    pa_hashmap_free(c->clients, (pa_free_cb_t) pa_dbusiface_client_free);
     pa_hook_slot_free(c->sink_put_slot);
     pa_hook_slot_free(c->sink_unlink_slot);
     pa_hook_slot_free(c->source_put_slot);
index 151938dfbc576c02fda015f4f645e50ea91d4cdd..888d407eb85de4824afe2a10aa5407aad7d1c1ad 100644 (file)
@@ -1266,14 +1266,6 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
     return d;
 }
 
-static void port_free_cb(void *p, void *userdata) {
-    pa_dbusiface_device_port *port = p;
-
-    pa_assert(port);
-
-    pa_dbusiface_device_port_free(port);
-}
-
 void pa_dbusiface_device_free(pa_dbusiface_device *d) {
     pa_assert(d);
 
@@ -1287,7 +1279,7 @@ void pa_dbusiface_device_free(pa_dbusiface_device *d) {
         pa_assert_se(pa_dbus_protocol_remove_interface(d->dbus_protocol, d->path, source_interface_info.name) >= 0);
         pa_source_unref(d->source);
     }
-    pa_hashmap_free(d->ports, port_free_cb, NULL);
+    pa_hashmap_free(d->ports, (pa_free_cb_t) pa_dbusiface_device_port_free);
     pa_proplist_free(d->proplist);
     pa_dbus_protocol_unref(d->dbus_protocol);
     pa_subscription_free(d->subscription);
index 5304116cd2dc14a608adad13108694e1fffba25d..c60d0f05d1d873d38d63f2949dd23e6df213aba4 100644 (file)
@@ -200,7 +200,7 @@ static void load_module(
     m->items[i].index = mod->index;
 }
 
-static void module_info_free(void *p, void *userdata) {
+static void module_info_free(void *p) {
     struct module_info *m = p;
 
     pa_assert(m);
@@ -291,7 +291,7 @@ static int handle_event(struct userdata *u) {
 
                 if ((m = pa_hashmap_get(u->module_infos, name))) {
                     pa_hashmap_remove(u->module_infos, name);
-                    module_info_free(m, u);
+                    module_info_free(m);
                 }
 
                 pa_xfree(name);
@@ -401,7 +401,7 @@ void pa__done(pa_module*m) {
         pa_close(u->fd);
 
     if (u->module_infos)
-        pa_hashmap_free(u->module_infos, module_info_free, NULL);
+        pa_hashmap_free(u->module_infos, (pa_free_cb_t) module_info_free);
 
     pa_xfree(u);
 }
index 667b6b738ad28b9a7ffba254f8015f7eabcb537a..d29d5185cec1bb3434ecb4878f115631b95a2920 100644 (file)
@@ -490,7 +490,7 @@ void pa__done(pa_module*m) {
     unpublish_all_services(u);
 
     if (u->services)
-        pa_hashmap_free(u->services, NULL, NULL);
+        pa_hashmap_free(u->services, NULL);
 
     if (u->sink_new_slot)
         pa_hook_slot_free(u->sink_new_slot);
index 6bba2b301275583160358532a64146c973c0eed5..ee3b54c7897a434ba46e46e866204d6641c15199 100644 (file)
@@ -347,14 +347,8 @@ void pa__done(pa_module *m) {
     if (u->client_proplist_changed_slot)
         pa_hook_slot_free(u->client_proplist_changed_slot);
 
-    if (u->cache) {
-        struct rule *r;
-
-        while ((r = pa_hashmap_steal_first(u->cache)))
-            rule_free(r);
-
-        pa_hashmap_free(u->cache, NULL, NULL);
-    }
+    if (u->cache)
+        pa_hashmap_free(u->cache, (pa_free_cb_t) rule_free);
 
     pa_xfree(u);
 }
index 51923fd1a0a6cecf6da50562e0406cea81aa7bd8..3b061b6d076f05cffd33a4ba6751bf01dce65b00 100644 (file)
@@ -136,7 +136,7 @@ static void port_info_update(struct port_info *p_info, pa_device_port *port) {
     p_info->offset = port->latency_offset;
 }
 
-static void port_info_free(struct port_info *p_info, void *userdata) {
+static void port_info_free(struct port_info *p_info) {
     pa_assert(p_info);
 
     pa_xfree(p_info->name);
@@ -147,7 +147,7 @@ static void entry_free(struct entry* e) {
     pa_assert(e);
 
     pa_xfree(e->profile);
-    pa_hashmap_free(e->ports, (pa_free2_cb_t) port_info_free, NULL);
+    pa_hashmap_free(e->ports, (pa_free_cb_t) port_info_free);
 
     pa_xfree(e);
 }
index 29f7e663413b649acd0505fac727310f498760d5..c9c2f4536f77e4ace79bfe123a503531959f9ff8 100644 (file)
@@ -347,19 +347,14 @@ fail:
 
 void pa__done(pa_module *m) {
     struct userdata *u;
-    struct session *session;
 
     pa_assert(m);
 
     if (!(u = m->userdata))
         return;
 
-    if (u->sessions) {
-        while ((session = pa_hashmap_steal_first(u->sessions)))
-            free_session(session);
-
-        pa_hashmap_free(u->sessions, NULL, NULL);
-    }
+    if (u->sessions)
+        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
 
     if (u->connection) {
         pa_dbus_remove_matches(
index 12eddec8c3413f3139d792f7c83413ffd226e5e6..1207824aad16247ac8a67478b3ff0b773569e4db 100644 (file)
@@ -1302,7 +1302,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL, NULL);
+                pa_hashmap_free(h, NULL);
                 pa_log_error("Protocol error on reorder");
                 goto fail;
             }
@@ -1314,7 +1314,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL, NULL);
+                pa_hashmap_free(h, NULL);
                 pa_log_error("Client specified an unknown device in it's reorder list.");
                 goto fail;
             }
@@ -1329,7 +1329,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL, NULL);
+                pa_hashmap_free(h, NULL);
                 pa_log_error("Attempted to reorder mixed devices (sinks and sources)");
                 goto fail;
             }
@@ -1402,7 +1402,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
         while ((device = pa_hashmap_steal_first(h))) {
             devices[idx++] = device;
         }
-        pa_hashmap_free(h, NULL, NULL);
+        pa_hashmap_free(h, NULL);
 
         /* Simple bubble sort */
         for (i = 0; i < n_devices; ++i) {
index cd0cd8d4f2ef5cc018d192035716e7bc4bb2a24b..6826a0a11a2b7626e090181dc3b1399859b8c25a 100644 (file)
@@ -743,7 +743,7 @@ void pa__done(pa_module *m) {
             filter_free(f);
         }
 
-        pa_hashmap_free(u->filters, NULL, NULL);
+        pa_hashmap_free(u->filters, NULL);
     }
 
     pa_xfree(u);
index 8f8b58dcd43c8c29d681adec69011d4e29881263..77bac1e4b241ff97b172dc1dddd2775946f63372 100644 (file)
@@ -311,7 +311,7 @@ void pa__done(pa_module *m) {
         pa_hook_slot_free(u->sink_input_move_finish_slot);
 
     if (u->cork_state)
-        pa_hashmap_free(u->cork_state, NULL, NULL);
+        pa_hashmap_free(u->cork_state, NULL);
 
     pa_xfree(u);
 
index 1166a63583b950ad84476ca3152e790431d30355..64bb241f2ef2faeb7b382df2d3ff9813f1690f4b 100644 (file)
@@ -2491,16 +2491,6 @@ fail:
     return -1;
 }
 
-#ifdef HAVE_DBUS
-static void free_dbus_entry_cb(void *p, void *userdata) {
-    struct dbus_entry *de = p;
-
-    pa_assert(de);
-
-    dbus_entry_free(de);
-}
-#endif
-
 void pa__done(pa_module*m) {
     struct userdata* u;
 
@@ -2516,7 +2506,7 @@ void pa__done(pa_module*m) {
         pa_assert_se(pa_dbus_protocol_unregister_extension(u->dbus_protocol, INTERFACE_STREAM_RESTORE) >= 0);
         pa_assert_se(pa_dbus_protocol_remove_interface(u->dbus_protocol, OBJECT_PATH, stream_restore_interface_info.name) >= 0);
 
-        pa_hashmap_free(u->dbus_entries, free_dbus_entry_cb, NULL);
+        pa_hashmap_free(u->dbus_entries, (pa_free_cb_t) dbus_entry_free);
 
         pa_dbus_protocol_unref(u->dbus_protocol);
     }
index f27dafd3977625c5f5aeefc72653e8285b033e8a..02a6b913a860897b7b9a56f8ccfafadc58cff468 100644 (file)
@@ -474,7 +474,6 @@ fail:
 
 void pa__done(pa_module*m) {
     struct userdata *u;
-    struct device_info *d;
 
     pa_assert(m);
 
@@ -519,10 +518,7 @@ void pa__done(pa_module*m) {
     if (u->source_output_state_changed_slot)
         pa_hook_slot_free(u->source_output_state_changed_slot);
 
-    while ((d = pa_hashmap_steal_first(u->device_infos)))
-        device_info_free(d);
-
-    pa_hashmap_free(u->device_infos, NULL, NULL);
+    pa_hashmap_free(u->device_infos, (pa_free_cb_t) device_info_free);
 
     pa_xfree(u);
 }
index 024c1eb1153371505809c03679acd50a17f912f0..2f24711005eea06f042e588a288ab7c345e9e6e8 100644 (file)
@@ -222,15 +222,8 @@ void pa__done(pa_module *m) {
         return;
 
     if (u->sessions) {
-        while ((session = pa_hashmap_steal_first(u->sessions)))
-            free_session(session);
-
-        pa_hashmap_free(u->sessions, NULL, NULL);
-
-        while ((session = pa_hashmap_steal_first(u->previous_sessions)))
-            free_session(session);
-
-        pa_hashmap_free(u->previous_sessions, NULL, NULL);
+        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
+        pa_hashmap_free(u->previous_sessions, (pa_free_cb_t) free_session);
     }
 
     if (u->io)
index 185c179aa39f2e38a9456f1f775dadecd6f1d87c..76cab90ee31d0bcec8c5f9e005ead0a98b99d96b 100644 (file)
@@ -817,14 +817,8 @@ void pa__done(pa_module *m) {
     if (u->inotify_fd >= 0)
         pa_close(u->inotify_fd);
 
-    if (u->devices) {
-        struct device *d;
-
-        while ((d = pa_hashmap_steal_first(u->devices)))
-            device_free(d);
-
-        pa_hashmap_free(u->devices, NULL, NULL);
-    }
+    if (u->devices)
+        pa_hashmap_free(u->devices, (pa_free_cb_t) device_free);
 
     pa_xfree(u);
 }
index b17f6e5c04a541325d0ec88956e8a6bfcf480b1d..4887510950c148429bfabb09ddcd15f9a1921ced 100644 (file)
@@ -426,7 +426,7 @@ void pa__done(pa_module*m) {
             tunnel_free(t);
         }
 
-        pa_hashmap_free(u->tunnels, NULL, NULL);
+        pa_hashmap_free(u->tunnels, NULL);
     }
 
     pa_xfree(u);
index 0c20cf6c58f366ec3825f9ed6084d91bafd37f7d..c21ff3e4af91d95275ba0c32df00e6d273b933fa 100644 (file)
@@ -326,8 +326,10 @@ static int publish_service(struct service *s) {
 finish:
 
     /* Remove this service */
-    if (r < 0)
+    if (r < 0) {
+        pa_hashmap_remove(s->userdata->services, s->device);
         service_free(s);
+    }
 
     avahi_string_list_free(txt);
 
@@ -374,8 +376,6 @@ static struct service *get_service(struct userdata *u, pa_object *device) {
 static void service_free(struct service *s) {
     pa_assert(s);
 
-    pa_hashmap_remove(s->userdata->services, s->device);
-
     if (s->entry_group) {
         pa_log_debug("Removing entry group for %s.", s->service_name);
         avahi_entry_group_free(s->entry_group);
@@ -413,7 +413,7 @@ static pa_hook_result_t device_unlink_cb(pa_core *c, pa_object *o, struct userda
     pa_assert(c);
     pa_object_assert_ref(o);
 
-    if ((s = pa_hashmap_get(u->services, o)))
+    if ((s = pa_hashmap_remove(u->services, o)))
         service_free(s);
 
     return PA_HOOK_OK;
@@ -661,14 +661,8 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->services) {
-        struct service *s;
-
-        while ((s = pa_hashmap_first(u->services)))
-            service_free(s);
-
-        pa_hashmap_free(u->services, NULL, NULL);
-    }
+    if (u->services)
+        pa_hashmap_free(u->services, (pa_free_cb_t) service_free);
 
     if (u->sink_new_slot)
         pa_hook_slot_free(u->sink_new_slot);
index 7499f634387cea61b4780ee40b1dd24fa22316dc..3db2c0e4254168f851504b7d5d4983a9b660b6d0 100644 (file)
@@ -381,7 +381,7 @@ void pa__done(pa_module*m) {
             tunnel_free(t);
         }
 
-        pa_hashmap_free(u->tunnels, NULL, NULL);
+        pa_hashmap_free(u->tunnels, NULL);
     }
 
     pa_xfree(u);
index 0fef835bbccefe9f8f91b28558b42bbbc5faabf9..30075185522467d3e2b8966aeb561f6553514463 100644 (file)
@@ -56,12 +56,7 @@ pa_headerlist* pa_headerlist_new(void) {
 }
 
 void pa_headerlist_free(pa_headerlist* p) {
-    struct header *hdr;
-
-    while ((hdr = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
-        header_free(hdr);
-
-    pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
+    pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) header_free);
 }
 
 int pa_headerlist_puts(pa_headerlist *p, const char *key, const char *value) {
index 3e9250c0938ef35acf2bc9b4de0155eb3869bf88..45d03f5d0069bf16aa24c630cae1d03f8045f4fe 100644 (file)
@@ -186,6 +186,7 @@ static void sink_input_kill(pa_sink_input* i) {
     pa_sink_input_assert_ref(i);
     pa_assert_se(s = i->userdata);
 
+    pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
     session_free(s);
 }
 
@@ -606,7 +607,6 @@ static void session_free(struct session *s) {
     PA_LLIST_REMOVE(struct session, s->userdata->sessions, s);
     pa_assert(s->userdata->n_sessions >= 1);
     s->userdata->n_sessions--;
-    pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
 
     pa_memblockq_free(s->memblockq);
     pa_sdp_info_destroy(&s->sdp_info);
@@ -635,7 +635,7 @@ static void sap_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event
 
     if (goodbye) {
 
-        if ((s = pa_hashmap_get(u->by_origin, info.origin)))
+        if ((s = pa_hashmap_remove(u->by_origin, info.origin)))
             session_free(s);
 
         pa_sdp_info_destroy(&info);
@@ -674,8 +674,10 @@ static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const str
 
         k = pa_atomic_load(&s->timestamp);
 
-        if (k + DEATH_TIMEOUT < now.tv_sec)
+        if (k + DEATH_TIMEOUT < now.tv_sec) {
+            pa_hashmap_remove(u->by_origin, s->sdp_info.origin);
             session_free(s);
+        }
     }
 
     /* Restart timer */
@@ -753,7 +755,6 @@ fail:
 
 void pa__done(pa_module*m) {
     struct userdata *u;
-    struct session *s;
 
     pa_assert(m);
 
@@ -768,12 +769,8 @@ void pa__done(pa_module*m) {
 
     pa_sap_context_destroy(&u->sap_context);
 
-    if (u->by_origin) {
-        while ((s = pa_hashmap_first(u->by_origin)))
-            session_free(s);
-
-        pa_hashmap_free(u->by_origin, NULL, NULL);
-    }
+    if (u->by_origin)
+        pa_hashmap_free(u->by_origin, (pa_free_cb_t) session_free);
 
     pa_xfree(u->sink_name);
     pa_xfree(u);
index 4618635083f79e705fa56c2be067b98bd2740a20..717641254953a57ab528c1a6e73afdcf6b5b2df9 100644 (file)
@@ -241,9 +241,9 @@ static void context_free(pa_context *c) {
 #endif
 
     if (c->record_streams)
-        pa_hashmap_free(c->record_streams, NULL, NULL);
+        pa_hashmap_free(c->record_streams, NULL);
     if (c->playback_streams)
-        pa_hashmap_free(c->playback_streams, NULL, NULL);
+        pa_hashmap_free(c->playback_streams, NULL);
 
     if (c->mempool)
         pa_mempool_free(c->mempool);
index 2c197bccc0cf749887574c2c0632f5c0729c3241..33b150c4028b9285cdf91befcbc7593ae3cbfdbd 100644 (file)
@@ -70,8 +70,7 @@ pa_proplist* pa_proplist_new(void) {
 void pa_proplist_free(pa_proplist* p) {
     pa_assert(p);
 
-    pa_proplist_clear(p);
-    pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
+    pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
 }
 
 /** Will accept only valid UTF-8 */
index afabc95311b3fe61fdf70c2d8a13bf69cba523b9..560e36e10021087accd04a4772ed05633d170ff3 100644 (file)
@@ -57,7 +57,6 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
 
 void pa_card_profile_free(pa_card_profile *c) {
     pa_assert(c);
-    pa_assert(!c->card); /* Card profiles shouldn't be freed before removing them from the card. */
 
     pa_xfree(c->name);
     pa_xfree(c->description);
@@ -126,14 +125,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
 
     pa_proplist_free(data->proplist);
 
-    if (data->profiles) {
-        pa_card_profile *c;
-
-        while ((c = pa_hashmap_steal_first(data->profiles)))
-            pa_card_profile_free(c);
-
-        pa_hashmap_free(data->profiles, NULL, NULL);
-    }
+    if (data->profiles)
+        pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
 
     if (data->ports)
         pa_device_port_hashmap_free(data->ports);
@@ -246,16 +239,8 @@ void pa_card_free(pa_card *c) {
 
     pa_device_port_hashmap_free(c->ports);
 
-    if (c->profiles) {
-        pa_card_profile *p;
-
-        while ((p = pa_hashmap_steal_first(c->profiles))) {
-            p->card = NULL;
-            pa_card_profile_free(p);
-        }
-
-        pa_hashmap_free(c->profiles, NULL, NULL);
-    }
+    if (c->profiles)
+        pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
 
     pa_proplist_free(c->proplist);
     pa_xfree(c->driver);
index e4f91403518a3221343f3a0aeec6d6e10dcf7206..37f3fae89346522c216bf17a5996843e049f77fc 100644 (file)
@@ -194,10 +194,10 @@ static void core_free(pa_object *o) {
     pa_idxset_free(c->sink_inputs, NULL, NULL);
 
     pa_assert(pa_hashmap_isempty(c->namereg));
-    pa_hashmap_free(c->namereg, NULL, NULL);
+    pa_hashmap_free(c->namereg, NULL);
 
     pa_assert(pa_hashmap_isempty(c->shared));
-    pa_hashmap_free(c->shared, NULL, NULL);
+    pa_hashmap_free(c->shared, NULL);
 
     pa_subscription_free_all(c);
 
index db68158313c30df3824682b48c26b24cff6dba17..5dd3ac9b63190dcc7a0d6eb177880179a5dacc14 100644 (file)
@@ -264,10 +264,9 @@ void pa_database_close(pa_database *database) {
     pa_assert(db);
 
     pa_database_sync(database);
-    pa_database_clear(database);
     pa_xfree(db->filename);
     pa_xfree(db->tmp_filename);
-    pa_hashmap_free(db->map, NULL, NULL);
+    pa_hashmap_free(db->map, (pa_free_cb_t) free_entry);
     pa_xfree(db);
 }
 
index 6d787aca2d28b1c55d6d7588880cc10020e3d807..5c7a5bb54d8c3345d4a84a1a0af09216ff3abf3f 100644 (file)
@@ -56,8 +56,10 @@ static void device_port_free(pa_object *o) {
 
     if (p->proplist)
         pa_proplist_free(p->proplist);
+
     if (p->profiles)
-        pa_hashmap_free(p->profiles, NULL, NULL);
+        pa_hashmap_free(p->profiles, NULL);
+
     pa_xfree(p->name);
     pa_xfree(p->description);
     pa_xfree(p);
@@ -88,14 +90,9 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
 }
 
 void pa_device_port_hashmap_free(pa_hashmap *h) {
-    pa_device_port *p;
-
     pa_assert(h);
 
-    while ((p = pa_hashmap_steal_first(h)))
-        pa_device_port_unref(p);
-
-    pa_hashmap_free(h, NULL, NULL);
+    pa_hashmap_free(h, (pa_free_cb_t) pa_device_port_unref);
 }
 
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
index e368512b24bf1fe823b0e780fbb3318a14e6a2db..cfd08b7a16dd4d4dc0b3a98219c1be838eab378b 100644 (file)
@@ -101,7 +101,7 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
     h->n_entries--;
 }
 
-void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) {
+void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
     pa_assert(h);
 
     while (h->iterate_list_head) {
@@ -110,7 +110,7 @@ void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) {
         remove_entry(h, h->iterate_list_head);
 
         if (free_cb)
-            free_cb(data, userdata);
+            free_cb(data);
     }
 
     pa_xfree(h);
index ac2092a60f33c6e740d1bbf7d7bfd4dc7df77df4..8d892b8fff2e180f41d560cf4ef80f479df16d46 100644 (file)
@@ -22,6 +22,8 @@
   USA.
 ***/
 
+#include <pulse/def.h>
+
 #include <pulsecore/idxset.h>
 
 /* Simple Implementation of a hash table. Memory management is the
@@ -35,7 +37,7 @@ typedef struct pa_hashmap pa_hashmap;
 pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
 
 /* Free the hash table. Calls the specified function for every value in the table. The function may be NULL */
-void pa_hashmap_free(pa_hashmap*, pa_free2_cb_t free_cb, void *userdata);
+void pa_hashmap_free(pa_hashmap*, pa_free_cb_t free_cb);
 
 /* Add an entry to the hashmap. Returns non-zero when the entry already exists */
 int pa_hashmap_put(pa_hashmap *h, const void *key, void *value);
index ea7b274fb72c6433cd7128a67237d510a25a80e5..5b77df3b45fce048193f619a1e78486d33c5140f 100644 (file)
@@ -964,8 +964,8 @@ void pa_memimport_free(pa_memimport *i) {
 
     pa_mutex_unlock(i->pool->mutex);
 
-    pa_hashmap_free(i->blocks, NULL, NULL);
-    pa_hashmap_free(i->segments, NULL, NULL);
+    pa_hashmap_free(i->blocks, NULL);
+    pa_hashmap_free(i->segments, NULL);
 
     pa_mutex_free(i->mutex);
 
index 0abc2436b30746256200cd4eeedb883f3053831a..d48a2c8e147cd7aa90cb96d2f7e5cb21ba39d098 100644 (file)
@@ -247,7 +247,7 @@ fail:
     return NULL;
 }
 
-static void free_func(void *p, void*userdata) {
+static void free_func(void *p) {
     struct entry *e = p;
     pa_assert(e);
 
@@ -259,8 +259,8 @@ static void free_func(void *p, void*userdata) {
 void pa_modargs_free(pa_modargs*ma) {
     pa_assert(ma);
 
-    pa_hashmap_free(ma->raw, free_func, NULL);
-    pa_hashmap_free(ma->unescaped, free_func, NULL);
+    pa_hashmap_free(ma->raw, free_func);
+    pa_hashmap_free(ma->unescaped, free_func);
     pa_xfree(ma);
 }
 
index f4652a907979dc5d69f961ca1e9da39dc2bde730..e70f230ac94649158adc85ab47f17561b9f0f337 100644 (file)
@@ -80,7 +80,7 @@ pa_cond *pa_cond_new(void) {
 void pa_cond_free(pa_cond *c) {
     assert(c);
 
-    pa_hashmap_free(c->wait_events, NULL, NULL);
+    pa_hashmap_free(c->wait_events, NULL);
     pa_xfree(c);
 }
 
index c82ea4a73804320a6c6ae0c22dc07e04c3017d52..dab467879cf73a2d1807830caad1c7bde712441a 100644 (file)
@@ -169,8 +169,8 @@ void pa_dbus_protocol_unref(pa_dbus_protocol *p) {
     pa_assert(pa_hashmap_isempty(p->connections));
     pa_assert(pa_idxset_isempty(p->extensions));
 
-    pa_hashmap_free(p->objects, NULL, NULL);
-    pa_hashmap_free(p->connections, NULL, NULL);
+    pa_hashmap_free(p->objects, NULL);
+    pa_hashmap_free(p->connections, NULL);
     pa_idxset_free(p->extensions, NULL, NULL);
 
     for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i)
@@ -789,8 +789,7 @@ static void unregister_object(pa_dbus_protocol *p, struct object_entry *obj_entr
         pa_assert_se(dbus_connection_unregister_object_path(conn_entry->connection, obj_entry->path));
 }
 
-static void method_handler_free_cb(void *p, void *userdata) {
-    pa_dbus_method_handler *h = p;
+static void method_handler_free(pa_dbus_method_handler *h) {
     unsigned i;
 
     pa_assert(h);
@@ -807,15 +806,7 @@ static void method_handler_free_cb(void *p, void *userdata) {
     pa_xfree(h);
 }
 
-static void method_signature_free_cb(void *p, void *userdata) {
-    pa_assert(p);
-
-    pa_xfree(p);
-}
-
-static void property_handler_free_cb(void *p, void *userdata) {
-    pa_dbus_property_handler *h = p;
-
+static void property_handler_free(pa_dbus_property_handler *h) {
     pa_assert(h);
 
     pa_xfree((char *) h->property_name);
@@ -844,9 +835,9 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
     pa_log_debug("Interface %s removed from object %s", iface_entry->name, obj_entry->path);
 
     pa_xfree(iface_entry->name);
-    pa_hashmap_free(iface_entry->method_signatures, method_signature_free_cb, NULL);
-    pa_hashmap_free(iface_entry->method_handlers, method_handler_free_cb, NULL);
-    pa_hashmap_free(iface_entry->property_handlers, property_handler_free_cb, NULL);
+    pa_hashmap_free(iface_entry->method_signatures, pa_xfree);
+    pa_hashmap_free(iface_entry->method_handlers, (pa_free_cb_t) method_handler_free);
+    pa_hashmap_free(iface_entry->property_handlers, (pa_free_cb_t) property_handler_free);
 
     for (i = 0; i < iface_entry->n_signals; ++i) {
         unsigned j;
@@ -870,7 +861,7 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
 
         pa_hashmap_remove(p->objects, path);
         pa_xfree(obj_entry->path);
-        pa_hashmap_free(obj_entry->interfaces, NULL, NULL);
+        pa_hashmap_free(obj_entry->interfaces, NULL);
         pa_xfree(obj_entry->introspection);
         pa_xfree(obj_entry);
     }
@@ -952,7 +943,6 @@ static void signal_paths_entry_free(struct signal_paths_entry *e) {
 
 int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) {
     struct connection_entry *conn_entry = NULL;
-    struct signal_paths_entry *signal_paths_entry = NULL;
     char *object_path = NULL;
 
     pa_assert(p);
@@ -970,10 +960,7 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *
 
     pa_idxset_free(conn_entry->all_signals_objects, NULL, NULL);
 
-    while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
-        signal_paths_entry_free(signal_paths_entry);
-
-    pa_hashmap_free(conn_entry->listening_signals, NULL, NULL);
+    pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
     pa_xfree(conn_entry);
 
     return 0;
index 88808bf84272b4b5e362ec0e18f25d6e7dcfa8bd..6a9379e919ec242a97943375427454c5dc20b823 100644 (file)
@@ -5100,7 +5100,7 @@ void pa_native_protocol_unref(pa_native_protocol *p) {
     for (h = 0; h < PA_NATIVE_HOOK_MAX; h++)
         pa_hook_done(&p->hooks[h]);
 
-    pa_hashmap_free(p->extensions, NULL, NULL);
+    pa_hashmap_free(p->extensions, NULL);
 
     pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0);
 
index a6ddb1522f3f18c1f043d3c44a47efb57d2dd0d6..165faa7c11655b63302d66656d5a834b1eabaaf9 100644 (file)
@@ -74,10 +74,6 @@ static void volume_factor_entry_free(struct volume_factor_entry *volume_entry) {
     pa_xfree(volume_entry);
 }
 
-static void volume_factor_entry_free2(struct volume_factor_entry *volume_entry, void *userdarta) {
-    volume_factor_entry_free(volume_entry);
-}
-
 static void volume_factor_from_hashmap(pa_cvolume *v, pa_hashmap *items, uint8_t channels) {
     struct volume_factor_entry *entry;
     void *state = NULL;
@@ -245,10 +241,10 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
         pa_format_info_free(data->format);
 
     if (data->volume_factor_items)
-        pa_hashmap_free(data->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
+        pa_hashmap_free(data->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
 
     if (data->volume_factor_sink_items)
-        pa_hashmap_free(data->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
+        pa_hashmap_free(data->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
 
     pa_proplist_free(data->proplist);
 }
@@ -745,12 +741,13 @@ static void sink_input_free(pa_object *o) {
         pa_idxset_free(i->direct_outputs, NULL, NULL);
 
     if (i->thread_info.direct_outputs)
-        pa_hashmap_free(i->thread_info.direct_outputs, NULL, NULL);
+        pa_hashmap_free(i->thread_info.direct_outputs, NULL);
 
     if (i->volume_factor_items)
-        pa_hashmap_free(i->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
+        pa_hashmap_free(i->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
+
     if (i->volume_factor_sink_items)
-        pa_hashmap_free(i->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
+        pa_hashmap_free(i->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
 
     pa_xfree(i->driver);
     pa_xfree(i);
index 175cfe50f879ac25caf2fad723020834290f6fb8..171072e17335803ad20c297d0e06b8d098a2d163 100644 (file)
@@ -715,7 +715,6 @@ void pa_sink_unlink(pa_sink* s) {
 /* Called from main context */
 static void sink_free(pa_object *o) {
     pa_sink *s = PA_SINK(o);
-    pa_sink_input *i;
 
     pa_assert(s);
     pa_assert_ctl_context();
@@ -732,11 +731,7 @@ static void sink_free(pa_object *o) {
     }
 
     pa_idxset_free(s->inputs, NULL, NULL);
-
-    while ((i = pa_hashmap_steal_first(s->thread_info.inputs)))
-        pa_sink_input_unref(i);
-
-    pa_hashmap_free(s->thread_info.inputs, NULL, NULL);
+    pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);
index f33611904befe8ed21212171f7feecbef56dad32..5c1213703d1f6781c1b80685c5707372c3f851a5 100644 (file)
@@ -648,7 +648,6 @@ void pa_source_unlink(pa_source *s) {
 
 /* Called from main context */
 static void source_free(pa_object *o) {
-    pa_source_output *so;
     pa_source *s = PA_SOURCE(o);
 
     pa_assert(s);
@@ -661,11 +660,7 @@ static void source_free(pa_object *o) {
     pa_log_info("Freeing source %u \"%s\"", s->index, s->name);
 
     pa_idxset_free(s->outputs, NULL, NULL);
-
-    while ((so = pa_hashmap_steal_first(s->thread_info.outputs)))
-        pa_source_output_unref(so);
-
-    pa_hashmap_free(s->thread_info.outputs, NULL, NULL);
+    pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);