]> Savannah Git Hosting - gnulib.git/commitdiff
list, set, oset, map, omap: Prepare allocation-deallocation checking.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 22:00:36 +0000 (00:00 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 22:00:36 +0000 (00:00 +0200)
* lib/gl_list.h (gl_list_create_empty, gl_list_nx_create_empty,
gl_list_create, gl_list_nx_create): Add comment that deallocation must
happen through 'gl_list_free'.
* lib/gl_xlist.h (gl_list_create_empty, gl_list_create): Likewise.
* lib/gl_sublist.h (gl_sublist_create, gl_sublist_nx_create): Likewise.
* lib/gl_xsublist.h (gl_sublist_create): Likewise.
* lib/gl_set.h (gl_set_create_empty, gl_set_nx_create_empty): Add
comment that deallocation must happen through 'gl_set_free'.
* lib/gl_xset.h (gl_set_create_empty): Likewise.
* lib/gl_oset.h (gl_oset_create_empty, gl_oset_nx_create_empty): Add
comment that deallocation must happen through 'gl_oset_free'.
* lib/gl_xoset.h (gl_oset_create_empty): Likewise.
* lib/gl_map.h (gl_map_create_empty, gl_map_nx_create_empty): Add
comment that deallocation must happen through 'gl_map_free'.
* lib/gl_xmap.h (gl_map_create_empty): Likewise.
* lib/gl_omap.h (gl_omap_create_empty, gl_omap_nx_create_empty): Add
comment that deallocation must happen through 'gl_omap_free'.
* lib/gl_xomap.h (gl_omap_create_empty): Likewise.

13 files changed:
ChangeLog
lib/gl_list.h
lib/gl_map.h
lib/gl_omap.h
lib/gl_oset.h
lib/gl_set.h
lib/gl_sublist.h
lib/gl_xlist.h
lib/gl_xmap.h
lib/gl_xomap.h
lib/gl_xoset.h
lib/gl_xset.h
lib/gl_xsublist.h

index 0cb5d613eb30b56edaa246a1b19a6e21abd1507a..1f1230911433cc4189f259ea2d5fa9afd12d4b7c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2021-08-07  Bruno Haible  <bruno@clisp.org>
+
+       list, set, oset, map, omap: Prepare allocation-deallocation checking.
+       * lib/gl_list.h (gl_list_create_empty, gl_list_nx_create_empty,
+       gl_list_create, gl_list_nx_create): Add comment that deallocation must
+       happen through 'gl_list_free'.
+       * lib/gl_xlist.h (gl_list_create_empty, gl_list_create): Likewise.
+       * lib/gl_sublist.h (gl_sublist_create, gl_sublist_nx_create): Likewise.
+       * lib/gl_xsublist.h (gl_sublist_create): Likewise.
+       * lib/gl_set.h (gl_set_create_empty, gl_set_nx_create_empty): Add
+       comment that deallocation must happen through 'gl_set_free'.
+       * lib/gl_xset.h (gl_set_create_empty): Likewise.
+       * lib/gl_oset.h (gl_oset_create_empty, gl_oset_nx_create_empty): Add
+       comment that deallocation must happen through 'gl_oset_free'.
+       * lib/gl_xoset.h (gl_oset_create_empty): Likewise.
+       * lib/gl_map.h (gl_map_create_empty, gl_map_nx_create_empty): Add
+       comment that deallocation must happen through 'gl_map_free'.
+       * lib/gl_xmap.h (gl_map_create_empty): Likewise.
+       * lib/gl_omap.h (gl_omap_create_empty, gl_omap_nx_create_empty): Add
+       comment that deallocation must happen through 'gl_omap_free'.
+       * lib/gl_xomap.h (gl_omap_create_empty): Likewise.
+
 2021-08-07  Bruno Haible  <bruno@clisp.org>
 
        xgetdomainname: Improve GCC 11 allocation-deallocation checking.
index e2da4f1b8dc8208a7c38ec33ef0899ae214c147c..3374ae274d7f591d109fb3d8fc794161e91dd923 100644 (file)
@@ -152,13 +152,16 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
                                        gl_listelement_equals_fn equals_fn,
                                        gl_listelement_hashcode_fn hashcode_fn,
                                        gl_listelement_dispose_fn dispose_fn,
-                                       bool allow_duplicates);
+                                       bool allow_duplicates)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation,
                                           gl_listelement_equals_fn equals_fn,
                                           gl_listelement_hashcode_fn hashcode_fn,
                                           gl_listelement_dispose_fn dispose_fn,
