Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 31b5c05

Browse files
committed
Restore include-file updates, and fix some of the more glaring macro
sloppiness (insufficient parenthesization, etc). It still fails regress test for me, however.
1 parent 8f82141 commit 31b5c05

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

contrib/intarray/_int.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
format for these routines is dictated by Postgres architecture.
55
******************************************************************************/
66

7-
#include <stdio.h>
7+
#include "postgres.h"
8+
89
#include <float.h>
9-
#include <string.h>
1010

11-
#include "postgres.h"
1211
#include "access/gist.h"
1312
#include "access/itup.h"
1413
#include "access/rtree.h"
@@ -22,7 +21,7 @@
2221

2322
#define max(a,b) ((a) > (b) ? (a) : (b))
2423
#define min(a,b) ((a) <= (b) ? (a) : (b))
25-
#define abs(a) ((a) < (0) ? (-a) : (a))
24+
#define abs(a) ((a) < (0) ? -(a) : (a))
2625

2726
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
2827
#ifdef PGSQL71
@@ -53,7 +52,7 @@ typedef char* BITVECP;
5352

5453
#define NULLIFY(a) MemSet( a, 0, sizeof( BITVEC ) )
5554
#define NEWSIG(a) \
56-
a=(BITVECP) malloc( sizeof( BITVEC );\
55+
a=(BITVECP) malloc( sizeof( BITVEC ) );\
5756
NULLIFY(a);
5857

5958
#define LOOPBYTE(a) \
@@ -66,10 +65,11 @@ typedef char* BITVECP;
6665
a;\
6766
}
6867

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 )
7373

7474
#define union_sig(a,b,r) LOOPBYTE(r[i] = a[i] | b[i])
7575
#define inter_sig(a,b,r) LOOPBYTE(r[i] = a[i] & b[i])
@@ -97,7 +97,7 @@ static void printbitvec( BITVEC bv ) {
9797
int i;
9898
char str[ SIGLENBIT+1 ];
9999
str[ SIGLENBIT ] ='\0';
100-
LOOPBIT( str[i] = ( getbit(bv,i) ) ? '1' : '0' );
100+
LOOPBIT( str[i] = ( GETBIT(bv,i) ) ? '1' : '0' );
101101

102102
elog(NOTICE,"BV: %s", str);
103103
}
@@ -727,7 +727,7 @@ gensign(BITVEC sign, int * a, int len) {
727727
int i;
728728
NULLIFY(sign);
729729
for(i=0; i<len; i++) {
730-
setbit( sign, *a%SIGLENBIT );
730+
SETBIT( sign, (*a)%SIGLENBIT );
731731
a++;
732732
}
733733
}
@@ -770,7 +770,7 @@ rt__intbig_size(ArrayType *a, float* sz) {
770770
}
771771

772772
bv = SIGPTR(a);
773-
LOOPBIT( len += getbit(bv, i) );
773+
LOOPBIT( len += GETBIT(bv, i) );
774774
*sz = (float) len;
775775
return;
776776
}
@@ -780,8 +780,9 @@ _intbig_union(ArrayType *a, ArrayType *b) {
780780
ArrayType * r = NULL;
781781
BITVECP da, db, dr;
782782
int i;
783-
783+
784784
if ( ARRISNULL( a ) && ARRISNULL( b ) ) return new_intArrayType(0);
785+
785786
if ( ARRISNULL( a ) ) {
786787
r = copy_intArrayType( b );
787788
return r;
@@ -876,7 +877,7 @@ g_intbig_compress(GISTENTRY *entry) {
876877
gensign( SIGPTR( r ),
877878
ARRPTR ( in ),
878879
ARRSIZE( in ) );
879-
880+
880881
gistentryinit(*retval, (char *)r, entry->rel, entry->page, entry->offset, VARSIZE( r ), FALSE);
881882

882883
#ifdef PGSQL71
@@ -971,10 +972,12 @@ g_intbig_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result){
971972
bool
972973
g_intbig_consistent(GISTENTRY *entry, ArrayType *query, StrategyNumber strategy) {
973974
bool retval;
974-
ArrayType * q = new_intArrayType( SIGLENINT );
975+
ArrayType * q;
975976

976977
if ( ARRISNULL( query ) ) return FALSE;
977978

979+
q = new_intArrayType( SIGLENINT );
980+
978981
gensign( SIGPTR( q ),
979982
ARRPTR( query ),
980983
ARRSIZE( query ) );
@@ -1060,7 +1063,7 @@ _int_common_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result,
10601063
pfree((char *)ud);
10611064

10621065
#ifdef GIST_DEBUG
1063-
elog(NOTICE, "--penalty\t%g", *result);
1066+
elog(NOTICE, "--penalty\t%g\t%g\t%g", *result, tmp1, tmp2);
10641067
#endif
10651068

10661069
return(result);
@@ -1160,6 +1163,7 @@ _int_common_picksplit(bytea *entryvec,
11601163
*/
11611164

11621165
maxoff = OffsetNumberNext(maxoff);
1166+
11631167
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
11641168

11651169

0 commit comments

Comments
 (0)