bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

hash: Improve GCC 11 allocation-deallocation checking


From: Bruno Haible
Subject: hash: Improve GCC 11 allocation-deallocation checking
Date: Sat, 07 Aug 2021 19:46:18 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; )

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'.

diff --git a/lib/hash.h b/lib/hash.h
index 230d5cd..5877b57 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.
  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]