public inbox for [email protected]help / color / mirror / Atom feed
Cleanup: Use modern macro for text-to-CString conversion in plsample.c 4+ messages / 2 participants [nested] [flat]
* Cleanup: Use modern macro for text-to-CString conversion in plsample.c @ 2026-04-17 12:54 Amul Sul <[email protected]> 2026-04-20 12:20 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Fujii Masao <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Amul Sul @ 2026-04-17 12:54 UTC (permalink / raw) To: PostgreSQL Hackers <[email protected]> Hi, I noticed that plsample.c uses an outdated method to convert text data to a C string. This old method calls the textout function manually, which adds unnecessary overhead. The attached patch replaces this with the TextDatumGetCString() macro. This macro is more efficient and automatically handles "detoasting" (decompressing/fetching) the data. Since plsample serves as a template for developers writing new extensions, it should follow current best practices. This patch updates the code in both the function and trigger handlers. -- Regards, Amul Sul EDB: http://www.enterprisedb.com Attachments: [application/x-patch] 0001-plsample-Use-TextDatumGetCString-for-text-to-CString.patch (1.8K, 2-0001-plsample-Use-TextDatumGetCString-for-text-to-CString.patch) download | inline diff: From 3290c94d6839c1e0e25f2b6f55291b9d0d266327 Mon Sep 17 00:00:00 2001 From: Amul Sul <[email protected]> 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 ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c 2026-04-17 12:54 Cleanup: Use modern macro for text-to-CString conversion in plsample.c Amul Sul <[email protected]> @ 2026-04-20 12:20 ` Fujii Masao <[email protected]> 2026-04-20 23:41 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Fujii Masao <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Fujii Masao @ 2026-04-20 12:20 UTC (permalink / raw) To: Amul Sul <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> On Fri, Apr 17, 2026 at 9:55 PM Amul Sul <[email protected]> wrote: > > Hi, > > I noticed that plsample.c uses an outdated method to convert text data > to a C string. This old method calls the textout function manually, > which adds unnecessary overhead. > > The attached patch replaces this with the TextDatumGetCString() macro. > This macro is more efficient and automatically handles "detoasting" > (decompressing/fetching) the data. > > Since plsample serves as a template for developers writing new > extensions, it should follow current best practices. This patch > updates the code in both the function and trigger handlers. LGTM. Regards, -- Fujii Masao ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c 2026-04-17 12:54 Cleanup: Use modern macro for text-to-CString conversion in plsample.c Amul Sul <[email protected]> 2026-04-20 12:20 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Fujii Masao <[email protected]> @ 2026-04-20 23:41 ` Fujii Masao <[email protected]> 2026-04-21 03:57 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Amul Sul <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Fujii Masao @ 2026-04-20 23:41 UTC (permalink / raw) To: Amul Sul <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> On Mon, Apr 20, 2026 at 9:20 PM Fujii Masao <[email protected]> wrote: > LGTM. I've pushed the patch. Thanks! Regards, -- Fujii Masao ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c 2026-04-17 12:54 Cleanup: Use modern macro for text-to-CString conversion in plsample.c Amul Sul <[email protected]> 2026-04-20 12:20 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Fujii Masao <[email protected]> 2026-04-20 23:41 ` Re: Cleanup: Use modern macro for text-to-CString conversion in plsample.c Fujii Masao <[email protected]> @ 2026-04-21 03:57 ` Amul Sul <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Amul Sul @ 2026-04-21 03:57 UTC (permalink / raw) To: Fujii Masao <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> On Tue, Apr 21, 2026 at 5:11 AM Fujii Masao <[email protected]> wrote: > > On Mon, Apr 20, 2026 at 9:20 PM Fujii Masao <[email protected]> wrote: > > LGTM. > > I've pushed the patch. Thanks! > Thank you, Fujii-san. Regards, Amul ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-04-21 03:57 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-04-17 12:54 Cleanup: Use modern macro for text-to-CString conversion in plsample.c Amul Sul <[email protected]> 2026-04-20 12:20 ` Fujii Masao <[email protected]> 2026-04-20 23:41 ` Fujii Masao <[email protected]> 2026-04-21 03:57 ` Amul Sul <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox