basic/set: let set_put_strdup() create the set with string hash ops

If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.

hashmap_put_strdup() was already doing something similar.

(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)

No functional change intended.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-05-06 16:54:06 +02:00
parent 0894f08bf1
commit be32732168
25 changed files with 71 additions and 108 deletions
+2 -2
View File
@@ -1878,7 +1878,7 @@ static int mount_process_proc_self_mountinfo(Manager *m) {
/* Remember that this device might just have disappeared */
if (set_ensure_allocated(&gone, &path_hash_ops) < 0 ||
set_put_strdup(gone, mount->parameters_proc_self_mountinfo.what) < 0)
set_put_strdup(&gone, mount->parameters_proc_self_mountinfo.what) < 0)
log_oom(); /* we don't care too much about OOM here... */
}
@@ -1933,7 +1933,7 @@ static int mount_process_proc_self_mountinfo(Manager *m) {
/* Track devices currently used */
if (set_ensure_allocated(&around, &path_hash_ops) < 0 ||
set_put_strdup(around, mount->parameters_proc_self_mountinfo.what) < 0)
set_put_strdup(&around, mount->parameters_proc_self_mountinfo.what) < 0)
log_oom();
}
+1 -1
View File
@@ -4709,7 +4709,7 @@ int unit_write_setting(Unit *u, UnitWriteFlags flags, const char *name, const ch
/* Make sure the drop-in dir is registered in our path cache. This way we don't need to stupidly
* recreate the cache after every drop-in we write. */
if (u->manager->unit_path_cache) {
r = set_put_strdup(u->manager->unit_path_cache, p);
r = set_put_strdup(&u->manager->unit_path_cache, p);
if (r < 0)
return r;
}