@@ -84,6 +84,7 @@ bms_copy(const Bitmapset *a)
84
84
85
85
if (a == NULL )
86
86
return NULL ;
87
+ Assert (IsA (a , Bitmapset ));
87
88
size = BITMAPSET_SIZE (a -> nwords );
88
89
result = (Bitmapset * ) palloc (size );
89
90
memcpy (result , a , size );
@@ -98,8 +99,8 @@ bms_equal(const Bitmapset *a, const Bitmapset *b)
98
99
{
99
100
int i ;
100
101
101
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
102
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
102
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
103
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
103
104
104
105
/* Handle cases where either input is NULL */
105
106
if (a == NULL )
@@ -139,8 +140,8 @@ bms_compare(const Bitmapset *a, const Bitmapset *b)
139
140
{
140
141
int i ;
141
142
142
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
143
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
143
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
144
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
144
145
145
146
/* Handle cases where either input is NULL */
146
147
if (a == NULL )
@@ -215,6 +216,9 @@ bms_union(const Bitmapset *a, const Bitmapset *b)
215
216
int otherlen ;
216
217
int i ;
217
218
219
+ Assert (a == NULL || IsA (a , Bitmapset ));
220
+ Assert (b == NULL || IsA (b , Bitmapset ));
221
+
218
222
/* Handle cases where either input is NULL */
219
223
if (a == NULL )
220
224
return bms_copy (b );
@@ -253,6 +257,9 @@ bms_intersect(const Bitmapset *a, const Bitmapset *b)
253
257
int resultlen ;
254
258
int i ;
255
259
260
+ Assert (a == NULL || IsA (a , Bitmapset ));
261
+ Assert (b == NULL || IsA (b , Bitmapset ));
262
+
256
263
/* Handle cases where either input is NULL */
257
264
if (a == NULL || b == NULL )
258
265
return NULL ;
@@ -299,15 +306,17 @@ bms_difference(const Bitmapset *a, const Bitmapset *b)
299
306
Bitmapset * result ;
300
307
int i ;
301
308
302
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
303
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
309
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
310
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
304
311
305
312
/* Handle cases where either input is NULL */
306
313
if (a == NULL )
307
314
return NULL ;
308
315
if (b == NULL )
309
316
return bms_copy (a );
310
317
318
+ Assert (IsA (a , Bitmapset ) && IsA (b , Bitmapset ));
319
+
311
320
/*
312
321
* In Postgres' usage, an empty result is a very common case, so it's
313
322
* worth optimizing for that by testing bms_nonempty_difference(). This
@@ -364,15 +373,17 @@ bms_is_subset(const Bitmapset *a, const Bitmapset *b)
364
373
{
365
374
int i ;
366
375
367
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
368
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
376
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
377
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
369
378
370
379
/* Handle cases where either input is NULL */
371
380
if (a == NULL )
372
381
return true; /* empty set is a subset of anything */
373
382
if (b == NULL )
374
383
return false;
375
384
385
+ Assert (IsA (a , Bitmapset ) && IsA (b , Bitmapset ));
386
+
376
387
/* 'a' can't be a subset of 'b' if it contains more words */
377
388
if (a -> nwords > b -> nwords )
378
389
return false;
@@ -399,8 +410,8 @@ bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
399
410
int shortlen ;
400
411
int i ;
401
412
402
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
403
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
413
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
414
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
404
415
405
416
/* Handle cases where either input is NULL */
406
417
if (a == NULL )
@@ -411,6 +422,9 @@ bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
411
422
}
412
423
if (b == NULL )
413
424
return BMS_SUBSET2 ;
425
+
426
+ Assert (IsA (a , Bitmapset ) && IsA (b , Bitmapset ));
427
+
414
428
/* Check common words */
415
429
result = BMS_EQUAL ; /* status so far */
416
430
shortlen = Min (a -> nwords , b -> nwords );
@@ -467,6 +481,9 @@ bms_is_member(int x, const Bitmapset *a)
467
481
elog (ERROR , "negative bitmapset member not allowed" );
468
482
if (a == NULL )
469
483
return false;
484
+
485
+ Assert (IsA (a , Bitmapset ));
486
+
470
487
wordnum = WORDNUM (x );
471
488
bitnum = BITNUM (x );
472
489
if (wordnum >= a -> nwords )
@@ -495,6 +512,8 @@ bms_member_index(Bitmapset *a, int x)
495
512
if (!bms_is_member (x , a ))
496
513
return -1 ;
497
514
515
+ Assert (IsA (a , Bitmapset ));
516
+
498
517
wordnum = WORDNUM (x );
499
518
bitnum = BITNUM (x );
500
519
@@ -529,6 +548,9 @@ bms_overlap(const Bitmapset *a, const Bitmapset *b)
529
548
int shortlen ;
530
549
int i ;
531
550
551
+ Assert (a == NULL || IsA (a , Bitmapset ));
552
+ Assert (b == NULL || IsA (b , Bitmapset ));
553
+
532
554
/* Handle cases where either input is NULL */
533
555
if (a == NULL || b == NULL )
534
556
return false;
@@ -553,6 +575,8 @@ bms_overlap_list(const Bitmapset *a, const List *b)
553
575
int wordnum ,
554
576
bitnum ;
555
577
578
+ Assert (a == NULL || IsA (a , Bitmapset ));
579
+
556
580
if (a == NULL || b == NIL )
557
581
return false;
558
582
@@ -582,8 +606,8 @@ bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
582
606
{
583
607
int i ;
584
608
585
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
586
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
609
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
610
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
587
611
588
612
/* Handle cases where either input is NULL */
589
613
if (a == NULL )
@@ -617,6 +641,9 @@ bms_singleton_member(const Bitmapset *a)
617
641
618
642
if (a == NULL )
619
643
elog (ERROR , "bitmapset is empty" );
644
+
645
+ Assert (IsA (a , Bitmapset ));
646
+
620
647
nwords = a -> nwords ;
621
648
wordnum = 0 ;
622
649
do
@@ -657,6 +684,7 @@ bms_get_singleton_member(const Bitmapset *a, int *member)
657
684
658
685
if (a == NULL )
659
686
return false;
687
+ Assert (IsA (a , Bitmapset ));
660
688
nwords = a -> nwords ;
661
689
wordnum = 0 ;
662
690
do
@@ -690,6 +718,7 @@ bms_num_members(const Bitmapset *a)
690
718
691
719
if (a == NULL )
692
720
return 0 ;
721
+ Assert (IsA (a , Bitmapset ));
693
722
nwords = a -> nwords ;
694
723
wordnum = 0 ;
695
724
do
@@ -717,6 +746,7 @@ bms_membership(const Bitmapset *a)
717
746
718
747
if (a == NULL )
719
748
return BMS_EMPTY_SET ;
749
+ Assert (IsA (a , Bitmapset ));
720
750
nwords = a -> nwords ;
721
751
wordnum = 0 ;
722
752
do
@@ -759,6 +789,7 @@ bms_add_member(Bitmapset *a, int x)
759
789
elog (ERROR , "negative bitmapset member not allowed" );
760
790
if (a == NULL )
761
791
return bms_make_singleton (x );
792
+ Assert (IsA (a , Bitmapset ));
762
793
wordnum = WORDNUM (x );
763
794
bitnum = BITNUM (x );
764
795
@@ -799,6 +830,9 @@ bms_del_member(Bitmapset *a, int x)
799
830
elog (ERROR , "negative bitmapset member not allowed" );
800
831
if (a == NULL )
801
832
return NULL ;
833
+
834
+ Assert (IsA (a , Bitmapset ));
835
+
802
836
wordnum = WORDNUM (x );
803
837
bitnum = BITNUM (x );
804
838
@@ -839,6 +873,9 @@ bms_add_members(Bitmapset *a, const Bitmapset *b)
839
873
int otherlen ;
840
874
int i ;
841
875
876
+ Assert (a == NULL || IsA (a , Bitmapset ));
877
+ Assert (b == NULL || IsA (b , Bitmapset ));
878
+
842
879
/* Handle cases where either input is NULL */
843
880
if (a == NULL )
844
881
return bms_copy (b );
@@ -884,6 +921,8 @@ bms_add_range(Bitmapset *a, int lower, int upper)
884
921
ushiftbits ,
885
922
wordnum ;
886
923
924
+ Assert (a == NULL || IsA (a , Bitmapset ));
925
+
887
926
/* do nothing if nothing is called for, without further checking */
888
927
if (upper < lower )
889
928
return a ;
@@ -954,6 +993,9 @@ bms_int_members(Bitmapset *a, const Bitmapset *b)
954
993
int shortlen ;
955
994
int i ;
956
995
996
+ Assert (a == NULL || IsA (a , Bitmapset ));
997
+ Assert (b == NULL || IsA (b , Bitmapset ));
998
+
957
999
/* Handle cases where either input is NULL */
958
1000
if (a == NULL )
959
1001
return NULL ;
@@ -994,8 +1036,8 @@ bms_del_members(Bitmapset *a, const Bitmapset *b)
994
1036
{
995
1037
int i ;
996
1038
997
- Assert (a == NULL || a -> words [a -> nwords - 1 ] != 0 );
998
- Assert (b == NULL || b -> words [b -> nwords - 1 ] != 0 );
1039
+ Assert (a == NULL || ( IsA ( a , Bitmapset ) && a -> words [a -> nwords - 1 ] != 0 ) );
1040
+ Assert (b == NULL || ( IsA ( b , Bitmapset ) && b -> words [b -> nwords - 1 ] != 0 ) );
999
1041
1000
1042
/* Handle cases where either input is NULL */
1001
1043
if (a == NULL )
@@ -1055,6 +1097,9 @@ bms_join(Bitmapset *a, Bitmapset *b)
1055
1097
int otherlen ;
1056
1098
int i ;
1057
1099
1100
+ Assert (a == NULL || IsA (a , Bitmapset ));
1101
+ Assert (b == NULL || IsA (b , Bitmapset ));
1102
+
1058
1103
/* Handle cases where either input is NULL */
1059
1104
if (a == NULL )
1060
1105
return b ;
@@ -1109,6 +1154,8 @@ bms_next_member(const Bitmapset *a, int prevbit)
1109
1154
int wordnum ;
1110
1155
bitmapword mask ;
1111
1156
1157
+ Assert (a == NULL || IsA (a , Bitmapset ));
1158
+
1112
1159
if (a == NULL )
1113
1160
return -2 ;
1114
1161
nwords = a -> nwords ;
@@ -1168,6 +1215,8 @@ bms_prev_member(const Bitmapset *a, int prevbit)
1168
1215
int ushiftbits ;
1169
1216
bitmapword mask ;
1170
1217
1218
+ Assert (a == NULL || IsA (a , Bitmapset ));
1219
+
1171
1220
/*
1172
1221
* If set is NULL or if there are no more bits to the right then we've
1173
1222
* nothing to do.
0 commit comments