diff options
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/formatting.c | 12 | ||||
-rw-r--r-- | src/backend/utils/adt/regexp.c | 5 | ||||
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 32 | ||||
-rw-r--r-- | src/backend/utils/adt/tid.c | 37 | ||||
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 33 | ||||
-rw-r--r-- | src/backend/utils/adt/varlena.c | 32 |
6 files changed, 64 insertions, 87 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index cf7d3618426..3df0fe35579 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- * formatting.c * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.18 2000/07/03 23:09:50 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.19 2000/07/05 23:11:35 tgl Exp $ * * * Portions Copyright (c) 1999-2000, PostgreSQL, Inc @@ -2420,8 +2420,8 @@ timestamp_to_char(PG_FUNCTION_ARGS) len = VARSIZE(fmt) - VARHDRSZ; - if ((!len) || (TIMESTAMP_NOT_FINITE(dt))) - return PointerGetDatum(textin("")); + if (len <= 0 || TIMESTAMP_NOT_FINITE(dt)) + return DirectFunctionCall1(textin, CStringGetDatum("")); ZERO_tm(tm); tzn = NULL; @@ -3956,13 +3956,11 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, #define NUM_TOCHAR_prepare \ do { \ len = VARSIZE(fmt) - VARHDRSZ; \ - \ if (len <= 0) \ - return PointerGetDatum(textin("")); \ - \ + return DirectFunctionCall1(textin, CStringGetDatum("")); \ result = (text *) palloc( (len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \ format = NUM_cache(len, &Num, VARDATA(fmt), &flag); \ -} while(0) +} while (0) /* ---------- * MACRO: Finish part of NUM diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index 052b68137f8..6bb7bac705d 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.30 2000/01/26 05:57:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.31 2000/07/05 23:11:35 tgl Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -68,7 +68,8 @@ RE_compile_and_execute(struct varlena * text_re, char *text, int cflags) char *re; int regcomp_result; - re = textout(text_re); + re = DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(text_re))); /* find a previously compiled regular expression */ for (i = 0; i < rec; i++) { diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 5cd46bb0de2..d46c81157da 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.73 2000/06/15 03:32:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.74 2000/07/05 23:11:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -442,7 +442,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) /* the right-hand const is type text for all supported operators */ Assert(rtype == TEXTOID); - patt = textout((text *) DatumGetPointer(value)); + patt = DatumGetCString(DirectFunctionCall1(textout, value)); /* divide pattern into fixed prefix and remainder */ pstatus = pattern_fixed_prefix(patt, ptype, &prefix, &rest); @@ -1184,9 +1184,9 @@ getattstatistics(Oid relid, */ if (commonval) { - text *val = (text *) SysCacheGetAttr(STATRELID, tuple, + Datum val = SysCacheGetAttr(STATRELID, tuple, Anum_pg_statistic_stacommonval, - &isnull); + &isnull); if (isnull) { @@ -1195,7 +1195,8 @@ getattstatistics(Oid relid, } else { - char *strval = textout(val); + char *strval = DatumGetCString(DirectFunctionCall1(textout, + val)); *commonval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1207,9 +1208,9 @@ getattstatistics(Oid relid, if (loval) { - text *val = (text *) SysCacheGetAttr(STATRELID, tuple, - Anum_pg_statistic_staloval, - &isnull); + Datum val = SysCacheGetAttr(STATRELID, tuple, + Anum_pg_statistic_staloval, + &isnull); if (isnull) { @@ -1218,7 +1219,8 @@ getattstatistics(Oid relid, } else { - char *strval = textout(val); + char *strval = DatumGetCString(DirectFunctionCall1(textout, + val)); *loval = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1230,9 +1232,9 @@ getattstatistics(Oid relid, if (hival) { - text *val = (text *) SysCacheGetAttr(STATRELID, tuple, - Anum_pg_statistic_stahival, - &isnull); + Datum val = SysCacheGetAttr(STATRELID, tuple, + Anum_pg_statistic_stahival, + &isnull); if (isnull) { @@ -1241,7 +1243,8 @@ getattstatistics(Oid relid, } else { - char *strval = textout(val); + char *strval = DatumGetCString(DirectFunctionCall1(textout, + val)); *hival = FunctionCall3(&inputproc, CStringGetDatum(strval), @@ -1868,7 +1871,6 @@ find_operator(const char *opname, Oid datatype) static Datum string_to_datum(const char *str, Oid datatype) { - /* * We cheat a little by assuming that textin() will do for bpchar and * varchar constants too... @@ -1876,7 +1878,7 @@ string_to_datum(const char *str, Oid datatype) if (datatype == NAMEOID) return PointerGetDatum(namein((char *) str)); else - return PointerGetDatum(textin((char *) str)); + return DirectFunctionCall1(textin, CStringGetDatum(str)); } /*------------------------------------------------------------------------- diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 263470a063c..7d0f4447c2d 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.20 2000/06/09 01:11:09 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.21 2000/07/05 23:11:35 tgl Exp $ * * NOTES * input routine largely stolen from boxin(). @@ -126,38 +126,6 @@ tidne(ItemPointer arg1, ItemPointer arg2) } #endif -#ifdef NOT_USED -text * -tid_text(ItemPointer tid) -{ - char *str; - - if (!tid) - return (text *) NULL; - str = tidout(tid); - - return textin(str); -} /* tid_text() */ -#endif - -#ifdef NOT_USED -ItemPointer -text_tid(const text *string) -{ - ItemPointer result; - char *str; - - if (!string) - return (ItemPointer) 0; - - str = textout((text *) string); - result = tidin(str); - pfree(str); - - return result; -} /* text_tid() */ -#endif - /* * Functions to get latest tid of a specified tuple. * @@ -197,7 +165,8 @@ currtid_byrelname(PG_FUNCTION_ARGS) char *str; Relation rel; - str = textout(relname); + str = DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(relname))); result = (ItemPointer) palloc(sizeof(ItemPointerData)); ItemPointerSetInvalid(result); diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 4b3f498a2af..d5d5b86f9fe 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.31 2000/07/03 23:09:53 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.32 2000/07/05 23:11:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1487,7 +1487,9 @@ timestamp_trunc(PG_FUNCTION_ARGS) *tm = &tt; if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1625,7 +1627,9 @@ interval_trunc(PG_FUNCTION_ARGS) result = (Interval *) palloc(sizeof(Interval)); if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1706,7 +1710,9 @@ interval_trunc(PG_FUNCTION_ARGS) #endif else { - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); PG_RETURN_NULL(); } @@ -1738,7 +1744,9 @@ timestamp_part(PG_FUNCTION_ARGS) *tm = &tt; if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -1926,7 +1934,9 @@ interval_part(PG_FUNCTION_ARGS) *tm = &tt; if (VARSIZE(units) - VARHDRSZ > MAXDATELEN) - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); up = VARDATA(units); lp = lowunits; for (i = 0; i < (VARSIZE(units) - VARHDRSZ); i++) @@ -2000,7 +2010,8 @@ interval_part(PG_FUNCTION_ARGS) default: elog(ERROR, "Interval units '%s' not yet supported", - textout(units)); + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); result = 0; } @@ -2022,7 +2033,9 @@ interval_part(PG_FUNCTION_ARGS) } else { - elog(ERROR, "Interval units '%s' not recognized", textout(units)); + elog(ERROR, "Interval units '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(units)))); result = 0; } @@ -2056,7 +2069,9 @@ timestamp_zone(PG_FUNCTION_ARGS) int len; if (VARSIZE(zone) - VARHDRSZ > MAXDATELEN) - elog(ERROR, "Time zone '%s' not recognized", textout(zone)); + elog(ERROR, "Time zone '%s' not recognized", + DatumGetCString(DirectFunctionCall1(textout, + PointerGetDatum(zone)))); up = VARDATA(zone); lp = lowzone; for (i = 0; i < (VARSIZE(zone) - VARHDRSZ); i++) diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 114bcff29a4..8ddabdb4ee4 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.61 2000/07/03 23:09:54 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.62 2000/07/05 23:11:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -146,54 +146,46 @@ byteaout(bytea *vlena) /* * textin - converts "..." to internal representation */ -text * -textin(char *inputText) +Datum +textin(PG_FUNCTION_ARGS) { + char *inputText = PG_GETARG_CSTRING(0); text *result; int len; - if (inputText == NULL) - return NULL; - len = strlen(inputText) + VARHDRSZ; result = (text *) palloc(len); VARATT_SIZEP(result) = len; - memmove(VARDATA(result), inputText, len - VARHDRSZ); + memcpy(VARDATA(result), inputText, len - VARHDRSZ); #ifdef CYR_RECODE convertstr(VARDATA(result), len - VARHDRSZ, 0); #endif - return result; + PG_RETURN_TEXT_P(result); } /* * textout - converts internal representation to "..." */ -char * -textout(text *vlena) +Datum +textout(PG_FUNCTION_ARGS) { + text *t = PG_GETARG_TEXT_P(0); int len; char *result; - if (vlena == NULL) - { - result = (char *) palloc(2); - result[0] = '-'; - result[1] = '\0'; - return result; - } - len = VARSIZE(vlena) - VARHDRSZ; + len = VARSIZE(t) - VARHDRSZ; result = (char *) palloc(len + 1); - memmove(result, VARDATA(vlena), len); + memcpy(result, VARDATA(t), len); result[len] = '\0'; #ifdef CYR_RECODE convertstr(result, len, 1); #endif - return result; + PG_RETURN_CSTRING(result); } |