-                                          bool allow_duplicates);
+                                          bool allow_duplicates)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/;
 
 /* Creates a list with given contents.
    IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
@@ -177,14 +180,17 @@ extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
                                  gl_listelement_hashcode_fn hashcode_fn,
                                  gl_listelement_dispose_fn dispose_fn,
                                  bool allow_duplicates,
-                                 size_t count, const void **contents);
+                                 size_t count, const void **contents)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation,
                                     gl_listelement_equals_fn equals_fn,
                                     gl_listelement_hashcode_fn hashcode_fn,
                                     gl_listelement_dispose_fn dispose_fn,
                                     bool allow_duplicates,
-                                    size_t count, const void **contents);
+                                    size_t count, const void **contents)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/;
 
 /* Returns the current number of elements in a list.  */
 extern size_t gl_list_size (gl_list_t list);
@@ -591,7 +597,9 @@ struct gl_list_impl_base
 /* Define all functions of this file as accesses to the
    struct gl_list_implementation.  */
 
-GL_LIST_INLINE gl_list_t
+GL_LIST_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+gl_list_t
 gl_list_nx_create_empty (gl_list_implementation_t implementation,
                          gl_listelement_equals_fn equals_fn,
                          gl_listelement_hashcode_fn hashcode_fn,
@@ -603,7 +611,9 @@ gl_list_nx_create_empty (gl_list_implementation_t implementation,
                                           allow_duplicates);
 }
 
-GL_LIST_INLINE gl_list_t
+GL_LIST_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+gl_list_t
 gl_list_nx_create (gl_list_implementation_t implementation,
                    gl_listelement_equals_fn equals_fn,
                    gl_listelement_hashcode_fn hashcode_fn,
index 118d4e321cecfba8f09e2f3db4e8e8c7821eb08f..a0c9f93cd0a696f84fa77814b850f2921b32d2d3 100644 (file)
@@ -117,13 +117,16 @@ extern gl_map_t gl_map_create_empty (gl_map_implementation_t implementation,
                                      gl_mapkey_equals_fn equals_fn,
                                      gl_mapkey_hashcode_fn hashcode_fn,
                                      gl_mapkey_dispose_fn kdispose_fn,
-                                     gl_mapvalue_dispose_fn vdispose_fn);
+                                     gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_map_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_map_t gl_map_nx_create_empty (gl_map_implementation_t implementation,
                                         gl_mapkey_equals_fn equals_fn,
                                         gl_mapkey_hashcode_fn hashcode_fn,
                                         gl_mapkey_dispose_fn kdispose_fn,
-                                        gl_mapvalue_dispose_fn vdispose_fn);
+                                        gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_map_free, 1)*/;
 
 /* Returns the current number of pairs in a map.  */
 extern size_t gl_map_size (gl_map_t map);
@@ -255,7 +258,9 @@ struct gl_map_impl_base
 /* Define most functions of this file as accesses to the
    struct gl_map_implementation.  */
 
-GL_MAP_INLINE gl_map_t
+GL_MAP_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_map_free, 1)*/
+gl_map_t
 gl_map_nx_create_empty (gl_map_implementation_t implementation,
                         gl_mapkey_equals_fn equals_fn,
                         gl_mapkey_hashcode_fn hashcode_fn,
index b2dacfb28342387e3094268756265edcd48a6674..f187d5d3c5294b20de6c75fc5d89aef2c1db42a9 100644 (file)
@@ -117,12 +117,15 @@ typedef const struct gl_omap_implementation * gl_omap_implementation_t;
 extern gl_omap_t gl_omap_create_empty (gl_omap_implementation_t implementation,
                                        gl_mapkey_compar_fn compar_fn,
                                        gl_mapkey_dispose_fn kdispose_fn,
-                                       gl_mapvalue_dispose_fn vdispose_fn);
+                                       gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_omap_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_omap_t gl_omap_nx_create_empty (gl_omap_implementation_t implementation,
                                           gl_mapkey_compar_fn compar_fn,
                                           gl_mapkey_dispose_fn kdispose_fn,
-                                          gl_mapvalue_dispose_fn vdispose_fn);
+                                          gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_omap_free, 1)*/;
 
 /* Returns the current number of pairs in an ordered map.  */
 extern size_t gl_omap_size (gl_omap_t map);
@@ -265,7 +268,9 @@ struct gl_omap_impl_base
 /* Define most functions of this file as accesses to the
    struct gl_omap_implementation.  */
 
-GL_OMAP_INLINE gl_omap_t
+GL_OMAP_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_omap_free, 1)*/
+gl_omap_t
 gl_omap_nx_create_empty (gl_omap_implementation_t implementation,
                          gl_mapkey_compar_fn compar_fn,
                          gl_mapkey_dispose_fn kdispose_fn,
index ac90f0445d75ac8ba8da8e82d0a7ca873741e791..44e7ef3db8e84e2ba4ec72756f380064f5d5b787 100644 (file)
@@ -107,11 +107,14 @@ typedef const struct gl_oset_implementation * gl_oset_implementation_t;
 /* declared in gl_xoset.h */
 extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
                                        gl_setelement_compar_fn compar_fn,
-                                       gl_setelement_dispose_fn dispose_fn);
+                                       gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_oset_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_oset_t gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
                                           gl_setelement_compar_fn compar_fn,
