diff options
| author | Tom Lane | 2008-03-25 22:42:46 +0000 |
|---|---|---|
| committer | Tom Lane | 2008-03-25 22:42:46 +0000 |
| commit | 220db7ccd8c88aafea4629f00e8be6f9f073ed00 (patch) | |
| tree | 772c9dca19736eb9d417cb665a281686c3570b4c /contrib/tsearch2/tsearch2.c | |
| parent | f948197b4055bb0e22e508e9d6966217b7dbea3d (diff) | |
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/tsearch2/tsearch2.c')
| -rw-r--r-- | contrib/tsearch2/tsearch2.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/contrib/tsearch2/tsearch2.c b/contrib/tsearch2/tsearch2.c index 9dc5eb3bdbf..7754f574026 100644 --- a/contrib/tsearch2/tsearch2.c +++ b/contrib/tsearch2/tsearch2.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.5 2008/01/01 19:45:45 momjian Exp $ + * $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.6 2008/03/25 22:42:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,14 +41,9 @@ static Oid current_parser_oid = InvalidOid; fcinfo->nargs++; \ } while (0) -#define TextPGetCString(t) \ - DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(t))) -#define CStringGetTextP(c) \ - DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(c))) - #define TextGetObjectId(infunction, text) \ DatumGetObjectId(DirectFunctionCall1(infunction, \ - DirectFunctionCall1(textout, PointerGetDatum(text)))) + CStringGetDatum(text_to_cstring(text)))) #define UNSUPPORTED_FUNCTION(name) \ Datum name(PG_FUNCTION_ARGS); \ @@ -151,7 +146,7 @@ UNSUPPORTED_FUNCTION(tsa_get_covers); Datum tsa_lexize_byname(PG_FUNCTION_ARGS) { - text *dictname = PG_GETARG_TEXT_P(0); + text *dictname = PG_GETARG_TEXT_PP(0); Datum arg1 = PG_GETARG_DATUM(1); return DirectFunctionCall2(ts_lexize, @@ -192,10 +187,10 @@ tsa_set_curdict(PG_FUNCTION_ARGS) Datum tsa_set_curdict_byname(PG_FUNCTION_ARGS) { - text *name = PG_GETARG_TEXT_P(0); + text *name = PG_GETARG_TEXT_PP(0); Oid dict_oid; - dict_oid = TSDictionaryGetDictid(stringToQualifiedNameList(TextPGetCString(name)), false); + dict_oid = TSDictionaryGetDictid(stringToQualifiedNameList(text_to_cstring(name)), false); current_dictionary_oid = dict_oid; @@ -231,10 +226,10 @@ tsa_set_curprs(PG_FUNCTION_ARGS) Datum tsa_set_curprs_byname(PG_FUNCTION_ARGS) { - text *name = PG_GETARG_TEXT_P(0); + text *name = PG_GETARG_TEXT_PP(0); Oid parser_oid; - parser_oid = TSParserGetPrsid(stringToQualifiedNameList(TextPGetCString(name)), false); + parser_oid = TSParserGetPrsid(stringToQualifiedNameList(text_to_cstring(name)), false); current_parser_oid = parser_oid; @@ -272,10 +267,10 @@ tsa_set_curcfg(PG_FUNCTION_ARGS) Datum tsa_set_curcfg_byname(PG_FUNCTION_ARGS) { - text *arg0 = PG_GETARG_TEXT_P(0); + text *arg0 = PG_GETARG_TEXT_PP(0); char *name; - name = TextPGetCString(arg0); + name = text_to_cstring(arg0); set_config_option("default_text_search_config", name, PGC_USERSET, @@ -290,7 +285,7 @@ tsa_set_curcfg_byname(PG_FUNCTION_ARGS) Datum tsa_to_tsvector_name(PG_FUNCTION_ARGS) { - text *cfgname = PG_GETARG_TEXT_P(0); + text *cfgname = PG_GETARG_TEXT_PP(0); Datum arg1 = PG_GETARG_DATUM(1); Oid config_oid; @@ -304,7 +299,7 @@ tsa_to_tsvector_name(PG_FUNCTION_ARGS) Datum tsa_to_tsquery_name(PG_FUNCTION_ARGS) { - text *cfgname = PG_GETARG_TEXT_P(0); + text *cfgname = PG_GETARG_TEXT_PP(0); Datum arg1 = PG_GETARG_DATUM(1); Oid config_oid; @@ -319,7 +314,7 @@ tsa_to_tsquery_name(PG_FUNCTION_ARGS) Datum tsa_plainto_tsquery_name(PG_FUNCTION_ARGS) { - text *cfgname = PG_GETARG_TEXT_P(0); + text *cfgname = PG_GETARG_TEXT_PP(0); Datum arg1 = PG_GETARG_DATUM(1); Oid config_oid; @@ -341,7 +336,7 @@ tsa_headline_byname(PG_FUNCTION_ARGS) /* first parameter has to be converted to oid */ config_oid = DatumGetObjectId(DirectFunctionCall1(regconfigin, - DirectFunctionCall1(textout, arg0))); + CStringGetDatum(TextDatumGetCString(arg0)))); if (PG_NARGS() == 3) result = DirectFunctionCall3(ts_headline_byid, |
