diff -dcrpN pgsql-float4-float8-int64-byval/src/backend/utils/adt/tsquery_gist.c pgsql-float4-float8-int64-byval-tsearch-fixup/src/backend/utils/adt/tsquery_gist.c
*** pgsql-float4-float8-int64-byval/src/backend/utils/adt/tsquery_gist.c	2008-01-01 20:45:53.000000000 +0100
--- pgsql-float4-float8-int64-byval-tsearch-fixup/src/backend/utils/adt/tsquery_gist.c	2008-03-31 11:28:03.000000000 +0200
***************
*** 19,25 ****
  #include "tsearch/ts_type.h"
  #include "tsearch/ts_utils.h"
  
! #define GETENTRY(vec,pos) ((TSQuerySign *) DatumGetPointer((vec)->vector[(pos)].key))
  
  Datum
  gtsquery_compress(PG_FUNCTION_ARGS)
--- 19,25 ----
  #include "tsearch/ts_type.h"
  #include "tsearch/ts_utils.h"
  
! #define GETENTRY(vec,pos) (DatumGetTSQuerySign((vec)->vector[(pos)].key))
  
  Datum
  gtsquery_compress(PG_FUNCTION_ARGS)
*************** gtsquery_compress(PG_FUNCTION_ARGS)
*** 29,40 ****
  
  	if (entry->leafkey)
  	{
! 		TSQuerySign *sign = (TSQuerySign *) palloc(sizeof(TSQuerySign));
  
  		retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
! 		*sign = makeTSQuerySign(DatumGetTSQuery(entry->key));
  
! 		gistentryinit(*retval, PointerGetDatum(sign),
  					  entry->rel, entry->page,
  					  entry->offset, FALSE);
  	}
--- 29,40 ----
  
  	if (entry->leafkey)
  	{
! 		TSQuerySign sign;
  
  		retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
! 		sign = makeTSQuerySign(DatumGetTSQuery(entry->key));
  
! 		gistentryinit(*retval, TSQuerySignGetDatum(sign),
  					  entry->rel, entry->page,
  					  entry->offset, FALSE);
  	}
