Use bitset_bindex, not int or unsigned int or size_t, to count bits.
(ebitset_bytes): Use size_t, not unsigned int, to count bytes.
(struct ebitset_struct.size, ebitset_elts_grow,
ebitset_elt_add, ebitset_elt_remove, ebitset_weed,
ebitset_elt_find, ebitset_list_reverse, ebitset_list, ebitset_init):
Use bitset_windex instead of unsigned int.
(ebitset_elts_grow): Check for arithmetic overflow when computing sizes.
be zero.
The bitset cache can be disabled either by setting cindex to
be zero.
The bitset cache can be disabled either by setting cindex to
- some large number or by setting csize to 0. Here
+ BITSET_WINDEX_MAX or by setting csize to 0. Here
we use the former approach since cindex needs to be updated whenever
cdata is changed.
*/
we use the former approach since cindex needs to be updated whenever
cdata is changed.
*/
/* Head of ebitset linked list. */
typedef struct ebitset_struct
{
/* Head of ebitset linked list. */
typedef struct ebitset_struct
{
- unsigned int size; /* Number of elements. */
+ bitset_windex size; /* Number of elements. */
ebitset_elts *elts; /* Expanding array of pointers to elements. */
}
*ebitset;
ebitset_elts *elts; /* Expanding array of pointers to elements. */
}
*ebitset;
static int ebitset_obstack_init = 0;
static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */
static int ebitset_obstack_init = 0;
static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */
-static void ebitset_elts_grow PARAMS ((bitset, unsigned int));
+static void ebitset_elts_grow PARAMS ((bitset, bitset_windex));
static ebitset_elt *ebitset_elt_alloc PARAMS ((void));
static ebitset_elt *ebitset_elt_calloc PARAMS ((void));
static ebitset_elt *ebitset_elt_alloc PARAMS ((void));
static ebitset_elt *ebitset_elt_calloc PARAMS ((void));
-static void ebitset_elt_add PARAMS ((bitset, ebitset_elt *, unsigned int));
-static void ebitset_elt_remove PARAMS ((bitset, unsigned int));
+static void ebitset_elt_add PARAMS ((bitset, ebitset_elt *, bitset_windex));
+static void ebitset_elt_remove PARAMS ((bitset, bitset_windex));
static void ebitset_elt_free PARAMS ((ebitset_elt *));
static ebitset_elt *ebitset_elt_find PARAMS ((bitset, bitset_windex,
enum ebitset_find_mode));
static ebitset_elt *ebitset_elt_last PARAMS ((bitset));
static int ebitset_elt_zero_p PARAMS ((ebitset_elt *));
static void ebitset_elt_free PARAMS ((ebitset_elt *));
static ebitset_elt *ebitset_elt_find PARAMS ((bitset, bitset_windex,
enum ebitset_find_mode));
static ebitset_elt *ebitset_elt_last PARAMS ((bitset));
static int ebitset_elt_zero_p PARAMS ((ebitset_elt *));
-static int ebitset_weed PARAMS ((bitset));
+static bitset_windex ebitset_weed PARAMS ((bitset));
static void ebitset_zero PARAMS ((bitset));
static void ebitset_copy_ PARAMS ((bitset, bitset));
static int ebitset_copy_cmp PARAMS ((bitset, bitset));
static void ebitset_set PARAMS ((bitset, bitset_bindex));
static void ebitset_reset PARAMS ((bitset, bitset_bindex));
static int ebitset_test PARAMS ((bitset, bitset_bindex));
static void ebitset_zero PARAMS ((bitset));
static void ebitset_copy_ PARAMS ((bitset, bitset));
static int ebitset_copy_cmp PARAMS ((bitset, bitset));
static void ebitset_set PARAMS ((bitset, bitset_bindex));
static void ebitset_reset PARAMS ((bitset, bitset_bindex));
static int ebitset_test PARAMS ((bitset, bitset_bindex));
-static int ebitset_size PARAMS ((bitset));
+static bitset_bindex ebitset_size PARAMS ((bitset));
static int ebitset_disjoint_p PARAMS ((bitset, bitset));
static int ebitset_equal_p PARAMS ((bitset, bitset));
static void ebitset_not PARAMS ((bitset, bitset));
static int ebitset_disjoint_p PARAMS ((bitset, bitset));
static int ebitset_equal_p PARAMS ((bitset, bitset));
static void ebitset_not PARAMS ((bitset, bitset));
static int ebitset_andn_cmp PARAMS ((bitset, bitset, bitset));
static int ebitset_or_cmp PARAMS ((bitset, bitset, bitset));
static int ebitset_xor_cmp PARAMS ((bitset, bitset, bitset));
static int ebitset_andn_cmp PARAMS ((bitset, bitset, bitset));
static int ebitset_or_cmp PARAMS ((bitset, bitset, bitset));
static int ebitset_xor_cmp PARAMS ((bitset, bitset, bitset));
-static int ebitset_list PARAMS ((bitset, bitset_bindex *, bitset_bindex,
- bitset_bindex *));
-static int ebitset_list_reverse
+static bitset_bindex ebitset_list PARAMS ((bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *));
+static bitset_bindex ebitset_list_reverse
PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
static void ebitset_free PARAMS ((bitset));
PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
static void ebitset_free PARAMS ((bitset));
#define EBITSET_WORDS(ELT) ((ELT)->u.words)
/* Disable bitset cache and mark BSET as being zero. */
#define EBITSET_WORDS(ELT) ((ELT)->u.words)
/* Disable bitset cache and mark BSET as being zero. */
-#define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX, \
+#define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX, \
-#define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX)
+#define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX)
/* Disable bitset cache and mark BSET as being possibly non-zero. */
#define EBITSET_NONZERO_SET(BSET) \
/* Disable bitset cache and mark BSET as being possibly non-zero. */
#define EBITSET_NONZERO_SET(BSET) \
static void
ebitset_elts_grow (bset, size)
bitset bset;
static void
ebitset_elts_grow (bset, size)
bitset bset;
- unsigned int oldsize;
- unsigned int newsize;
+ bitset_windex oldsize;
+ bitset_windex newsize;
oldsize = EBITSET_SIZE (bset);
newsize = oldsize + size;
oldsize = EBITSET_SIZE (bset);
newsize = oldsize + size;
+ if (BITSET_SIZE_MAX / sizeof (ebitset_elt *) < newsize)
+ xalloc_die ();
+
EBITSET_ELTS (bset) = xrealloc (EBITSET_ELTS (bset),
newsize * sizeof (ebitset_elt *));
EBITSET_SIZE (bset) = newsize;
EBITSET_ELTS (bset) = xrealloc (EBITSET_ELTS (bset),
newsize * sizeof (ebitset_elt *));
EBITSET_SIZE (bset) = newsize;
static inline void
ebitset_elt_remove (bset, eindex)
bitset bset;
static inline void
ebitset_elt_remove (bset, eindex)
bitset bset;
{
ebitset_elts *elts;
ebitset_elt *elt;
{
ebitset_elts *elts;
ebitset_elt *elt;
ebitset_elt_add (bset, elt, eindex)
bitset bset;
ebitset_elt *elt;
ebitset_elt_add (bset, elt, eindex)
bitset bset;
ebitset_elt *elt;
{
ebitset_elt *elt;
bitset_windex size;
{
ebitset_elt *elt;
bitset_windex size;
ebitset_elts *elts;
eindex = windex / EBITSET_ELT_WORDS;
ebitset_elts *elts;
eindex = windex / EBITSET_ELT_WORDS;
case EBITSET_CREATE:
if (eindex >= size)
{
case EBITSET_CREATE:
if (eindex >= size)
{
extra = eindex - size + 1;
extra = eindex - size + 1;
/* Weed out the zero elements from the elts. */
/* Weed out the zero elements from the elts. */
+static inline bitset_windex
ebitset_weed (bset)
bitset bset;
{
ebitset_elts *elts;
bitset_windex j;
ebitset_weed (bset)
bitset bset;
{
ebitset_elts *elts;
bitset_windex j;
if (EBITSET_ZERO_P (bset))
return 0;
if (EBITSET_ZERO_P (bset))
return 0;
/* Return size in bits of bitset SRC. */
/* Return size in bits of bitset SRC. */
ebitset_size (src)
bitset src;
{
ebitset_size (src)
bitset src;
{
/* Find list of up to NUM bits set in BSET starting from and including
*NEXT and store in array LIST. Return with actual number of bits
found and with *NEXT indicating where search stopped. */
/* Find list of up to NUM bits set in BSET starting from and including
*NEXT and store in array LIST. Return with actual number of bits
found and with *NEXT indicating where search stopped. */
ebitset_list_reverse (bset, list, num, next)
bitset bset;
bitset_bindex *list;
ebitset_list_reverse (bset, list, num, next)
bitset bset;
bitset_bindex *list;
unsigned int bcount;
bitset_bindex boffset;
bitset_windex windex;
unsigned int bcount;
bitset_bindex boffset;
bitset_windex windex;
bitset_windex woffset;
bitset_bindex count;
bitset_windex size;
bitset_windex woffset;
bitset_bindex count;
bitset_windex size;
/* Find list of up to NUM bits set in BSET starting from and including
*NEXT and store in array LIST. Return with actual number of bits
found and with *NEXT indicating where search stopped. */
/* Find list of up to NUM bits set in BSET starting from and including
*NEXT and store in array LIST. Return with actual number of bits
found and with *NEXT indicating where search stopped. */
ebitset_list (bset, list, num, next)
bitset bset;
bitset_bindex *list;
ebitset_list (bset, list, num, next)
bitset bset;
bitset_bindex *list;
{
bitset_bindex bitno;
bitset_windex windex;
{
bitset_bindex bitno;
bitset_windex windex;
bitset_bindex count;
bitset_windex size;
ebitset_elt *elt;
bitset_bindex count;
bitset_windex size;
ebitset_elt *elt;
/* Return size of initial structure. */
/* Return size of initial structure. */
ebitset_bytes (n_bits)
bitset_bindex n_bits ATTRIBUTE_UNUSED;
{
ebitset_bytes (n_bits)
bitset_bindex n_bits ATTRIBUTE_UNUSED;
{
bitset bset;
bitset_bindex n_bits;
{
bitset bset;
bitset_bindex n_bits;
{
bset->b.vtable = &ebitset_vtable;
bset->b.vtable = &ebitset_vtable;