0001-plsample-Use-TextDatumGetCString-for-text-to-CString.patch

application/x-patch

Filename: 0001-plsample-Use-TextDatumGetCString-for-text-to-CString.patch
Type: application/x-patch
Part: 0
Message: Cleanup: Use modern macro for text-to-CString conversion in plsample.c

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0001
Subject: plsample: Use TextDatumGetCString() for text-to-CString conversion.
File+
src/test/modules/plsample/plsample.c 3 2
From 3290c94d6839c1e0e25f2b6f55291b9d0d266327 Mon Sep 17 00:00:00 2001
From: Amul Sul <sulamul@gmail.com>
Date: Fri, 17 Apr 2026 18:12:41 +0530
Subject: [PATCH] plsample: Use TextDatumGetCString() for text-to-CString
 conversion.

Replace the outdated DatumGetCString(DirectFunctionCall1(textout, ...))
pattern with TextDatumGetCString(). The macro is the modern, more
efficient way to convert a text Datum to a C string as it avoids
unnecessary function call machinery and handles detoasting internally.

Since plsample serves as reference code for extension authors, it
should follow current idiomatic practices.
---
 src/test/modules/plsample/plsample.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/test/modules/plsample/plsample.c b/src/test/modules/plsample/plsample.c
index 29248bd70eb..f294f5ca4ad 100644
--- a/src/test/modules/plsample/plsample.c
+++ b/src/test/modules/plsample/plsample.c
@@ -21,6 +21,7 @@
 #include "commands/trigger.h"
 #include "executor/spi.h"
 #include "funcapi.h"
+#include "utils/builtins.h"
 #include "utils/fmgrprotos.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
@@ -128,7 +129,7 @@ plsample_func_handler(PG_FUNCTION_ARGS)
 	if (isnull)
 		elog(ERROR, "could not find source text of function \"%s\"",
 			 proname);
-	source = DatumGetCString(DirectFunctionCall1(textout, ret));
+	source = TextDatumGetCString(ret);
 	ereport(NOTICE,
 			(errmsg("source text of function \"%s\": %s",
 					proname, source)));
@@ -244,7 +245,7 @@ plsample_trigger_handler(PG_FUNCTION_ARGS)
 	if (isnull)
 		elog(ERROR, "could not find source text of function \"%s\"",
 			 proname);
-	source = DatumGetCString(DirectFunctionCall1(textout, ret));
+	source = TextDatumGetCString(ret);
 	ereport(NOTICE,
 			(errmsg("source text of function \"%s\": %s",
 					proname, source)));
-- 
2.47.1