]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: let freeing functions accept NULL
authorAkim Demaille <akim.demaille@gmail.com>
Mon, 21 Oct 2019 14:47:00 +0000 (16:47 +0200)
committerAkim Demaille <akim.demaille@gmail.com>
Mon, 21 Oct 2019 14:52:34 +0000 (16:52 +0200)
* lib/bitset.c (bitset_free, bitset_obstack_free): Do nothing if
given NULL.
* lib/bitset.h: Document that.
* doc/bitset.texi: Fix the example, and demonstrate bitset_free.

ChangeLog
doc/bitset.texi
lib/bitset.c
lib/bitset.h

index cd62812712dec562cd65b1f99c8aa190e3e11fd8..56102ad45b0265f414257028c3561169b9712272 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-10-21  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: let freeing functions accept NULL.
+       * lib/bitset.c (bitset_free, bitset_obstack_free): Do nothing if
+       given NULL.
+       * lib/bitset.h: Document that.
+       * doc/bitset.texi: Fix the example, and demonstrate bitset_free.
+
 2019-10-15  Paul Eggert  <eggert@cs.ucla.edu>
 
        inttypes: use more-robust test for int range
index d624c0952a1923ebb29413408c94a7348df947bb..b9e5407778d05905ddd5f0b4f9f9d82cb4640f87 100644 (file)
@@ -48,9 +48,9 @@ Prefer fastest at memory expense.
 enum { nbits = 32 };
 
 bitset bs0 = bitset_create (nbits, BITSET_FIXED);
-bitset_set (bs1, 1);
-bitset_set (bs1, 3);
-bitset_set (bs1, 5);
+bitset_set (bs0, 1);
+bitset_set (bs0, 3);
+bitset_set (bs0, 5);
 
 bitset bs1 = bitset_create (nbits, BITSET_FIXED);
 bitset_set (bs1, 0);
@@ -58,6 +58,10 @@ bitset_set (bs1, 2);
 bitset_set (bs1, 4);
 
 bitset bs = bitset_create (nbits, BITSET_FIXED);
-bitset_or (bs, b1, b2);
+bitset_or (bs, bs0, bs1);
 ASSERT (bitset_count (bs) == 6);
+
+bitset_free (bs);
+bitset_free (bs1);
+bitset_free (bs0);
 @end smallexample
index 7ea592e1343ebd7d9e07ddf0ad30dffe2a3f8e56..c3fe923bfa76dcee4148c7300d6e6316b194dd75 100644 (file)
@@ -168,8 +168,11 @@ bitset_create (bitset_bindex n_bits, unsigned attr)
 void
 bitset_free (bitset bset)
 {
-  BITSET_FREE_ (bset);
-  free (bset);
+  if (bset)
+    {
+      BITSET_FREE_ (bset);
+      free (bset);
+    }
 }
 
 
@@ -177,7 +180,8 @@ bitset_free (bitset bset)
 void
 bitset_obstack_free (bitset bset)
 {
-  BITSET_FREE_ (bset);
+  if (bset)
+    BITSET_FREE_ (bset);
 }
 
 
index e5bb015b883d7af8aa03338a0e8bc3acf6554122..ea04916ea437ec30b2474fb10189aaff2f550fb1 100644 (file)
@@ -109,7 +109,7 @@ enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
 /* Create a bitset of desired type and size.  The bitset is zeroed.  */
 bitset bitset_alloc (bitset_bindex, enum bitset_type);
 
-/* Free bitset.  */
+/* Free bitset.  Do nothing if NULL.  */
 void bitset_free (bitset);
 
 /* Create a bitset of desired type and size using an obstack.  The
@@ -117,7 +117,7 @@ void bitset_free (bitset);
 bitset bitset_obstack_alloc (struct obstack *bobstack,
                              bitset_bindex, enum bitset_type);
 
-/* Free bitset allocated on obstack.  */
+/* Free bitset allocated on obstack.  Do nothing if NULL.  */
 void bitset_obstack_free (bitset);
 
 /* Create a bitset of desired size and attributes.  The bitset is zeroed.  */