Subject: [PATCH v15 1/3] Modernize coding in GIN pageinspect functions.

From: reshke <[email-masked]>
Date: Wed, 7 Jan 2026 19:38:52 +0000

This patch switches palloc to our newly preferred palloc_array and modernizes
ereport calls, switching from list-style to polymorphic ereport
calls. This patch also fixes whitespace/tab issues, enforcing a single style.
across existing ginfuncs.c code.

Inspired by Peter Eisentraut's patch in the thread.

Reviewed-by: Andrey Borodin <[email-masked]>
Reviewed-by: Chao Li <[email-masked]>
Reviewed-by: Japin Li <[email-masked]>

Discussion: https://postgr.es/m/CALdSSPiN13n7feQcY0WCmq8jzxjwqhNrt1E=g=[email-masked]
---
 contrib/pageinspect/ginfuncs.c | 58 +++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index ebcc2b3db5c..b7bd7a3f4cd 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -38,8 +38,8 @@ gin_metapage_info(PG_FUNCTION_ARGS)
 
 	if (!superuser())
 		ereport(ERROR,
-				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-				 errmsg("must be superuser to use raw page functions")));
+				errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+				errmsg("must be superuser to use raw page functions"));
 
 	page = get_page_from_raw(raw_page);
 
@@ -48,20 +48,20 @@ gin_metapage_info(PG_FUNCTION_ARGS)
 
 	if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("input page is not a valid GIN metapage"),
-				 errdetail("Expected special size %d, got %d.",
-						   (int) MAXALIGN(sizeof(GinPageOpaqueData)),
-						   (int) PageGetSpecialSize(page))));
+				errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("input page is not a valid GIN metapage"),
+				errdetail("Expected special size %d, got %d.",
+						  (int) MAXALIGN(sizeof(GinPageOpaqueData)),
+						  (int) PageGetSpecialSize(page)));
 
 	opaq = GinPageGetOpaque(page);
 
 	if (opaq->flags != GIN_META)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("input page is not a GIN metapage"),
-				 errdetail("Flags %04X, expected %04X",
-						   opaq->flags, GIN_META)));
+				errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("input page is not a GIN metapage"),
+				errdetail("Flags %04X, expected %04X",
+						  opaq->flags, GIN_META));
 
 	/* Build a tuple descriptor for our result type */
 	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
@@ -118,11 +118,11 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
 
 	if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-				 errmsg("input page is not a valid GIN data leaf page"),
-				 errdetail("Expected special size %d, got %d.",
-						   (int) MAXALIGN(sizeof(GinPageOpaqueData)),
-						   (int) PageGetSpecialSize(page))));
+				errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("input page is not a valid GIN data leaf page"),
+				errdetail("Expected special size %d, got %d.",
+						  (int) MAXALIGN(sizeof(GinPageOpaqueData)),
+						  (int) PageGetSpecialSize(page)));
 
 	opaq = GinPageGetOpaque(page);
 
@@ -184,8 +184,8 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
 
 	if (!superuser())
 		ereport(ERROR,
-				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-				 errmsg("must be superuser to use raw page functions")));
+				errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+				errmsg("must be superuser to use raw page functions"));
 
 	if (SRF_IS_FIRSTCALL())
 	{
@@ -207,20 +207,20 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
 
 		if (PageGetSpecialSize(page) != MAXALIGN(sizeof(GinPageOpaqueData)))
 			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-					 errmsg("input page is not a valid GIN data leaf page"),
-					 errdetail("Expected special size %d, got %d.",
-							   (int) MAXALIGN(sizeof(GinPageOpaqueData)),
-							   (int) PageGetSpecialSize(page))));
+					errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					errmsg("input page is not a valid GIN data leaf page"),
+					errdetail("Expected special size %d, got %d.",
+							  (int) MAXALIGN(sizeof(GinPageOpaqueData)),
+							  (int) PageGetSpecialSize(page)));
 
 		opaq = GinPageGetOpaque(page);
 		if (opaq->flags != (GIN_DATA | GIN_LEAF | GIN_COMPRESSED))
 			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-					 errmsg("input page is not a compressed GIN data leaf page"),
-					 errdetail("Flags %04X, expected %04X",
-							   opaq->flags,
-							   (GIN_DATA | GIN_LEAF | GIN_COMPRESSED))));
+					errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					errmsg("input page is not a compressed GIN data leaf page"),
+					errdetail("Flags %04X, expected %04X",
+							  opaq->flags,
+							  (GIN_DATA | GIN_LEAF | GIN_COMPRESSED)));
 
 		inter_call_data = palloc_object(gin_leafpage_items_state);
 
@@ -262,7 +262,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
 
 		/* build an array of decoded item pointers */
 		tids = ginPostingListDecode(cur, &ndecoded);
-		tids_datum = (Datum *) palloc(ndecoded * sizeof(Datum));
+		tids_datum = palloc_array(Datum, ndecoded);
 		for (i = 0; i < ndecoded; i++)
 			tids_datum[i] = ItemPointerGetDatum(&tids[i]);
 		values[2] = PointerGetDatum(construct_array_builtin(tids_datum, ndecoded, TIDOID));
-- 
2.43.0

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=v15-0002-GIN-pageinspect-support-for-entry-tree-and-posti.patch