diff -dcrpN --exclude=configure pgsql.orig/config/c-compiler.m4 pgsql/config/c-compiler.m4
*** pgsql.orig/config/c-compiler.m4	2008-02-18 13:49:56.000000000 +0100
--- pgsql/config/c-compiler.m4	2008-03-24 21:44:56.000000000 +0100
*************** AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_
*** 62,68 ****
  
  Ac_define=$Ac_cachevar
  if test x"$Ac_cachevar" = xyes ; then
!   AC_DEFINE(Ac_define,, [Define to 1 if `]$1[' works and is 64 bits.])
  fi
  undefine([Ac_define])dnl
  undefine([Ac_cachevar])dnl
--- 62,68 ----
  
  Ac_define=$Ac_cachevar
  if test x"$Ac_cachevar" = xyes ; then
!   AC_DEFINE(Ac_define, 1, [Define to 1 if `]$1[' works and is 64 bits.])
  fi
  undefine([Ac_define])dnl
  undefine([Ac_cachevar])dnl
diff -dcrpN --exclude=configure pgsql.orig/configure.in pgsql/configure.in
*** pgsql.orig/configure.in	2008-03-11 10:52:17.000000000 +0100
--- pgsql/configure.in	2008-03-25 08:51:17.000000000 +0100
*************** PGAC_TYPE_64BIT_INT([long int])
*** 1308,1313 ****
--- 1308,1316 ----
  
  if test x"$HAVE_LONG_INT_64" = x"no" ; then
    PGAC_TYPE_64BIT_INT([long long int])
+   AC_DEFINE(INT64PASSBYVALUE, false, [Define to false if INT8/FLOAT8/TIME[STAMP[TZ]] is passed by reference.])
+ else
+   AC_DEFINE(INT64PASSBYVALUE, true, [Define to true if INT8/FLOAT8/TIME[STAMP[TZ]] is passed by value.])
  fi
  
  
diff -dcrpN --exclude=configure pgsql.orig/src/backend/bootstrap/bootstrap.c pgsql/src/backend/bootstrap/bootstrap.c
*** pgsql.orig/src/backend/bootstrap/bootstrap.c	2008-02-18 13:50:00.000000000 +0100
--- pgsql/src/backend/bootstrap/bootstrap.c	2008-03-24 21:44:56.000000000 +0100
*************** static const struct typinfo TypInfo[] = 
*** 121,127 ****
  	F_INT2IN, F_INT2OUT},
  	{"int4", INT4OID, 0, 4, true, 'i', 'p',
  	F_INT4IN, F_INT4OUT},
! 	{"float4", FLOAT4OID, 0, 4, false, 'i', 'p',
  	F_FLOAT4IN, F_FLOAT4OUT},
  	{"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'i', 'p',
  	F_NAMEIN, F_NAMEOUT},
--- 121,127 ----
  	F_INT2IN, F_INT2OUT},
  	{"int4", INT4OID, 0, 4, true, 'i', 'p',
  	F_INT4IN, F_INT4OUT},
! 	{"float4", FLOAT4OID, 0, 4, true, 'i', 'p',
  	F_FLOAT4IN, F_FLOAT4OUT},
  	{"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'i', 'p',
  	F_NAMEIN, F_NAMEOUT},
diff -dcrpN --exclude=configure pgsql.orig/src/backend/catalog/genbki.sh pgsql/src/backend/catalog/genbki.sh
*** pgsql.orig/src/backend/catalog/genbki.sh	2008-01-01 20:45:48.000000000 +0100
--- pgsql/src/backend/catalog/genbki.sh	2008-03-24 22:12:59.000000000 +0100
*************** for dir in $INCLUDE_DIRS; do
*** 114,119 ****
--- 114,132 ----
      fi
  done
  
+ # Deduce INT64PASSBYVAL from pg_config.h / HAVE_LONG_INT_64
+ for dir in $INCLUDE_DIRS; do
+     if [ -f "$dir/pg_config.h" ]; then
+         REAL64MACH=`grep '^#define[    ]*HAVE_LONG_INT_64' $dir/pg_config.h | $AWK '{ print $3 }'`
+         break
+     fi
+ done
+ if [ "$REAL64MACH" == "1" ]; then
+     INT64PASSBYVAL="t"
+ else
+     INT64PASSBYVAL="f"
+ fi
+ 
  # Get BOOTSTRAP_SUPERUSERID from catalog/pg_authid.h
  for dir in $INCLUDE_DIRS; do
      if [ -f "$dir/catalog/pg_authid.h" ]; then
*************** sed -e "s/;[ 	]*$//g" \
*** 164,169 ****
--- 177,183 ----
      -e "s/(TransactionId/(xid/g" \
      -e "s/PGUID/$BOOTSTRAP_SUPERUSERID/g" \
      -e "s/NAMEDATALEN/$NAMEDATALEN/g" \
