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/parser/parse_utilcmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backend/parser/parse_utilcmd.c') diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index e2699592970..88fba239cdb 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -19,7 +19,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.10 2008/03/21 22:10:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.11 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -811,7 +811,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx, { char *exprsString; - exprsString = DatumGetCString(DirectFunctionCall1(textout, datum)); + exprsString = TextDatumGetCString(datum); indexprs = (List *) stringToNode(exprsString); } else @@ -904,7 +904,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx, char *pred_str; /* Convert text string to node tree */ - pred_str = DatumGetCString(DirectFunctionCall1(textout, datum)); + pred_str = TextDatumGetCString(datum); index->whereClause = (Node *) stringToNode(pred_str); /* Adjust attribute numbers */ change_varattnos_of_a_node(index->whereClause, attmap); -- cgit v1.2.3