-                                          gl_setelement_dispose_fn dispose_fn);
+                                          gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_oset_free, 1)*/;
 
 /* Returns the current number of elements in an ordered set.  */
 extern size_t gl_oset_size (gl_oset_t set);
@@ -243,7 +246,9 @@ struct gl_oset_impl_base
 /* Define all functions of this file as accesses to the
    struct gl_oset_implementation.  */
 
-GL_OSET_INLINE gl_oset_t
+GL_OSET_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_oset_free, 1)*/
+gl_oset_t
 gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
                          gl_setelement_compar_fn compar_fn,
                          gl_setelement_dispose_fn dispose_fn)
index 4e68cc739d38ef66d1668fa84fe47045cc83562f..aa803e6db366bf3a77fad0f9500a36fbce7a9503 100644 (file)
@@ -106,12 +106,15 @@ typedef const struct gl_set_implementation * gl_set_implementation_t;
 extern gl_set_t gl_set_create_empty (gl_set_implementation_t implementation,
                                      gl_setelement_equals_fn equals_fn,
                                      gl_setelement_hashcode_fn hashcode_fn,
-                                     gl_setelement_dispose_fn dispose_fn);
+                                     gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_set_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_set_t gl_set_nx_create_empty (gl_set_implementation_t implementation,
                                         gl_setelement_equals_fn equals_fn,
                                         gl_setelement_hashcode_fn hashcode_fn,
-                                        gl_setelement_dispose_fn dispose_fn);
+                                        gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_set_free, 1)*/;
 
 /* Returns the current number of elements in a set.  */
 extern size_t gl_set_size (gl_set_t set);
@@ -209,7 +212,9 @@ struct gl_set_impl_base
 /* Define all functions of this file as accesses to the
    struct gl_set_implementation.  */
 
-GL_SET_INLINE gl_set_t
+GL_SET_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_set_free, 1)*/
+gl_set_t
 gl_set_nx_create_empty (gl_set_implementation_t implementation,
                         gl_setelement_equals_fn equals_fn,
                         gl_setelement_hashcode_fn hashcode_fn,
index eb6fb7398bb1a54e65159f886fcebb922a4bce3e..f1bf68d36fcf0e4f15a704723e5a5014590da441 100644 (file)
@@ -35,11 +35,14 @@ extern "C" {
  */
 #if 0 /* declared in gl_xsublist.h */
 extern gl_list_t gl_sublist_create (gl_list_t whole_list,
-                                    size_t start_index, size_t end_index);
+                                    size_t start_index, size_t end_index)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 #endif
 /* Likewise.  Returns NULL upon out-of-memory.  */
 extern gl_list_t gl_sublist_nx_create (gl_list_t whole_list,
-                                       size_t start_index, size_t end_index);
+                                       size_t start_index, size_t end_index)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/;
 
 
 #ifdef __cplusplus
index 87fd6ea528b9482737054de69c03a6eca3c6b4e7..7e66ab250500ca7746e09216e1553644e68afeee 100644 (file)
@@ -41,13 +41,17 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
                                        gl_listelement_equals_fn equals_fn,
                                        gl_listelement_hashcode_fn hashcode_fn,
                                        gl_listelement_dispose_fn dispose_fn,
-                                       bool allow_duplicates);
+                                       bool allow_duplicates)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
                                  gl_listelement_equals_fn equals_fn,
                                  gl_listelement_hashcode_fn hashcode_fn,
                                  gl_listelement_dispose_fn dispose_fn,
                                  bool allow_duplicates,
-                                 size_t count, const void **contents);
+                                 size_t count, const void **contents)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
                                     const void *elt);
 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
@@ -67,7 +71,10 @@ extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
                                          const void *elt);
 #endif
 