+     -e "s/INT64PASSBYVAL/$INT64PASSBYVAL/g" \
      -e "s/PGNSP/$PG_CATALOG_NAMESPACE/g" \
  | $AWK '
  # ----------------
diff -dcrpN --exclude=configure pgsql.orig/src/backend/commands/analyze.c pgsql/src/backend/commands/analyze.c
*** pgsql.orig/src/backend/commands/analyze.c	2008-03-02 13:44:44.000000000 +0100
--- pgsql/src/backend/commands/analyze.c	2008-03-24 21:44:56.000000000 +0100
*************** update_attstats(Oid relid, int natts, Va
*** 1223,1229 ****
  				/* XXX knows more than it should about type float4: */
  				arry = construct_array(numdatums, nnum,
  									   FLOAT4OID,
! 									   sizeof(float4), false, 'i');
  				values[i++] = PointerGetDatum(arry);	/* stanumbersN */
  			}
  			else
--- 1223,1229 ----
  				/* XXX knows more than it should about type float4: */
  				arry = construct_array(numdatums, nnum,
  									   FLOAT4OID,
! 									   sizeof(float4), true, 'i');
  				values[i++] = PointerGetDatum(arry);	/* stanumbersN */
  			}
  			else
diff -dcrpN --exclude=configure pgsql.orig/src/backend/optimizer/plan/planagg.c pgsql/src/backend/optimizer/plan/planagg.c
*** pgsql.orig/src/backend/optimizer/plan/planagg.c	2008-01-01 20:45:50.000000000 +0100
--- pgsql/src/backend/optimizer/plan/planagg.c	2008-03-25 01:23:16.000000000 +0100
*************** make_agg_subplan(PlannerInfo *root, MinM
*** 503,509 ****
  	subparse->limitOffset = NULL;
  	subparse->limitCount = (Node *) makeConst(INT8OID, -1, sizeof(int64),
  											  Int64GetDatum(1),
! 											  false, false /* not by val */ );
  
  	/*
  	 * Generate the plan for the subquery.	We already have a Path for the
--- 503,509 ----
  	subparse->limitOffset = NULL;
  	subparse->limitCount = (Node *) makeConst(INT8OID, -1, sizeof(int64),
  											  Int64GetDatum(1),
! 											  false, INT64PASSBYVALUE );
  
  	/*
  	 * Generate the plan for the subquery.	We already have a Path for the
diff -dcrpN --exclude=configure pgsql.orig/src/backend/parser/parse_node.c pgsql/src/backend/parser/parse_node.c
*** pgsql.orig/src/backend/parser/parse_node.c	2008-01-01 20:45:51.000000000 +0100
--- pgsql/src/backend/parser/parse_node.c	2008-03-25 01:48:21.000000000 +0100
*************** make_const(Value *value)
*** 375,381 ****
  
  					typeid = INT8OID;
  					typelen = sizeof(int64);
! 					typebyval = false;	/* XXX might change someday */
  				}
  			}
  			else
--- 375,381 ----
  
  					typeid = INT8OID;
  					typelen = sizeof(int64);
! 					typebyval = INT64PASSBYVALUE;
  				}
  			}
  			else
diff -dcrpN --exclude=configure pgsql.orig/src/backend/utils/adt/float.c pgsql/src/backend/utils/adt/float.c
*** pgsql.orig/src/backend/utils/adt/float.c	2008-03-11 10:52:20.000000000 +0100
--- pgsql/src/backend/utils/adt/float.c	2008-03-25 01:25:40.000000000 +0100
*************** float8_accum(PG_FUNCTION_ARGS)
*** 1780,1786 ****
  
  		result = construct_array(transdatums, 3,
  								 FLOAT8OID,
! 							 sizeof(float8), false /* float8 byval */ , 'd');
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
--- 1780,1786 ----
  
  		result = construct_array(transdatums, 3,
  								 FLOAT8OID,
! 							 sizeof(float8), INT64PASSBYVALUE , 'd'); /* INT64PASSBYVALUE is used for FLOAT8, too */
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
*************** float4_accum(PG_FUNCTION_ARGS)
*** 1833,1839 ****
  
  		result = construct_array(transdatums, 3,
  								 FLOAT8OID,
! 							 sizeof(float8), false /* float8 byval */ , 'd');
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
--- 1833,1839 ----
  
  		result = construct_array(transdatums, 3,
  								 FLOAT8OID,
! 							 sizeof(float8), INT64PASSBYVALUE, 'd'); /* INT64PASSBYVALUE is used for FLOAT8, too */
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
*************** float8_regr_accum(PG_FUNCTION_ARGS)
*** 2057,2063 ****
  		result = construct_array(transdatums, 6,
  								 FLOAT8OID,
  								 sizeof(float8),
! 								 false /* float8 byval */ , 'd');
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
--- 2057,2063 ----
  		result = construct_array(transdatums, 6,
  								 FLOAT8OID,
  								 sizeof(float8),
! 								 INT64PASSBYVALUE, 'd'); /* INT64PASSBYVALUE is used for FLOAT8, too */
  
  		PG_RETURN_ARRAYTYPE_P(result);
  	}
