Whack btree_gist code around until it has some small hope of building

on non-gcc compilers.
This commit is contained in:
Tom Lane 2004-08-21 00:09:10 +00:00
parent bf9d9bd2f3
commit 86d78021a4
3 changed files with 41 additions and 41 deletions

View File

@ -65,13 +65,15 @@ static bytea *
gbt_text_xfrm ( bytea * leaf ) gbt_text_xfrm ( bytea * leaf )
{ {
bytea * out = leaf; bytea * out = leaf;
int32 ilen = VARSIZE (leaf) - VARHDRSZ; int32 ilen = VARSIZE (leaf) - VARHDRSZ;
int32 olen ; int32 olen ;
char sin[ilen+1]; char * sin;
char * sou = NULL; char * sou;
memcpy ( (void*)&sin[0], (void*) VARDATA(leaf) ,ilen );
sin = palloc(ilen + 1);
memcpy (sin, (void*) VARDATA(leaf) ,ilen );
sin[ilen] = '\0'; sin[ilen] = '\0';
olen = strxfrm ( NULL, &sin[0], 0 ) + 1; olen = strxfrm ( NULL, &sin[0], 0 ) + 1;
sou = palloc ( olen ); sou = palloc ( olen );
olen = strxfrm ( sou , &sin[0] , olen ); olen = strxfrm ( sou , &sin[0] , olen );
@ -80,7 +82,9 @@ gbt_text_xfrm ( bytea * leaf )
out->vl_len = olen+1; out->vl_len = olen+1;
memcpy( (void*) VARDATA(out), sou, olen-VARHDRSZ ); memcpy( (void*) VARDATA(out), sou, olen-VARHDRSZ );
((char*)out)[olen] = '\0'; ((char*)out)[olen] = '\0';
pfree(sou); pfree(sou);
pfree(sin);
return out; return out;
} }

View File

@ -200,19 +200,16 @@ gbt_num_consistent(
} }
GIST_SPLITVEC * GIST_SPLITVEC *
gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo * tinfo ) gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_ninfo * tinfo )
{ {
OffsetNumber i,
maxoff = entryvec->n - 1;
Nsrt *arr;
int nbytes;
OffsetNumber i , arr = (Nsrt *) palloc((maxoff+1) * sizeof(Nsrt));
maxoff = entryvec->n - 1;
Nsrt arr[maxoff+1] ;
int nbytes ;
nbytes = (maxoff + 2) * sizeof(OffsetNumber); nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes);
@ -248,7 +245,7 @@ gbt_num_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtr
} }
} }
pfree(arr);
return v; return v;
} }

View File

@ -416,36 +416,35 @@ gbt_var_penalty ( float * res , const GISTENTRY * o , const GISTENTRY * n, const
} }
static int32 gbt_vsrt_cmp ( const Vsrt * a , const Vsrt * b , const gbtree_vinfo * tinfo ) /*
* Fortunately, this sort comparsion routine needn't be reentrant...
*/
static const gbtree_vinfo * gbt_vsrt_cmp_tinfo;
static int
gbt_vsrt_cmp(const void *a, const void *b)
{ {
GBT_VARKEY_R ar = gbt_var_key_readable ( a->t ); GBT_VARKEY_R ar = gbt_var_key_readable ( ((const Vsrt *) a)->t );
GBT_VARKEY_R br = gbt_var_key_readable ( b->t ); GBT_VARKEY_R br = gbt_var_key_readable ( ((const Vsrt *) b)->t );
return (*tinfo->f_cmp) ( ar.lower, br.lower );
return (*gbt_vsrt_cmp_tinfo->f_cmp) ( ar.lower, br.lower );
} }
extern GIST_SPLITVEC * extern GIST_SPLITVEC *
gbt_var_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo * tinfo ) gbt_var_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo * tinfo )
{ {
OffsetNumber i,
OffsetNumber i , maxoff = entryvec->n - 1;
maxoff = entryvec->n - 1; Vsrt *arr;
Vsrt arr[maxoff+1] ;
int pfrcntr = 0 , int pfrcntr = 0 ,
svcntr = 0 , svcntr = 0 ,
nbytes ; nbytes ;
char * tst , char * tst ,
* cur ; * cur ;
char **pfr = NULL ; char **pfr = NULL ;
GBT_VARKEY **sv = NULL; GBT_VARKEY **sv = NULL;
static int cmp (const void *a, const void *b ){ arr = (Vsrt *) palloc((maxoff+1) * sizeof(Vsrt));
return gbt_vsrt_cmp ((Vsrt *) a , (Vsrt *) b , tinfo );
}
nbytes = (maxoff + 2) * sizeof(OffsetNumber); nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes);
@ -482,8 +481,11 @@ gbt_var_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtr
} }
/* sort */ /* sort */
qsort ( (void*) &arr[FirstOffsetNumber], maxoff-FirstOffsetNumber+1,sizeof(Vsrt), cmp ); gbt_vsrt_cmp_tinfo = tinfo;
qsort((void*) &arr[FirstOffsetNumber],
maxoff-FirstOffsetNumber+1,
sizeof(Vsrt),
gbt_vsrt_cmp);
/* We do simply create two parts */ /* We do simply create two parts */
@ -545,18 +547,15 @@ gbt_var_picksplit( const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtr
} }
return v; pfree(arr);
return v;
} }
/* /*
** The GiST consistent method * The GiST consistent method
*/ */
extern bool extern bool
gbt_var_consistent( gbt_var_consistent(
GBT_VARKEY_R * key, GBT_VARKEY_R * key,