From d665f4db8310ed0c78c1ba0e30bbb6dcf9274f43 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 7 Aug 2021 19:45:19 +0200 Subject: [PATCH] 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'. --- ChangeLog | 7 +++++++ lib/hash.h | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9427ede1a..8daff4879f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-08-07 Bruno Haible + + 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'. + 2021-08-07 Bruno Haible hamt: Improve GCC 11 allocation-deallocation checking. 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. */ -- 2.39.5