diff -dcrpN --exclude=configure pgsql.orig/src/backend/utils/adt/int8.c pgsql/src/backend/utils/adt/int8.c
*** pgsql.orig/src/backend/utils/adt/int8.c	2008-01-01 20:45:52.000000000 +0100
--- pgsql/src/backend/utils/adt/int8.c	2008-03-24 21:44:56.000000000 +0100
*************** int8mod(PG_FUNCTION_ARGS)
*** 657,662 ****
--- 657,663 ----
  Datum
  int8inc(PG_FUNCTION_ARGS)
  {
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		/*
*************** int8inc(PG_FUNCTION_ARGS)
*** 682,687 ****
--- 683,689 ----
  		PG_RETURN_POINTER(arg);
  	}
  	else
+ #endif
  	{
  		/* Not called by nodeAgg, so just do it the dumb way */
  		int64		arg = PG_GETARG_INT64(0);
diff -dcrpN --exclude=configure pgsql.orig/src/backend/utils/adt/numeric.c pgsql/src/backend/utils/adt/numeric.c
*** pgsql.orig/src/backend/utils/adt/numeric.c	2008-01-01 20:45:52.000000000 +0100
--- pgsql/src/backend/utils/adt/numeric.c	2008-03-24 21:44:56.000000000 +0100
*************** int2_sum(PG_FUNCTION_ARGS)
*** 2550,2556 ****
--- 2550,2560 ----
  	 * If we're invoked by nodeAgg, we can cheat and modify out first
  	 * parameter in-place to avoid palloc overhead. If not, we need to return
  	 * the new value of the transition variable.
+ 	 * If we're on a 64-bit machine (HAVE_LONG_INT_64 == 1) then int64
+ 	 * is passed-by-value, there's no palloc overhead and the code below
+ 	 * becomes harmful.
  	 */
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		int64	   *oldsum = (int64 *) PG_GETARG_POINTER(0);
*************** int2_sum(PG_FUNCTION_ARGS)
*** 2562,2567 ****
--- 2566,2572 ----
  		PG_RETURN_POINTER(oldsum);
  	}
  	else
