From 220db7ccd8c88aafea4629f00e8be6f9f073ed00 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 25 Mar 2008 22:42:46 +0000 Subject: Simplify and standardize conversions between TEXT datums and ordinary C strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane --- src/backend/executor/functions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backend/executor/functions.c') diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index da6976b62f7..678b43927d7 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.121 2008/03/18 22:04:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.122 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -244,7 +244,7 @@ init_sql_fcache(FmgrInfo *finfo) &isNull); if (isNull) elog(ERROR, "null prosrc for function %u", foid); - fcache->src = DatumGetCString(DirectFunctionCall1(textout, tmp)); + fcache->src = TextDatumGetCString(tmp); /* * Parse and rewrite the queries in the function text. @@ -777,7 +777,7 @@ sql_exec_error_callback(void *arg) &isnull); if (isnull) elog(ERROR, "null prosrc"); - prosrc = DatumGetCString(DirectFunctionCall1(textout, tmp)); + prosrc = TextDatumGetCString(tmp); errposition(0); internalerrposition(syntaxerrposition); internalerrquery(prosrc); -- cgit v1.2.3