4
4
format for these routines is dictated by Postgres architecture.
5
5
******************************************************************************/
6
6
7
- #include <stdio.h>
7
+ #include "postgres.h"
8
+
8
9
#include <float.h>
9
- #include <string.h>
10
10
11
- #include "postgres.h"
12
11
#include "access/gist.h"
13
12
#include "access/itup.h"
14
13
#include "access/rtree.h"
22
21
23
22
#define max (a ,b ) ((a) > (b) ? (a) : (b))
24
23
#define min (a ,b ) ((a) <= (b) ? (a) : (b))
25
- #define abs (a ) ((a) < (0) ? (- a) : (a))
24
+ #define abs (a ) ((a) < (0) ? -( a) : (a))
26
25
27
26
#define ARRPTR (x ) ( (int4 *) ARR_DATA_PTR(x) )
28
27
#ifdef PGSQL71
@@ -53,7 +52,7 @@ typedef char* BITVECP;
53
52
54
53
#define NULLIFY (a ) MemSet( a, 0, sizeof( BITVEC ) )
55
54
#define NEWSIG (a ) \
56
- a=(BITVECP) malloc( sizeof( BITVEC );\
55
+ a=(BITVECP) malloc( sizeof( BITVEC ) ) ;\
57
56
NULLIFY(a);
58
57
59
58
#define LOOPBYTE (a ) \
@@ -66,10 +65,11 @@ typedef char* BITVECP;
66
65
a;\
67
66
}
68
67
69
- #define getbytebit (x ,i ) ( *( (char*)(x) + (int)( i / BITBYTE ) ) )
70
- #define clrbit (x ,i ) getbytebit(x,i) &= ~( 0x01 << ( i % BITBYTE ) )
71
- #define setbit (x ,i ) getbytebit(x,i) |= ( 0x01 << ( i % BITBYTE ) )
72
- #define getbit (x ,i ) ( getbytebit(x,i) >> ( i % BITBYTE ) & 0x01 )
68
+ /* beware of multiple evaluation of arguments to these macros! */
69
+ #define GETBYTEBIT (x ,i ) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
70
+ #define CLRBIT (x ,i ) GETBYTEBIT(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
71
+ #define SETBIT (x ,i ) GETBYTEBIT(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
72
+ #define GETBIT (x ,i ) ( (GETBYTEBIT(x,i) >> ( (i) % BITBYTE )) & 0x01 )
73
73
74
74
#define union_sig (a ,b ,r ) LOOPBYTE(r[i] = a[i] | b[i])
75
75
#define inter_sig (a ,b ,r ) LOOPBYTE(r[i] = a[i] & b[i])
@@ -97,7 +97,7 @@ static void printbitvec( BITVEC bv ) {
97
97
int i ;
98
98
char str [ SIGLENBIT + 1 ];
99
99
str [ SIGLENBIT ] = '\0' ;
100
- LOOPBIT ( str [i ] = ( getbit (bv ,i ) ) ? '1' : '0' );
100
+ LOOPBIT ( str [i ] = ( GETBIT (bv ,i ) ) ? '1' : '0' );
101
101
102
102
elog (NOTICE ,"BV: %s" , str );
103
103
}
@@ -727,7 +727,7 @@ gensign(BITVEC sign, int * a, int len) {
727
727
int i ;
728
728
NULLIFY (sign );
729
729
for (i = 0 ; i < len ; i ++ ) {
730
- setbit ( sign , * a %SIGLENBIT );
730
+ SETBIT ( sign , ( * a ) %SIGLENBIT );
731
731
a ++ ;
732
732
}
733
733
}
@@ -770,7 +770,7 @@ rt__intbig_size(ArrayType *a, float* sz) {
770
770
}
771
771
772
772
bv = SIGPTR (a );
773
- LOOPBIT ( len += getbit (bv , i ) );
773
+ LOOPBIT ( len += GETBIT (bv , i ) );
774
774
* sz = (float ) len ;
775
775
return ;
776
776
}
@@ -780,8 +780,9 @@ _intbig_union(ArrayType *a, ArrayType *b) {
780
780
ArrayType * r = NULL ;
781
781
BITVECP da , db , dr ;
782
782
int i ;
783
-
783
+
784
784
if ( ARRISNULL ( a ) && ARRISNULL ( b ) ) return new_intArrayType (0 );
785
+
785
786
if ( ARRISNULL ( a ) ) {
786
787
r = copy_intArrayType ( b );
787
788
return r ;
@@ -876,7 +877,7 @@ g_intbig_compress(GISTENTRY *entry) {
876
877
gensign ( SIGPTR ( r ),
877
878
ARRPTR ( in ),
878
879
ARRSIZE ( in ) );
879
-
880
+
880
881
gistentryinit (* retval , (char * )r , entry -> rel , entry -> page , entry -> offset , VARSIZE ( r ), FALSE);
881
882
882
883
#ifdef PGSQL71
@@ -971,10 +972,12 @@ g_intbig_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result){
971
972
bool
972
973
g_intbig_consistent (GISTENTRY * entry , ArrayType * query , StrategyNumber strategy ) {
973
974
bool retval ;
974
- ArrayType * q = new_intArrayType ( SIGLENINT ) ;
975
+ ArrayType * q ;
975
976
976
977
if ( ARRISNULL ( query ) ) return FALSE;
977
978
979
+ q = new_intArrayType ( SIGLENINT );
980
+
978
981
gensign ( SIGPTR ( q ),
979
982
ARRPTR ( query ),
980
983
ARRSIZE ( query ) );
@@ -1060,7 +1063,7 @@ _int_common_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result,
1060
1063
pfree ((char * )ud );
1061
1064
1062
1065
#ifdef GIST_DEBUG
1063
- elog (NOTICE , "--penalty\t%g" , * result );
1066
+ elog (NOTICE , "--penalty\t%g\t%g\t%g " , * result , tmp1 , tmp2 );
1064
1067
#endif
1065
1068
1066
1069
return (result );
@@ -1160,6 +1163,7 @@ _int_common_picksplit(bytea *entryvec,
1160
1163
*/
1161
1164
1162
1165
maxoff = OffsetNumberNext (maxoff );
1166
+
1163
1167
for (i = FirstOffsetNumber ; i <= maxoff ; i = OffsetNumberNext (i )) {
1164
1168
1165
1169
0 commit comments