From 6f3f39926b3de346695e6213b9378c643dc47817 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 17 May 2020 11:55:12 +0200 Subject: [PATCH] hash: add hash_xinsert * lib/hash.h, lib/xhash.c (hash_xinsert): New. --- ChangeLog | 5 +++++ lib/hash.h | 1 + lib/xhash.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index 889c756eba..65abbb5598 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-17 Akim Demaille + + hash: add hash_xinsert + * lib/hash.h, lib/xhash.c (hash_xinsert): New. + 2020-05-16 Bruno Haible findprog-lgpl: Fix link error (existing since 2008-09-02). diff --git a/lib/hash.h b/lib/hash.h index ae08ce8678..e5af43c0d7 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 1e998d2d15..95df54501c 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; +} -- 2.39.5