]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
plsample: Use TextDatumGetCString() for text-to-CString conversion
authorFujii Masao <fujii@postgresql.org>
Mon, 20 Apr 2026 23:37:17 +0000 (08:37 +0900)
committerFujii Masao <fujii@postgresql.org>
Mon, 20 Apr 2026 23:37:17 +0000 (08:37 +0900)
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.

Author: Amul Sul <sulamul@gmail.com>
Discussion: https://postgr.es/m/CAAJ_b95-xMvUN1PEqxv8y6g-A-8k+fSgyv20kSZc9eF1wZAUPg@mail.gmail.com

src/test/modules/plsample/plsample.c

index 29248bd70eb60b29ed0c259539db01dffed90731..f294f5ca4ad0f637f523cb98b696ca35e1c16e0b 100644 (file)
@@ -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)));