*************** Datum
*** 52,58 ****
  gtsquery_consistent(PG_FUNCTION_ARGS)
  {
  	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
! 	TSQuerySign *key = (TSQuerySign *) DatumGetPointer(entry->key);
  	TSQuery		query = PG_GETARG_TSQUERY(1);
  	StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
  	TSQuerySign sq = makeTSQuerySign(query);
--- 52,58 ----
  gtsquery_consistent(PG_FUNCTION_ARGS)
  {
  	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
! 	TSQuerySign	key = DatumGetTSQuerySign(entry->key);
  	TSQuery		query = PG_GETARG_TSQUERY(1);
  	StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
  	TSQuerySign sq = makeTSQuerySign(query);
*************** gtsquery_consistent(PG_FUNCTION_ARGS)
*** 62,76 ****
  	{
  		case RTContainsStrategyNumber:
  			if (GIST_LEAF(entry))
! 				retval = (*key & sq) == sq;
  			else
! 				retval = (*key & sq) != 0;
  			break;
  		case RTContainedByStrategyNumber:
  			if (GIST_LEAF(entry))
! 				retval = (*key & sq) == *key;
  			else
! 				retval = (*key & sq) != 0;
  			break;
  		default:
  			retval = FALSE;
--- 62,76 ----
  	{
  		case RTContainsStrategyNumber:
  			if (GIST_LEAF(entry))
! 				retval = (key & sq) == sq;
  			else
! 				retval = (key & sq) != 0;
  			break;
  		case RTContainedByStrategyNumber:
  			if (GIST_LEAF(entry))
! 				retval = (key & sq) == key;
  			else
! 				retval = (key & sq) != 0;
  			break;
  		default:
  			retval = FALSE;
*************** gtsquery_union(PG_FUNCTION_ARGS)
*** 83,108 ****
  {
  	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
  	int		   *size = (int *) PG_GETARG_POINTER(1);
! 	TSQuerySign *sign = (TSQuerySign *) palloc(sizeof(TSQuerySign));
  	int			i;
  
! 	memset(sign, 0, sizeof(TSQuerySign));
  
  	for (i = 0; i < entryvec->n; i++)
! 		*sign |= *GETENTRY(entryvec, i);
  
  	*size = sizeof(TSQuerySign);
  
! 	PG_RETURN_POINTER(sign);
  }
  
  Datum
  gtsquery_same(PG_FUNCTION_ARGS)
  {
! 	TSQuerySign *a = (TSQuerySign *) PG_GETARG_POINTER(0);
! 	TSQuerySign *b = (TSQuerySign *) PG_GETARG_POINTER(1);
  
! 	PG_RETURN_POINTER(*a == *b);
  }
  
  static int
--- 83,108 ----
  {
  	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
  	int		   *size = (int *) PG_GETARG_POINTER(1);
! 	TSQuerySign		sign;
  	int			i;
  
! 	sign = 0;
  
  	for (i = 0; i < entryvec->n; i++)
! 		sign |= GETENTRY(entryvec, i);
  
  	*size = sizeof(TSQuerySign);
  
! 	PG_RETURN_TSQUERYSIGN(sign);
  }
  
  Datum
  gtsquery_same(PG_FUNCTION_ARGS)
  {
! 	TSQuerySign a = PG_GETARG_TSQUERYSIGN(0);
! 	TSQuerySign b = PG_GETARG_TSQUERYSIGN(1);
  
! 	PG_RETURN_POINTER(a == b); /* shouldn't it be PG_RETURN_BOOL(a == b) for clarity? */
  }
  
  static int
*************** hemdist(TSQuerySign a, TSQuerySign b)
*** 128,138 ****
  Datum
  gtsquery_penalty(PG_FUNCTION_ARGS)
  {
! 	TSQuerySign *origval = (TSQuerySign *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
! 	TSQuerySign *newval = (TSQuerySign *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
  	float	   *penalty = (float *) PG_GETARG_POINTER(2);
  
! 	*penalty = hemdist(*origval, *newval);
  
  	PG_RETURN_POINTER(penalty);
  }
--- 128,138 ----
  Datum
  gtsquery_penalty(PG_FUNCTION_ARGS)
  {
! 	TSQuerySign origval = DatumGetTSQuerySign(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
! 	TSQuerySign newval  = DatumGetTSQuerySign(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
  	float	   *penalty = (float *) PG_GETARG_POINTER(2);
  
! 	*penalty = hemdist(origval, newval);
  
  	PG_RETURN_POINTER(penalty);
  }
*************** gtsquery_picksplit(PG_FUNCTION_ARGS)
*** 164,171 ****
  	OffsetNumber k,
  				j;
  
! 	TSQuerySign *datum_l,
! 			   *datum_r;
  	int4		size_alpha,
  				size_beta;
  	int4		size_waste,
--- 164,171 ----
  	OffsetNumber k,
  				j;
  
! 	TSQuerySign datum_l,
! 			   datum_r;
  	int4		size_alpha,
  				size_beta;
  	int4		size_waste,
*************** gtsquery_picksplit(PG_FUNCTION_ARGS)
*** 186,192 ****
  	for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
  		for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
  		{
! 			size_waste = hemdist(*GETENTRY(entryvec, j), *GETENTRY(entryvec, k));
  			if (size_waste > waste)
  			{
  				waste = size_waste;
--- 186,192 ----
  	for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
  		for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
  		{
! 			size_waste = hemdist(GETENTRY(entryvec, j), GETENTRY(entryvec, k));
  			if (size_waste > waste)
  			{
  				waste = size_waste;
*************** gtsquery_picksplit(PG_FUNCTION_ARGS)
*** 202,211 ****
  		seed_2 = 2;
  	}
  
! 	datum_l = (TSQuerySign *) palloc(sizeof(TSQuerySign));
! 	*datum_l = *GETENTRY(entryvec, seed_1);
! 	datum_r = (TSQuerySign *) palloc(sizeof(TSQuerySign));
! 	*datum_r = *GETENTRY(entryvec, seed_2);
  
  
  	maxoff = OffsetNumberNext(maxoff);
--- 202,209 ----
  		seed_2 = 2;
  	}
  
! 	datum_l = GETENTRY(entryvec, seed_1);
! 	datum_r = GETENTRY(entryvec, seed_2);
  
  
  	maxoff = OffsetNumberNext(maxoff);
*************** gtsquery_picksplit(PG_FUNCTION_ARGS)
*** 213,220 ****
  	for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
  	{
  		costvector[j - 1].pos = j;
! 		size_alpha = hemdist(*GETENTRY(entryvec, seed_1), *GETENTRY(entryvec, j));
! 		size_beta = hemdist(*GETENTRY(entryvec, seed_2), *GETENTRY(entryvec, j));
  		costvector[j - 1].cost = abs(size_alpha - size_beta);
  	}
  	qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
--- 211,218 ----
  	for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
  	{
  		costvector[j - 1].pos = j;
! 		size_alpha = hemdist(GETENTRY(entryvec, seed_1), GETENTRY(entryvec, j));
! 		size_beta = hemdist(GETENTRY(entryvec, seed_2), GETENTRY(entryvec, j));
  		costvector[j - 1].cost = abs(size_alpha - size_beta);
  	}
  	qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
*************** gtsquery_picksplit(PG_FUNCTION_ARGS)
*** 234,259 ****
  			v->spl_nright++;
  			continue;
  		}
! 		size_alpha = hemdist(*datum_l, *GETENTRY(entryvec, j));
! 		size_beta = hemdist(*datum_r, *GETENTRY(entryvec, j));
  
  		if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.05))
  		{
! 			*datum_l |= *GETENTRY(entryvec, j);
  			*left++ = j;
  			v->spl_nleft++;
  		}
  		else
  		{
! 			*datum_r |= *GETENTRY(entryvec, j);
  			*right++ = j;
  			v->spl_nright++;
  		}
  	}
  
  	*right = *left = FirstOffsetNumber;
! 	v->spl_ldatum = PointerGetDatum(datum_l);
! 	v->spl_rdatum = PointerGetDatum(datum_r);
  
  	PG_RETURN_POINTER(v);
  }
--- 232,257 ----
  			v->spl_nright++;
  			continue;
  		}
! 		size_alpha = hemdist(datum_l, GETENTRY(entryvec, j));
! 		size_beta = hemdist(datum_r, GETENTRY(entryvec, j));
  
  		if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.05))
  		{
! 			datum_l |= GETENTRY(entryvec, j);
  			*left++ = j;
  			v->spl_nleft++;
  		}
  		else
  		{
! 			datum_r |= GETENTRY(entryvec, j);
  			*right++ = j;
  			v->spl_nright++;
  		}
  	}
  
  	*right = *left = FirstOffsetNumber;
! 	v->spl_ldatum = TSQuerySignGetDatum(datum_l);
! 	v->spl_rdatum = TSQuerySignGetDatum(datum_r);
  
  	PG_RETURN_POINTER(v);
  }
