summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-10-15 00:17:51 +0200
committerMichal Schmidt <mschmidt@redhat.com>2014-10-23 17:38:02 +0200
commit7ad63f57b6ce7ae9e3cc19dcb441f0a4494fa3f2 (patch)
tree643272a659bd396c791a4fb4e12949102e87b2b3 /src/shared
parent09a65f92994445d8fecca34e71b423a8be1769bf (diff)
hashmap: allow hashmap_move() to fail
It cannot fail in the current hashmap implementation, but it may fail in alternative implementations (unless a sufficiently large reservation has been placed beforehand).
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/hashmap.c8
-rw-r--r--src/shared/hashmap.h6
-rw-r--r--src/shared/set.c2
-rw-r--r--src/shared/set.h2
4 files changed, 10 insertions, 8 deletions
diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index ebc2ef19bb..6f5f8204dd 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -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) {
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h
index e0ff26c006..65fb3c0ee9 100644
--- a/src/shared/hashmap.h
+++ b/src/shared/hashmap.h
@@ -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) {
diff --git a/src/shared/set.c b/src/shared/set.c
index 1a3465ca8b..84ab82a701 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -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));
}
diff --git a/src/shared/set.h b/src/shared/set.h
index 8fe071a326..d2622d17ea 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -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);