summaryrefslogtreecommitdiff
path: root/src/backend/utils/fmgr
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-03-25 22:42:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-03-25 22:42:46 +0000
commit220db7ccd8c88aafea4629f00e8be6f9f073ed00 (patch)
tree772c9dca19736eb9d417cb665a281686c3570b4c /src/backend/utils/fmgr
parentf948197b4055bb0e22e508e9d6966217b7dbea3d (diff)
downloadpostgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.tar.gz
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/utils/fmgr')
-rw-r--r--src/backend/utils/fmgr/fmgr.c11
-rw-r--r--src/backend/utils/fmgr/funcapi.c10
2 files changed, 8 insertions, 13 deletions
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 19216b4381..e06da243ab 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.113 2008/01/03 21:23:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.114 2008/03/25 22:42:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -246,8 +246,7 @@ fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt,
Anum_pg_proc_prosrc, &isnull);
if (isnull)
elog(ERROR, "null prosrc");
- prosrc = DatumGetCString(DirectFunctionCall1(textout,
- prosrcdatum));
+ prosrc = TextDatumGetCString(prosrcdatum);
fbp = fmgr_lookupByName(prosrc);
if (fbp == NULL)
ereport(ERROR,
@@ -315,15 +314,13 @@ fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Anum_pg_proc_prosrc, &isnull);
if (isnull)
elog(ERROR, "null prosrc for function %u", functionId);
- prosrcstring = DatumGetCString(DirectFunctionCall1(textout,
- prosrcattr));
+ prosrcstring = TextDatumGetCString(prosrcattr);
probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
Anum_pg_proc_probin, &isnull);
if (isnull)
elog(ERROR, "null probin for function %u", functionId);
- probinstring = DatumGetCString(DirectFunctionCall1(textout,
- probinattr));
+ probinstring = TextDatumGetCString(probinattr);
/* Look up the function itself */
user_fn = load_external_function(probinstring, prosrcstring, true,
diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c
index 4bb230a3f3..42586f13aa 100644
--- a/src/backend/utils/fmgr/funcapi.c
+++ b/src/backend/utils/fmgr/funcapi.c
@@ -7,7 +7,7 @@
* Copyright (c) 2002-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.38 2008/02/29 02:49:39 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.39 2008/03/25 22:42:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -741,8 +741,7 @@ get_func_arg_info(HeapTuple procTup,
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
*p_argnames = (char **) palloc(sizeof(char *) * numargs);
for (i = 0; i < numargs; i++)
- (*p_argnames)[i] = DatumGetCString(DirectFunctionCall1(textout,
- elems[i]));
+ (*p_argnames)[i] = TextDatumGetCString(elems[i]);
}
/* Get argument modes, if available */
@@ -855,8 +854,7 @@ get_func_result_name(Oid functionId)
result = NULL;
break;
}
- result = DatumGetCString(DirectFunctionCall1(textout,
- argnames[i]));
+ result = TextDatumGetCString(argnames[i]);
if (result == NULL || result[0] == '\0')
{
/* Parameter is not named, so forget it */
@@ -1002,7 +1000,7 @@ build_function_result_tupdesc_d(Datum proallargtypes,
argmodes[i] == PROARGMODE_INOUT);
outargtypes[numoutargs] = argtypes[i];
if (argnames)
- pname = DatumGetCString(DirectFunctionCall1(textout, argnames[i]));
+ pname = TextDatumGetCString(argnames[i]);
else
pname = NULL;
if (pname == NULL || pname[0] == '\0')