diff -dcrpN pgsql-float4-float8-int64-byval/src/include/tsearch/ts_utils.h pgsql-float4-float8-int64-byval-tsearch-fixup/src/include/tsearch/ts_utils.h
*** pgsql-float4-float8-int64-byval/src/include/tsearch/ts_utils.h	2008-03-26 10:15:19.000000000 +0100
--- pgsql-float4-float8-int64-byval-tsearch-fixup/src/include/tsearch/ts_utils.h	2008-03-31 11:19:18.000000000 +0200
*************** typedef uint64 TSQuerySign;
*** 178,183 ****
--- 178,188 ----
  
  #define TSQS_SIGLEN  (sizeof(TSQuerySign)*BITS_PER_BYTE)
  
+ #define TSQuerySignGetDatum(X)		(Int64GetDatum((int64) (X)))
+ #define DatumGetTSQuerySign(X)		((TSQuerySign) DatumGetInt64(X))
+ #define PG_RETURN_TSQUERYSIGN(X)	return TSQuerySignGetDatum(X)
+ #define PG_GETARG_TSQUERYSIGN(n)	(DatumGetTSQuerySign(PG_GETARG_DATUM(n)))
+ 
  
  extern QTNode *QT2QTN(QueryItem *in, char *operand);
  extern TSQuery QTN2QT(QTNode *in);
