]> Savannah Git Hosting - gnulib.git/commitdiff
hash: Improve GCC 11 allocation-deallocation checking.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 17:45:19 +0000 (19:45 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 17:45:19 +0000 (19:45 +0200)
* lib/hash.h (hash_free): Move declaration up.
(hash_initialize, hash_xinitialize): Declare that deallocation must
happen through 'hash_free'.

ChangeLog
lib/hash.h

index d9427ede1ad5e237acd223b1268348035e465afa..8daff4879f158a3c4025e7081b8d94b30cd4574f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-08-07  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        hamt: Improve GCC 11 allocation-deallocation checking.
index 230d5cd3805b3fd9e63afbd65ebccb4dcc9a8992..5877b57a8792d4e0366e5469aedadd17e2853aed 100644 (file)
@@ -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.
  */