bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

hash: add hash_xinsert


From: Akim Demaille
Subject: hash: add hash_xinsert
Date: Sun, 17 May 2020 11:59:33 +0200

commit 6f3f39926b3de346695e6213b9378c643dc47817
Author: Akim Demaille <address@hidden>
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  <address@hidden>
+
+       hash: add hash_xinsert
+       * lib/hash.h, lib/xhash.c (hash_xinsert): New.
+
 2020-05-16  Bruno Haible  <address@hidden>
 
        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;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]