summaryrefslogtreecommitdiff
path: root/contrib/intarray
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 /contrib/intarray
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 'contrib/intarray')
-rw-r--r--contrib/intarray/_int_bool.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 2344d0b50b..ef9430901d 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -765,9 +765,7 @@ querytree(PG_FUNCTION_ARGS)
if (len == 0)
{
- res = (text *) palloc(1 + VARHDRSZ);
- SET_VARSIZE(res, 1 + VARHDRSZ);
- *((char *) VARDATA(res)) = 'T';
+ res = cstring_to_text("T");
}
else
{
@@ -776,12 +774,9 @@ querytree(PG_FUNCTION_ARGS)
nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
*(nrm.cur) = '\0';
infix(&nrm, true);
-
- res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
- SET_VARSIZE(res, nrm.cur - nrm.buf + VARHDRSZ);
- memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
+ res = cstring_to_text_with_len(nrm.buf, nrm.cur - nrm.buf);
}
pfree(q);
- PG_RETURN_POINTER(res);
+ PG_RETURN_TEXT_P(res);
}