From 81e11f2d056c7966ce6ae54f41026434e2eb3b28 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 14 Nov 2008 02:09:52 +0000
Subject: [PATCH] Actually, instead of whining about how type internal might
 not safely store a pointer, why don't we just fix that.  Every known use of
 "internal" really means a pointer anyway.

---
 src/backend/utils/adt/array_userfuncs.c | 14 +++++---------
 src/bin/initdb/initdb.c                 |  8 +++++++-
 src/include/catalog/catversion.h        |  4 ++--
 src/include/catalog/pg_type.h           |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 6f18c664059..4c147f0021d 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -6,7 +6,7 @@
  * Copyright (c) 2003-2008, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.25 2008/11/14 00:12:08 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.26 2008/11/14 02:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -495,14 +495,10 @@ array_agg_transfn(PG_FUNCTION_ARGS)
 							 ((AggState *) fcinfo->context)->aggcontext);
 
 	/*
-	 * We cheat quite a lot here by assuming that a pointer datum will be
-	 * preserved intact when nodeAgg.c thinks it is a value of type "internal".
-	 * This will in fact work because internal is stated to be pass-by-value
-	 * in pg_type.h, and nodeAgg will never do anything with a pass-by-value
-	 * transvalue except pass it around in Datum form.  But it's mighty
-	 * shaky seeing that internal is also stated to be 4 bytes wide in
-	 * pg_type.h.  If nodeAgg did put the value into a tuple this would
-	 * crash and burn on 64-bit machines.
+	 * The transition type for array_agg() is declared to be "internal",
+	 * which is a pass-by-value type the same size as a pointer.  So we
+	 * can safely pass the ArrayBuildState pointer through nodeAgg.c's
+	 * machinations.
 	 */
 	PG_RETURN_POINTER(state);
 }
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 0bf3a443686..04c29bec59e 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -42,7 +42,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  * Portions taken from FreeBSD.
  *
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.163 2008/10/31 07:15:11 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.164 2008/11/14 02:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1331,6 +1331,12 @@ bootstrap_template1(char *short_version)
 	sprintf(buf, "%d", NAMEDATALEN);
 	bki_lines = replace_token(bki_lines, "NAMEDATALEN", buf);
 
+	sprintf(buf, "%d", (int) sizeof(Pointer));
+	bki_lines = replace_token(bki_lines, "SIZEOF_POINTER", buf);
+
+	bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
+							  (sizeof(Pointer) == 4) ? "i" : "d");
+
 	bki_lines = replace_token(bki_lines, "FLOAT4PASSBYVAL",
 							  FLOAT4PASSBYVAL ? "true" : "false");
 
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index dd1bfbaf45f..f156b1c36da 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.506 2008/11/14 00:51:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.507 2008/11/14 02:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*							yyyymmddN */
-#define CATALOG_VERSION_NO	200811132
+#define CATALOG_VERSION_NO	200811133
 
 #endif
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index f3367b41b59..45c89630f65 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.201 2008/10/13 16:25:20 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.202 2008/11/14 02:09:52 tgl Exp $
  *
  * NOTES
  *	  the genbki.sh script reads this file and generates .bki
@@ -613,7 +613,7 @@ DATA(insert OID = 2279 ( trigger		PGNSP PGUID  4 t p P f t \054 0 0 0 trigger_in
 #define TRIGGEROID		2279
 DATA(insert OID = 2280 ( language_handler	PGNSP PGUID  4 t p P f t \054 0 0 0 language_handler_in language_handler_out - - - - - i p f 0 -1 0 _null_ _null_ ));
 #define LANGUAGE_HANDLEROID		2280
-DATA(insert OID = 2281 ( internal		PGNSP PGUID  4 t p P f t \054 0 0 0 internal_in internal_out - - - - - i p f 0 -1 0 _null_ _null_ ));
+DATA(insert OID = 2281 ( internal		PGNSP PGUID  SIZEOF_POINTER t p P f t \054 0 0 0 internal_in internal_out - - - - - ALIGNOF_POINTER p f 0 -1 0 _null_ _null_ ));
 #define INTERNALOID		2281
 DATA(insert OID = 2282 ( opaque			PGNSP PGUID  4 t p P f t \054 0 0 0 opaque_in opaque_out - - - - - i p f 0 -1 0 _null_ _null_ ));
 #define OPAQUEOID		2282
-- 
GitLab