+ #endif
  	{
  		int64		oldsum = PG_GETARG_INT64(0);
  
*************** int4_sum(PG_FUNCTION_ARGS)
*** 2595,2601 ****
--- 2600,2610 ----
  	 * If we're invoked by nodeAgg, we can cheat and modify out first
  	 * parameter in-place to avoid palloc overhead. If not, we need to return
  	 * the new value of the transition variable.
+ 	 * If we're on a 64-bit machine (HAVE_LONG_INT_64 == 1) then int64
+ 	 * is passed-by-value, there's no palloc overhead and the code below
+ 	 * becomes harmful.
  	 */
+ #ifndef HAVE_LONG_INT_64
  	if (fcinfo->context && IsA(fcinfo->context, AggState))
  	{
  		int64	   *oldsum = (int64 *) PG_GETARG_POINTER(0);
*************** int4_sum(PG_FUNCTION_ARGS)
*** 2607,2612 ****
--- 2616,2622 ----
  		PG_RETURN_POINTER(oldsum);
  	}
  	else
+ #endif
  	{
  		int64		oldsum = PG_GETARG_INT64(0);
  
diff -dcrpN --exclude=configure pgsql.orig/src/backend/utils/fmgr/fmgr.c pgsql/src/backend/utils/fmgr/fmgr.c
*** pgsql.orig/src/backend/utils/fmgr/fmgr.c	2008-01-03 22:23:15.000000000 +0100
--- pgsql/src/backend/utils/fmgr/fmgr.c	2008-03-24 21:44:56.000000000 +0100
*************** fmgr(Oid procedureId,...)
*** 2037,2042 ****
--- 2037,2043 ----
   *-------------------------------------------------------------------------
   */
  
+ #ifndef HAVE_LONG_INT_64
  Datum
  Int64GetDatum(int64 X)
  {
*************** Int64GetDatum(int64 X)
*** 2059,2083 ****
  	return PointerGetDatum(retval);
  #endif   /* INT64_IS_BUSTED */
  }
  
  Datum
  Float4GetDatum(float4 X)
  {
! 	float4	   *retval = (float4 *) palloc(sizeof(float4));
  
! 	*retval = X;
! 	return PointerGetDatum(retval);
  }
  
  Datum
  Float8GetDatum(float8 X)
  {
  	float8	   *retval = (float8 *) palloc(sizeof(float8));
  
  	*retval = X;
  	return PointerGetDatum(retval);
  }
  
  /*-------------------------------------------------------------------------
   *		Support routines for toastable datatypes
   *-------------------------------------------------------------------------
--- 2060,2124 ----
  	return PointerGetDatum(retval);
  #endif   /* INT64_IS_BUSTED */
  }
+ #endif
  
  Datum
  Float4GetDatum(float4 X)
  {
! 	union {
! 		float4	value;
! 		int32	retval;
! 	} myunion;
  
! 	myunion.value = X;
! 	return myunion.retval;
! }
! 
! float4
! DatumGetFloat4(Datum X)
! {
! 	union {
! 		int32	value;
! 		float4	retval;
! 	} myunion;
! 
! 	myunion.value = GET_4_BYTES(X);
! 	return myunion.retval;
  }
  
  Datum
  Float8GetDatum(float8 X)
  {
+ #ifndef HAVE_LONG_INT_64
  	float8	   *retval = (float8 *) palloc(sizeof(float8));
  
  	*retval = X;
  	return PointerGetDatum(retval);
+ #else
+ 	union {
+ 		float8	value;
+ 		int64	retval;
+ 	} myunion;
+ 
+ 	myunion.value = X;
+ 	return myunion.retval;
+ #endif
  }
  
+ #ifdef HAVE_LONG_INT_64
+ float8
+ DatumGetFloat8(Datum X)
+ {
+ 	union {
+ 		int64	value;
+ 		float8	retval;
+ 	} myunion;
+ 
+ 	myunion.value = GET_8_BYTES(X);
+ 	return myunion.retval;
+ }
+ #endif
+ 
  /*-------------------------------------------------------------------------
   *		Support routines for toastable datatypes
   *-------------------------------------------------------------------------
diff -dcrpN --exclude=configure pgsql.orig/src/include/catalog/pg_attribute.h pgsql/src/include/catalog/pg_attribute.h
*** pgsql.orig/src/include/catalog/pg_attribute.h	2008-01-01 20:45:56.000000000 +0100
--- pgsql/src/include/catalog/pg_attribute.h	2008-03-24 21:44:56.000000000 +0100
*************** DATA(insert ( 1247 tableoid			26 0  4  -
*** 292,299 ****
  { 1255, {"pronamespace"},		26, -1, 4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"proowner"},			26, -1, 4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"prolang"},			26, -1, 4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
! { 1255, {"procost"},		   700, -1, 4,	5, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
! { 1255, {"prorows"},		   700, -1, 4,	6, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"proisagg"},			16, -1, 1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
  { 1255, {"prosecdef"},			16, -1, 1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
  { 1255, {"proisstrict"},		16, -1, 1,	9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
--- 292,299 ----
  { 1255, {"pronamespace"},		26, -1, 4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"proowner"},			26, -1, 4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"prolang"},			26, -1, 4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
! { 1255, {"procost"},		   700, -1, 4,	5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
! { 1255, {"prorows"},		   700, -1, 4,	6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1255, {"proisagg"},			16, -1, 1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
  { 1255, {"prosecdef"},			16, -1, 1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
  { 1255, {"proisstrict"},		16, -1, 1,	9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
*************** DATA(insert ( 1255 proname			19 -1 NAMED
*** 314,321 ****
  DATA(insert ( 1255 pronamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1255 proowner			26 -1 4   3 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1255 prolang			26 -1 4   4 0 -1 -1 t p i t f f t 0));
! DATA(insert ( 1255 procost		   700 -1 4   5 0 -1 -1 f p i t f f t 0));
! DATA(insert ( 1255 prorows		   700 -1 4   6 0 -1 -1 f p i t f f t 0));
  DATA(insert ( 1255 proisagg			16 -1 1   7 0 -1 -1 t p c t f f t 0));
  DATA(insert ( 1255 prosecdef		16 -1 1   8 0 -1 -1 t p c t f f t 0));
  DATA(insert ( 1255 proisstrict		16 -1 1   9 0 -1 -1 t p c t f f t 0));
--- 314,321 ----
  DATA(insert ( 1255 pronamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1255 proowner			26 -1 4   3 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1255 prolang			26 -1 4   4 0 -1 -1 t p i t f f t 0));
! DATA(insert ( 1255 procost		   700 -1 4   5 0 -1 -1 t p i t f f t 0));
! DATA(insert ( 1255 prorows		   700 -1 4   6 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1255 proisagg			16 -1 1   7 0 -1 -1 t p c t f f t 0));
  DATA(insert ( 1255 prosecdef		16 -1 1   8 0 -1 -1 t p c t f f t 0));
  DATA(insert ( 1255 proisstrict		16 -1 1   9 0 -1 -1 t p c t f f t 0));
*************** DATA(insert ( 1249 tableoid			26 0  4  -
*** 400,406 ****
  { 1259, {"relfilenode"},   26, -1,	4,	6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltablespace"}, 26, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"relpages"},	   23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
! { 1259, {"reltuples"},	   700, -1, 4,	9, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltoastrelid"}, 26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltoastidxid"}, 26, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"relhasindex"},   16, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
--- 400,406 ----
  { 1259, {"relfilenode"},   26, -1,	4,	6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltablespace"}, 26, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"relpages"},	   23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
! { 1259, {"reltuples"},	   700, -1, 4,	9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltoastrelid"}, 26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"reltoastidxid"}, 26, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
  { 1259, {"relhasindex"},   16, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
*************** DATA(insert ( 1259 relam			26 -1 4   5 0
*** 428,434 ****
  DATA(insert ( 1259 relfilenode		26 -1 4   6 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 reltablespace	26 -1 4   7 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 relpages			23 -1 4   8 0 -1 -1 t p i t f f t 0));
! DATA(insert ( 1259 reltuples	   700 -1 4   9 0 -1 -1 f p i t f f t 0));
  DATA(insert ( 1259 reltoastrelid	26 -1 4  10 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 reltoastidxid	26 -1 4  11 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 relhasindex		16 -1 1  12 0 -1 -1 t p c t f f t 0));
--- 428,434 ----
  DATA(insert ( 1259 relfilenode		26 -1 4   6 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 reltablespace	26 -1 4   7 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 relpages			23 -1 4   8 0 -1 -1 t p i t f f t 0));
! DATA(insert ( 1259 reltuples	   700 -1 4   9 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 reltoastrelid	26 -1 4  10 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 reltoastidxid	26 -1 4  11 0 -1 -1 t p i t f f t 0));
  DATA(insert ( 1259 relhasindex		16 -1 1  12 0 -1 -1 t p c t f f t 0));
diff -dcrpN --exclude=configure pgsql.orig/src/include/catalog/pg_type.h pgsql/src/include/catalog/pg_type.h
*** pgsql.orig/src/include/catalog/pg_type.h	2008-03-20 21:46:09.000000000 +0100
--- pgsql/src/include/catalog/pg_type.h	2008-03-24 22:03:28.000000000 +0100
*************** DATA(insert OID = 19 (	name	   PGNSP PGU
*** 278,284 ****
  DESCR("63-character type for storing system identifiers");
  #define NAMEOID			19
  
! DATA(insert OID = 20 (	int8	   PGNSP PGUID	8 f b t \054 0	 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("~18 digit integer, 8-byte storage");
  #define INT8OID			20
  
--- 278,284 ----
  DESCR("63-character type for storing system identifiers");
  #define NAMEOID			19
  
! DATA(insert OID = 20 (	int8	   PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("~18 digit integer, 8-byte storage");
  #define INT8OID			20
  
*************** DESCR("");
*** 375,384 ****
  
  /* OIDS 700 - 799 */
  
! DATA(insert OID = 700 (  float4    PGNSP PGUID	4 f b t \054 0	 0 1021 float4in float4out float4recv float4send - - - i p f 0 -1 0 _null_ _null_ ));
  DESCR("single-precision floating point number, 4-byte storage");
  #define FLOAT4OID 700
! DATA(insert OID = 701 (  float8    PGNSP PGUID	8 f b t \054 0	 0 1022 float8in float8out float8recv float8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("double-precision floating point number, 8-byte storage");
  #define FLOAT8OID 701
  DATA(insert OID = 702 (  abstime   PGNSP PGUID	4 t b t \054 0	 0 1023 abstimein abstimeout abstimerecv abstimesend - - - i p f 0 -1 0 _null_ _null_ ));
--- 375,384 ----
  
  /* OIDS 700 - 799 */
  
! DATA(insert OID = 700 (  float4    PGNSP PGUID	4 t b t \054 0	 0 1021 float4in float4out float4recv float4send - - - i p f 0 -1 0 _null_ _null_ ));
  DESCR("single-precision floating point number, 4-byte storage");
  #define FLOAT4OID 700
! DATA(insert OID = 701 (  float8    PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	 0 1022 float8in float8out float8recv float8send - - - d p f 0 -1 0 _null_ _null_ ));
  DESCR("double-precision floating point number, 8-byte storage");
  #define FLOAT8OID 701
  DATA(insert OID = 702 (  abstime   PGNSP PGUID	4 t b t \054 0	 0 1023 abstimein abstimeout abstimerecv abstimesend - - - i p f 0 -1 0 _null_ _null_ ));
*************** DESCR("varchar(length), non-blank-padded
*** 466,483 ****
  DATA(insert OID = 1082 ( date		 PGNSP PGUID	4 t b t \054 0	0 1182 date_in date_out date_recv date_send - - - i p f 0 -1 0 _null_ _null_ ));
  DESCR("ANSI SQL date");
  #define DATEOID			1082
! DATA(insert OID = 1083 ( time		 PGNSP PGUID	8 f b t \054 0	0 1183 time_in time_out time_recv time_send timetypmodin timetypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("hh:mm:ss, ANSI SQL time");
  #define TIMEOID			1083
  
  /* OIDS 1100 - 1199 */
! DATA(insert OID = 1114 ( timestamp	 PGNSP PGUID	8 f b t \054 0	0 1115 timestamp_in timestamp_out timestamp_recv timestamp_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("date and time");
  #define TIMESTAMPOID	1114
  DATA(insert OID = 1115 ( _timestamp  PGNSP PGUID	-1 f b t \054 0 1114 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout - d x f 0 -1 0 _null_ _null_ ));
  DATA(insert OID = 1182 ( _date		 PGNSP PGUID	-1 f b t \054 0 1082 0 array_in array_out array_recv array_send - - - i x f 0 -1 0 _null_ _null_ ));
  DATA(insert OID = 1183 ( _time		 PGNSP PGUID	-1 f b t \054 0 1083 0 array_in array_out array_recv array_send timetypmodin timetypmodout - d x f 0 -1 0 _null_ _null_ ));
! DATA(insert OID = 1184 ( timestamptz PGNSP PGUID	8 f b t \054 0	0 1185 timestamptz_in timestamptz_out timestamptz_recv timestamptz_send timestamptztypmodin timestamptztypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("date and time with time zone");
  #define TIMESTAMPTZOID	1184
  DATA(insert OID = 1185 ( _timestamptz PGNSP PGUID -1 f b t \054 0	1184 0 array_in array_out array_recv array_send timestamptztypmodin timestamptztypmodout - d x f 0 -1 0 _null_ _null_ ));
--- 466,483 ----
  DATA(insert OID = 1082 ( date		 PGNSP PGUID	4 t b t \054 0	0 1182 date_in date_out date_recv date_send - - - i p f 0 -1 0 _null_ _null_ ));
  DESCR("ANSI SQL date");
  #define DATEOID			1082
! DATA(insert OID = 1083 ( time		 PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	0 1183 time_in time_out time_recv time_send timetypmodin timetypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("hh:mm:ss, ANSI SQL time");
  #define TIMEOID			1083
  
  /* OIDS 1100 - 1199 */
! DATA(insert OID = 1114 ( timestamp	 PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	0 1115 timestamp_in timestamp_out timestamp_recv timestamp_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("date and time");
  #define TIMESTAMPOID	1114
  DATA(insert OID = 1115 ( _timestamp  PGNSP PGUID	-1 f b t \054 0 1114 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout - d x f 0 -1 0 _null_ _null_ ));
  DATA(insert OID = 1182 ( _date		 PGNSP PGUID	-1 f b t \054 0 1082 0 array_in array_out array_recv array_send - - - i x f 0 -1 0 _null_ _null_ ));
  DATA(insert OID = 1183 ( _time		 PGNSP PGUID	-1 f b t \054 0 1083 0 array_in array_out array_recv array_send timetypmodin timetypmodout - d x f 0 -1 0 _null_ _null_ ));
! DATA(insert OID = 1184 ( timestamptz PGNSP PGUID	8 INT64PASSBYVAL b t \054 0	0 1185 timestamptz_in timestamptz_out timestamptz_recv timestamptz_send timestamptztypmodin timestamptztypmodout - d p f 0 -1 0 _null_ _null_ ));
  DESCR("date and time with time zone");
  #define TIMESTAMPTZOID	1184
  DATA(insert OID = 1185 ( _timestamptz PGNSP PGUID -1 f b t \054 0	1184 0 array_in array_out array_recv array_send timestamptztypmodin timestamptztypmodout - d x f 0 -1 0 _null_ _null_ ));
diff -dcrpN --exclude=configure pgsql.orig/src/include/pg_config.h.in pgsql/src/include/pg_config.h.in
*** pgsql.orig/src/include/pg_config.h.in	2008-03-11 10:52:21.000000000 +0100
--- pgsql/src/include/pg_config.h.in	2008-03-25 08:51:26.000000000 +0100
***************
*** 589,594 ****
--- 589,597 ----
  /* Define to 1 if you have the <winldap.h> header file. */
  #undef HAVE_WINLDAP_H
  
+ /* Define to true if INT8/FLOAT8/TIME[STAMP[TZ]] is passed by value. */
+ #undef INT64PASSBYVALUE
+ 
  /* Define to the appropriate snprintf format for 64-bit ints, if any. */
  #undef INT64_FORMAT
  
diff -dcrpN --exclude=configure pgsql.orig/src/include/postgres.h pgsql/src/include/postgres.h
*** pgsql.orig/src/include/postgres.h	2008-01-01 20:45:56.000000000 +0100
--- pgsql/src/include/postgres.h	2008-03-25 08:47:14.000000000 +0100
*************** typedef Datum *DatumPtr;
*** 315,323 ****
--- 315,333 ----
  #define GET_1_BYTE(datum)	(((Datum) (datum)) & 0x000000ff)
  #define GET_2_BYTES(datum)	(((Datum) (datum)) & 0x0000ffff)
  #define GET_4_BYTES(datum)	(((Datum) (datum)) & 0xffffffff)
+ #ifdef HAVE_LONG_INT_64
+ #define GET_8_BYTES(datum)	((Datum) (datum))
+ #else
+ #define GET_8_BYTES(datum)	(DatumGetInt64(datum))
+ #endif
  #define SET_1_BYTE(value)	(((Datum) (value)) & 0x000000ff)
  #define SET_2_BYTES(value)	(((Datum) (value)) & 0x0000ffff)
  #define SET_4_BYTES(value)	(((Datum) (value)) & 0xffffffff)
+ #ifdef HAVE_LONG_INT_64
+ #define SET_8_BYTES(value)	((Datum) (value))
+ #else
+ #define SET_8_BYTES(value)	(Int64GetDatum(value))
+ #endif
  
  /*
   * DatumGetBool
*************** typedef Datum *DatumPtr;
*** 533,564 ****
   * at least on some platforms.
   */
  
  #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
  
  /*
   * Int64GetDatum
   *		Returns datum representation for a 64-bit integer.
   *
!  * Note: this routine returns a reference to palloc'd space.
   */
  
  extern Datum Int64GetDatum(int64 X);
  
  /*
   * DatumGetFloat4
   *		Returns 4-byte floating point value of a datum.
-  *
-  * Note: this macro hides the fact that float4 is currently a
-  * pass-by-reference type.	Someday it may be pass-by-value.
   */
  
! #define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
  
  /*
   * Float4GetDatum
   *		Returns datum representation for a 4-byte floating point number.
-  *
-  * Note: this routine returns a reference to palloc'd space.
   */
  
  extern Datum Float4GetDatum(float4 X);
--- 543,578 ----
   * at least on some platforms.
   */
  
+ #ifndef HAVE_LONG_INT_64
  #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
+ #else
+ #define DatumGetInt64(X) ((int64) GET_8_BYTES(X))
+ #endif
  
  /*
   * Int64GetDatum
   *		Returns datum representation for a 64-bit integer.
   *
!  * Note: this routine returns a reference to palloc'd space
!  *       on non-native 64-bit machines
   */
  
+ #ifndef HAVE_LONG_INT_64
  extern Datum Int64GetDatum(int64 X);
+ #else
+ #define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
+ #endif
  
  /*
   * DatumGetFloat4
   *		Returns 4-byte floating point value of a datum.
   */
  
! extern float4 DatumGetFloat4(Datum X);
  
  /*
   * Float4GetDatum
   *		Returns datum representation for a 4-byte floating point number.
   */
  
  extern Datum Float4GetDatum(float4 X);
*************** extern Datum Float4GetDatum(float4 X);
*** 572,578 ****
--- 586,596 ----
   * at least on some platforms.
   */
  
+ #ifndef HAVE_LONG_INT_64
  #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
+ #else
+ extern float8 DatumGetFloat8(Datum X);
+ #endif
  
  /*
   * Float8GetDatum
*************** extern Datum Float8GetDatum(float8 X);
*** 585,636 ****
  
  
  /*
-  * DatumGetFloat32
-  *		Returns 32-bit floating point value of a datum.
-  *		This is really a pointer, of course.
-  *
-  * XXX: this macro is now deprecated in favor of DatumGetFloat4.
-  * It will eventually go away.
-  */
- 
- #define DatumGetFloat32(X) ((float32) DatumGetPointer(X))
- 
- /*
-  * Float32GetDatum
-  *		Returns datum representation for a 32-bit floating point number.
-  *		This is really a pointer, of course.
-  *
-  * XXX: this macro is now deprecated in favor of Float4GetDatum.
-  * It will eventually go away.
-  */
- 
- #define Float32GetDatum(X) PointerGetDatum(X)
- 
- /*
-  * DatumGetFloat64
-  *		Returns 64-bit floating point value of a datum.
-  *		This is really a pointer, of course.
-  *
-  * XXX: this macro is now deprecated in favor of DatumGetFloat8.
-  * It will eventually go away.
-  */
- 
- #define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
- 
- /*
-  * Float64GetDatum
-  *		Returns datum representation for a 64-bit floating point number.
-  *		This is really a pointer, of course.
-  *
-  * XXX: this macro is now deprecated in favor of Float8GetDatum.
-  * It will eventually go away.
-  */
- 
- #define Float64GetDatum(X) PointerGetDatum(X)
- 
- /*
   * Int64GetDatumFast
-  * Float4GetDatumFast
   * Float8GetDatumFast
   *
   * These macros are intended to allow writing code that does not depend on
--- 603,609 ----
*************** extern Datum Float8GetDatum(float8 X);
*** 642,650 ****
   * macros.
   */
  
  #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
- #define Float4GetDatumFast(X) PointerGetDatum(&(X))
  #define Float8GetDatumFast(X) PointerGetDatum(&(X))
  
  
  /* ----------------------------------------------------------------
--- 615,627 ----
   * macros.
   */
  
+ #ifndef HAVE_LONG_INT_64
  #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
  #define Float8GetDatumFast(X) PointerGetDatum(&(X))
+ #else
+ #define Int64GetDatumFast(X)  Int64GetDatum(X)
+ #define Float8GetDatumFast(X) Float8GetDatum(X)
+ #endif
  
  
  /* ----------------------------------------------------------------
diff -dcrpN --exclude=configure pgsql.orig/src/test/regress/expected/type_sanity.out pgsql/src/test/regress/expected/type_sanity.out
*** pgsql.orig/src/test/regress/expected/type_sanity.out	2007-10-14 00:33:38.000000000 +0200
--- pgsql/src/test/regress/expected/type_sanity.out	2008-03-24 22:08:14.000000000 +0100
*************** FROM pg_type as p1
*** 31,37 ****
  WHERE p1.typbyval AND
      (p1.typlen != 1 OR p1.typalign != 'c') AND
      (p1.typlen != 2 OR p1.typalign != 's') AND
!     (p1.typlen != 4 OR p1.typalign != 'i');
   oid | typname 
  -----+---------
  (0 rows)
--- 31,38 ----
  WHERE p1.typbyval AND
      (p1.typlen != 1 OR p1.typalign != 'c') AND
      (p1.typlen != 2 OR p1.typalign != 's') AND
!     (p1.typlen != 4 OR p1.typalign != 'i') AND
!     (p1.typlen != 8 OR p1.typalign != 'd');
   oid | typname 
  -----+---------
  (0 rows)
diff -dcrpN --exclude=configure pgsql.orig/src/test/regress/sql/type_sanity.sql pgsql/src/test/regress/sql/type_sanity.sql
*** pgsql.orig/src/test/regress/sql/type_sanity.sql	2007-10-14 00:33:37.000000000 +0200
--- pgsql/src/test/regress/sql/type_sanity.sql	2008-03-24 22:06:46.000000000 +0100
*************** FROM pg_type as p1
*** 32,38 ****
  WHERE p1.typbyval AND
      (p1.typlen != 1 OR p1.typalign != 'c') AND
      (p1.typlen != 2 OR p1.typalign != 's') AND
!     (p1.typlen != 4 OR p1.typalign != 'i');
  
  -- Look for "toastable" types that aren't varlena.
  
--- 32,39 ----
  WHERE p1.typbyval AND
      (p1.typlen != 1 OR p1.typalign != 'c') AND
      (p1.typlen != 2 OR p1.typalign != 's') AND
!     (p1.typlen != 4 OR p1.typalign != 'i') AND
!     (p1.typlen != 8 OR p1.typalign != 'd');
  
  -- Look for "toastable" types that aren't varlena.
  
diff -dcrpN --exclude=configure pgsql.orig/src/tools/msvc/Genbki.pm pgsql/src/tools/msvc/Genbki.pm
*** pgsql.orig/src/tools/msvc/Genbki.pm	2008-01-01 20:46:01.000000000 +0100
--- pgsql/src/tools/msvc/Genbki.pm	2008-03-25 15:49:21.000000000 +0100
*************** sub genbki
*** 38,43 ****
--- 38,49 ----
        || die "Could not read NAMEDATALEN from pg_config_manual.h\n";
      my $namedatalen = $1;
  
+     my $pgconf = read_file("src/include/pg_config.h");
+     $pgconf =~ /^#define\s+HAVE_LONG_INT_64\s+(\d+)$/mg
+       || die "Could not read HAVE_LONG_INT_64 from pg_config.h\n";
+     my $real64 = $1;
+     my $int64passbyval = $real64 ? 't' : 'f';
+ 
      my $pgauthid = read_file("src/include/catalog/pg_authid.h");
      $pgauthid =~ /^#define\s+BOOTSTRAP_SUPERUSERID\s+(\d+)$/mg
        || die "Could not read BOOTSTRAUP_SUPERUSERID from pg_authid.h\n";
*************** sub genbki
*** 71,76 ****
--- 77,83 ----
      $indata =~ s{\(TransactionId}{(xid}g;
      $indata =~ s{PGUID}{$bootstrapsuperuserid}g;
      $indata =~ s{NAMEDATALEN}{$namedatalen}g;
+     $indata =~ s{INT64PASSBYVAL}{$int64passbyval}g;
      $indata =~ s{PGNSP}{$pgcatalognamespace}g;
  
      #print $indata;
