summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2021-08-07 19:45:19 +0200
committerBruno Haible <bruno@clisp.org>2021-08-07 19:45:19 +0200
commitd665f4db8310ed0c78c1ba0e30bbb6dcf9274f43 (patch)
treea9727ac39a317398e55be997de797e1b98453076 /lib
parent5adafd694ccdddbc6ac476b126d7e7bf0ac7befa (diff)
downloadgnulib-d665f4db8310ed0c78c1ba0e30bbb6dcf9274f43.tar.gz
hash: Improve GCC 11 allocation-deallocation checking.
* lib/hash.h (hash_free): Move declaration up. (hash_initialize, hash_xinitialize): Declare that deallocation must happen through 'hash_free'.
Diffstat (limited to 'lib')
-rw-r--r--lib/hash.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/hash.h b/lib/hash.h
index 230d5cd380..5877b57a87 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -139,6 +139,12 @@ typedef size_t (*Hash_hasher) (const void *entry, size_t table_size);
typedef bool (*Hash_comparator) (const void *entry1, const void *entry2);
typedef void (*Hash_data_freer) (void *entry);
+/* Reclaim all storage associated with a hash table. If a data_freer
+ function has been supplied by the user when the hash table was created,
+ this function applies it to the data of each entry before freeing that
+ entry. */
+extern void hash_free (Hash_table *table);
+
/* Allocate and return a new hash table, or NULL upon failure. The initial
number of buckets is automatically selected so as to _guarantee_ that you
may insert at least CANDIDATE different user entries before any growth of
@@ -177,7 +183,8 @@ extern Hash_table *hash_initialize (size_t candidate,
const Hash_tuning *tuning,
Hash_hasher hasher,
Hash_comparator comparator,
- Hash_data_freer data_freer);
+ Hash_data_freer data_freer)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (hash_free, 1);
/* Same as hash_initialize, but invokes xalloc_die on memory exhaustion. */
/* This function is defined by module 'xhash'. */
@@ -186,19 +193,15 @@ extern Hash_table *hash_xinitialize (size_t candidate,
const Hash_tuning *tuning,
Hash_hasher hasher,
Hash_comparator comparator,
- Hash_data_freer data_freer);
+ Hash_data_freer data_freer)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (hash_free, 1)
+ _GL_ATTRIBUTE_RETURNS_NONNULL;
/* Make all buckets empty, placing any chained entries on the free list.
Apply the user-specified function data_freer (if any) to the datas of any
affected entries. */
extern void hash_clear (Hash_table *table);
-/* Reclaim all storage associated with a hash table. If a data_freer
- function has been supplied by the user when the hash table was created,
- this function applies it to the data of each entry before freeing that
- entry. */
-extern void hash_free (Hash_table *table);
-
/*
* Insertion and deletion.
*/