]> Savannah Git Hosting - gnulib.git/commitdiff
hash: add hash_xinsert
authorAkim Demaille <akim.demaille@gmail.com>
Sun, 17 May 2020 09:55:12 +0000 (11:55 +0200)
committerAkim Demaille <akim.demaille@gmail.com>
Sun, 17 May 2020 09:58:01 +0000 (11:58 +0200)
* lib/hash.h, lib/xhash.c (hash_xinsert): New.

ChangeLog
lib/hash.h
lib/xhash.c

index 889c756ebaae80cf8c4d774bd3ff0f441f137180..65abbb55982b2b52362cd4e234e63c2cbf0285fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-17  Akim Demaille  <akim@lrde.epita.fr>
+
+       hash: add hash_xinsert
+       * lib/hash.h, lib/xhash.c (hash_xinsert): New.
+
 2020-05-16  Bruno Haible  <bruno@clisp.org>
 
        findprog-lgpl: Fix link error (existing since 2008-09-02).
index ae08ce867855a3e11559e0bae39021a7b97f3ceb..e5af43c0d7a5bfaaadb1b433ebbc842eb74f5ba1 100644 (file)
@@ -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);
index 1e998d2d15e4a0fd6c1c85f67eb6794276a5a762..95df54501ce4f6342887372d05b1cc887d32076c 100644 (file)
@@ -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;
+}