+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
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);
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
void
bitset_free (bitset bset)
{
- BITSET_FREE_ (bset);
- free (bset);
+ if (bset)
+ {
+ BITSET_FREE_ (bset);
+ free (bset);
+ }
}
void
bitset_obstack_free (bitset bset)
{
- BITSET_FREE_ (bset);
+ if (bset)
+ BITSET_FREE_ (bset);
}
/* 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
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. */