diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-25 22:42:46 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-03-25 22:42:46 +0000 |
commit | 220db7ccd8c88aafea4629f00e8be6f9f073ed00 (patch) | |
tree | 772c9dca19736eb9d417cb665a281686c3570b4c /src/backend/executor | |
parent | f948197b4055bb0e22e508e9d6966217b7dbea3d (diff) | |
download | postgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.tar.gz postgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.zip |
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
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execCurrent.c | 5 | ||||
-rw-r--r-- | src/backend/executor/execQual.c | 10 | ||||
-rw-r--r-- | src/backend/executor/functions.c | 6 | ||||
-rw-r--r-- | src/backend/executor/nodeAgg.c | 4 |
4 files changed, 9 insertions, 16 deletions
diff --git a/src/backend/executor/execCurrent.c b/src/backend/executor/execCurrent.c index 3523ac7ae90..f775092896d 100644 --- a/src/backend/executor/execCurrent.c +++ b/src/backend/executor/execCurrent.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/executor/execCurrent.c,v 1.5 2008/01/01 19:45:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execCurrent.c,v 1.6 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -150,8 +150,7 @@ fetch_param_value(ExprContext *econtext, int paramId) { Assert(prm->ptype == REFCURSOROID); /* We know that refcursor uses text's I/O routines */ - return DatumGetCString(DirectFunctionCall1(textout, - prm->value)); + return TextDatumGetCString(prm->value); } } diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index 97d22dc2cd3..d142796815b 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.227 2008/03/25 19:26:53 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.228 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3039,13 +3039,7 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext, if (*isNull) result = NULL; else - { - int len = buf.len + VARHDRSZ; - - result = palloc(len); - SET_VARSIZE(result, len); - memcpy(VARDATA(result), buf.data, buf.len); - } + result = cstring_to_text_with_len(buf.data, buf.len); pfree(buf.data); return PointerGetDatum(result); 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); diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 0fac11a5371..8ddcf868699 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -61,7 +61,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.156 2008/01/11 18:39:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.157 2008/03/25 22:42:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1549,7 +1549,7 @@ GetAggInitVal(Datum textInitVal, Oid transtype) Datum initVal; getTypeInputInfo(transtype, &typinput, &typioparam); - strInitVal = DatumGetCString(DirectFunctionCall1(textout, textInitVal)); + strInitVal = TextDatumGetCString(textInitVal); initVal = OidInputFunctionCall(typinput, strInitVal, typioparam, -1); pfree(strInitVal); |