mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
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
This commit is contained in:
@ -13,7 +13,7 @@
|
||||
* this version handles 64 bit numbers and so can hold values up to
|
||||
* $92,233,720,368,547,758.07.
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.77 2007/11/24 16:18:48 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.78 2008/03/25 22:42:43 tgl Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -24,6 +24,7 @@
|
||||
#include <locale.h>
|
||||
|
||||
#include "libpq/pqformat.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/cash.h"
|
||||
#include "utils/pg_locale.h"
|
||||
|
||||
@ -796,7 +797,6 @@ cash_words(PG_FUNCTION_ARGS)
|
||||
Cash m4;
|
||||
Cash m5;
|
||||
Cash m6;
|
||||
text *result;
|
||||
|
||||
/* work with positive numbers */
|
||||
if (value < 0)
|
||||
@ -862,10 +862,6 @@ cash_words(PG_FUNCTION_ARGS)
|
||||
/* capitalize output */
|
||||
buf[0] = pg_toupper((unsigned char) buf[0]);
|
||||
|
||||
/* make a text type for output */
|
||||
result = (text *) palloc(strlen(buf) + VARHDRSZ);
|
||||
SET_VARSIZE(result, strlen(buf) + VARHDRSZ);
|
||||
memcpy(VARDATA(result), buf, strlen(buf));
|
||||
|
||||
PG_RETURN_TEXT_P(result);
|
||||
/* return as text datum */
|
||||
PG_RETURN_TEXT_P(cstring_to_text(buf));
|
||||
}
|
||||
|
Reference in New Issue
Block a user