]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hashmap: allow hashmap_move() to fail
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 14 Oct 2014 22:17:51 +0000 (00:17 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 23 Oct 2014 15:38:02 +0000 (17:38 +0200)
It cannot fail in the current hashmap implementation, but it may fail in
alternative implementations (unless a sufficiently large reservation has
been placed beforehand).

src/shared/hashmap.c
src/shared/hashmap.h
src/shared/set.c
src/shared/set.h
src/test/test-hashmap-plain.c

index ebc2ef19bba8556e81cded8a5d0ba961f68338f0..6f5f8204dd3dd0d2c733862edaa0b48662af3595 100644 (file)
@@ -815,16 +815,16 @@ int hashmap_reserve(Hashmap *h, unsigned entries_add) {
         return 0;
 }
 
-void hashmap_move(Hashmap *h, Hashmap *other) {
+int hashmap_move(Hashmap *h, Hashmap *other) {
         struct hashmap_entry *e, *n;
 
         assert(h);
 
         /* The same as hashmap_merge(), but every new item from other
-         * is moved to h. This function is guaranteed to succeed. */
+         * is moved to h. */
 
         if (!other)
-                return;
+                return 0;
 
         for (e = other->iterate_list_head; e; e = n) {
                 unsigned h_hash, other_hash;
@@ -839,6 +839,8 @@ void hashmap_move(Hashmap *h, Hashmap *other) {
                 unlink_entry(other, e, other_hash);
                 link_entry(h, e, h_hash);
         }
+
+        return 0;
 }
 
 int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key) {
index e0ff26c00635470367bf44a7d6ea3b57981fc0af..65fb3c0ee984d591c327db56f26b89eeb27046cc 100644 (file)
@@ -160,9 +160,9 @@ int hashmap_reserve(Hashmap *h, unsigned entries_add);
 static inline int ordered_hashmap_reserve(OrderedHashmap *h, unsigned entries_add) {
         return hashmap_reserve((Hashmap*) h, entries_add);
 }
-void hashmap_move(Hashmap *h, Hashmap *other);
-static inline void ordered_hashmap_move(OrderedHashmap *h, OrderedHashmap *other) {
-        hashmap_move((Hashmap*) h, (Hashmap*) other);
+int hashmap_move(Hashmap *h, Hashmap *other);
+static inline int ordered_hashmap_move(OrderedHashmap *h, OrderedHashmap *other) {
+        return hashmap_move((Hashmap*) h, (Hashmap*) other);
 }
 int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key);
 static inline int ordered_hashmap_move_one(OrderedHashmap *h, OrderedHashmap *other, const void *key) {
index 1a3465ca8bd59e95e18436de8c351b3647acd71b..84ab82a701738c08d567f9508953e56b1c94c929 100644 (file)
@@ -141,7 +141,7 @@ int set_reserve(Set *s, unsigned entries_add) {
         return hashmap_reserve(MAKE_HASHMAP(s), entries_add);
 }
 
-void set_move(Set *s, Set *other) {
+int set_move(Set *s, Set *other) {
         return hashmap_move(MAKE_HASHMAP(s), MAKE_HASHMAP(other));
 }
 
index 8fe071a326b175096383a887a12727a362d5db7c..d2622d17eaedd5e62bdaa4369c78fb60d7716532 100644 (file)
@@ -51,7 +51,7 @@ int set_remove_and_put(Set *s, void *old_value, void *new_value);
 
 int set_merge(Set *s, Set *other);
 int set_reserve(Set *s, unsigned entries_add);
-void set_move(Set *s, Set *other);
+int set_move(Set *s, Set *other);
 int set_move_one(Set *s, Set *other, void *value);
 
 unsigned set_size(Set *s);
index 8f7c039e3d514a768529d5783a2cde0ee69ab0dd..ce686b650caf7d6f7dedec3666016ddd8400ac91 100644 (file)
@@ -194,8 +194,8 @@ static void test_hashmap_move(void) {
         hashmap_put(m, "key 3", val3);
         hashmap_put(m, "key 4", val4);
 
-        hashmap_move(n, NULL);
-        hashmap_move(n, m);
+        assert(hashmap_move(n, NULL) == 0);
+        assert(hashmap_move(n, m) == 0);
 
         assert_se(hashmap_size(m) == 1);
         r = hashmap_get(m, "key 1");