commit 6f3f39926b3de346695e6213b9378c643dc47817
Author: Akim Demaille <[email protected]>
Date: Sun May 17 11:55:12 2020 +0200
hash: add hash_xinsert
* lib/hash.h, lib/xhash.c (hash_xinsert): New.
diff --git a/ChangeLog b/ChangeLog
index 889c756eb..65abbb559 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-17 Akim Demaille <[email protected]>
+
+ hash: add hash_xinsert
+ * lib/hash.h, lib/xhash.c (hash_xinsert): New.
+
2020-05-16 Bruno Haible <[email protected]>
findprog-lgpl: Fix link error (existing since 2008-09-02).
diff --git a/lib/hash.h b/lib/hash.h
index ae08ce867..e5af43c0d 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -80,6 +80,7 @@ void hash_free (Hash_table *);
/* Insertion and deletion. */
bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_NODISCARD;
void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_NODISCARD;
+void *hash_xinsert (Hash_table *, const void *);
int hash_insert_if_absent (Hash_table *table, const void *entry,
const void **matched_ent);
diff --git a/lib/xhash.c b/lib/xhash.c
index 1e998d2d1..95df54501 100644
--- a/lib/xhash.c
+++ b/lib/xhash.c
@@ -36,3 +36,15 @@ hash_xinitialize (size_t candidate, const Hash_tuning
*tuning,
xalloc_die ();
return res;
}
+
+/* Same as hash_insert, but invokes xalloc_die on memory
+ exhaustion. */
+
+void *
+hash_xinsert (Hash_table *table, void const *entry)
+{
+ void *res = hash_insert (table, entry);
+ if (!res)
+ xalloc_die ();
+ return res;
+}