-GL_XLIST_INLINE gl_list_t
+GL_XLIST_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_list_t
 gl_list_create_empty (gl_list_implementation_t implementation,
                       gl_listelement_equals_fn equals_fn,
                       gl_listelement_hashcode_fn hashcode_fn,
@@ -82,7 +89,10 @@ gl_list_create_empty (gl_list_implementation_t implementation,
   return result;
 }
 
-GL_XLIST_INLINE gl_list_t
+GL_XLIST_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_list_t
 gl_list_create (gl_list_implementation_t implementation,
                 gl_listelement_equals_fn equals_fn,
                 gl_listelement_hashcode_fn hashcode_fn,
index 1edf44ba3b21bc01e0c7538c7fe2c9e61b2ae889..01bb9deca3c06e6f8826d742b783c3a71a75af36 100644 (file)
@@ -42,13 +42,18 @@ extern gl_map_t gl_map_create_empty (gl_map_implementation_t implementation,
                                      gl_mapkey_equals_fn equals_fn,
                                      gl_mapkey_hashcode_fn hashcode_fn,
                                      gl_mapkey_dispose_fn kdispose_fn,
-                                     gl_mapvalue_dispose_fn vdispose_fn);
+                                     gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_map_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern bool gl_map_put (gl_map_t map, const void *key, const void *value);
 extern bool gl_map_getput (gl_map_t map, const void *key, const void *value,
                            const void **oldvaluep);
 #endif
 
-GL_XMAP_INLINE gl_map_t
+GL_XMAP_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_map_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_map_t
 gl_map_create_empty (gl_map_implementation_t implementation,
                      gl_mapkey_equals_fn equals_fn,
                      gl_mapkey_hashcode_fn hashcode_fn,
index a74ac6da4f040c46ff92f22d67f69f0a15a146bc..bc21528a651912d042969ada689f38718909b1b0 100644 (file)
@@ -41,13 +41,18 @@ extern "C" {
 extern gl_omap_t gl_omap_create_empty (gl_omap_implementation_t implementation,
                                        gl_mapkey_compar_fn compar_fn,
                                        gl_mapkey_dispose_fn kdispose_fn,
-                                       gl_mapvalue_dispose_fn vdispose_fn);
+                                       gl_mapvalue_dispose_fn vdispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_omap_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern bool gl_omap_put (gl_omap_t map, const void *key, const void *value);
 extern bool gl_omap_getput (gl_omap_t map, const void *key, const void *value,
                             const void **oldvaluep);
 #endif
 
-GL_XOMAP_INLINE gl_omap_t
+GL_XOMAP_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_omap_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_omap_t
 gl_omap_create_empty (gl_omap_implementation_t implementation,
                       gl_mapkey_compar_fn compar_fn,
                       gl_mapkey_dispose_fn kdispose_fn,
index a2c793070792b401c1b4dd440a2a4221d20d12fb..ced666d634524a68c55c141867ab9af6638ef5b7 100644 (file)
@@ -40,11 +40,16 @@ extern "C" {
 #if 0 /* These are defined inline below.  */
 extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
                                        gl_setelement_compar_fn compar_fn,
-                                       gl_setelement_dispose_fn dispose_fn);
+                                       gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_oset_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern bool gl_oset_add (gl_oset_t set, const void *elt);
 #endif
 
-GL_XOSET_INLINE gl_oset_t
+GL_XOSET_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_oset_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_oset_t
 gl_oset_create_empty (gl_oset_implementation_t implementation,
                       gl_setelement_compar_fn compar_fn,
                       gl_setelement_dispose_fn dispose_fn)
index 88fa4835f159e6b8738f1683468b63c32f69acb1..5206ba0ceea457c0e409c35cb28bc1d700ddbec6 100644 (file)
@@ -41,11 +41,16 @@ extern "C" {
 extern gl_set_t gl_set_create_empty (gl_set_implementation_t implementation,
                                      gl_setelement_equals_fn equals_fn,
                                      gl_setelement_hashcode_fn hashcode_fn,
-                                     gl_setelement_dispose_fn dispose_fn);
+                                     gl_setelement_dispose_fn dispose_fn)
+  /*_GL_ATTRIBUTE_DEALLOC (gl_set_free, 1)*/
+  _GL_ATTRIBUTE_RETURNS_NONNULL;
 extern bool gl_set_add (gl_set_t set, const void *elt);
 #endif
 
-GL_XSET_INLINE gl_set_t
+GL_XSET_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_set_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_set_t
 gl_set_create_empty (gl_set_implementation_t implementation,
                      gl_setelement_equals_fn equals_fn,
                      gl_setelement_hashcode_fn hashcode_fn,
index cae165eff0f422d405c3cde380445a2a2883d070..2427caac8ee265b2a1328d85462432b5232d2d96 100644 (file)
@@ -37,7 +37,10 @@ extern "C" {
 /* These functions are thin wrappers around the corresponding functions with
    _nx_ infix from gl_sublist.h.  Upon out-of-memory, they invoke
    xalloc_die (), instead of returning an error indicator.  */
-GL_XSUBLIST_INLINE gl_list_t
+GL_XSUBLIST_INLINE
+/*_GL_ATTRIBUTE_DEALLOC (gl_list_free, 1)*/
+_GL_ATTRIBUTE_RETURNS_NONNULL
+gl_list_t
 gl_sublist_create (gl_list_t whole_list, size_t start_index, size_t end_index)
 {
   gl_list_t result = gl_sublist_nx_create (whole_list, start_index, end_index);