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/utils/adt/lockfuncs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/backend/utils/adt/lockfuncs.c') diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index de5420e7719..55a6adaa5fa 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -6,7 +6,7 @@ * Copyright (c) 2002-2008, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.32 2008/01/08 23:18:51 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.33 2008/03/25 22:42:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -57,7 +57,7 @@ VXIDGetDatum(BackendId bid, LocalTransactionId lxid) snprintf(vxidstr, sizeof(vxidstr), "%d/%u", bid, lxid); - return DirectFunctionCall1(textin, CStringGetDatum(vxidstr)); + return CStringGetTextDatum(vxidstr); } @@ -214,8 +214,7 @@ pg_lock_status(PG_FUNCTION_ARGS) (int) lock->tag.locktag_type); locktypename = tnbuf; } - values[0] = DirectFunctionCall1(textin, - CStringGetDatum(locktypename)); + values[0] = CStringGetTextDatum(locktypename); switch ((LockTagType) lock->tag.locktag_type) { @@ -297,9 +296,7 @@ pg_lock_status(PG_FUNCTION_ARGS) values[11] = Int32GetDatum(proc->pid); else nulls[11] = 'n'; - values[12] = DirectFunctionCall1(textin, - CStringGetDatum(GetLockmodeName(LOCK_LOCKMETHOD(*lock), - mode))); + values[12] = CStringGetTextDatum(GetLockmodeName(LOCK_LOCKMETHOD(*lock), mode)); values[13] = BoolGetDatum(granted); tuple = heap_formtuple(funcctx->tuple_desc, values, nulls); -- cgit v1.2.3