summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2000-07-05 23:12:09 +0000
committerTom Lane2000-07-05 23:12:09 +0000
commitae4b9a195a0fadbd84c795687ff8cd5726025fb3 (patch)
tree2865950b755050030d01d7289c7515ff73de678e
parent0f225be3a6ad408e5d2c73bb60f41c9d27de1209 (diff)
Update textin() and textout() to new fmgr style. This is just phase
one of updating the whole text datatype, but there are so dang many calls of these two routines that it seems worth a separate commit.
-rw-r--r--contrib/spi/autoinc.c16
-rw-r--r--contrib/spi/insert_username.c2
-rw-r--r--src/backend/catalog/heap.c15
-rw-r--r--src/backend/catalog/index.c17
-rw-r--r--src/backend/catalog/pg_aggregate.c18
-rw-r--r--src/backend/catalog/pg_proc.c9
-rw-r--r--src/backend/catalog/pg_type.c46
-rw-r--r--src/backend/commands/analyze.c18
-rw-r--r--src/backend/commands/command.c19
-rw-r--r--src/backend/commands/comment.c2
-rw-r--r--src/backend/commands/copy.c3
-rw-r--r--src/backend/commands/dbcommands.c3
-rw-r--r--src/backend/commands/indexcmds.c3
-rw-r--r--src/backend/commands/proclang.c7
-rw-r--r--src/backend/commands/sequence.c3
-rw-r--r--src/backend/commands/user.c15
-rw-r--r--src/backend/executor/execUtils.c3
-rw-r--r--src/backend/libpq/be-pqexec.c9
-rw-r--r--src/backend/optimizer/path/indxpath.c21
-rw-r--r--src/backend/optimizer/util/plancat.c4
-rw-r--r--src/backend/parser/parse_coerce.c3
-rw-r--r--src/backend/parser/parse_node.c2
-rw-r--r--src/backend/utils/adt/formatting.c10
-rw-r--r--src/backend/utils/adt/regexp.c3
-rw-r--r--src/backend/utils/adt/selfuncs.c30
-rw-r--r--src/backend/utils/adt/tid.c35
-rw-r--r--src/backend/utils/adt/timestamp.c31
-rw-r--r--src/backend/utils/adt/varlena.c30
-rw-r--r--src/backend/utils/cache/fcache.c22
-rw-r--r--src/backend/utils/cache/relcache.c22
-rw-r--r--src/backend/utils/fmgr/dfmgr.c12
-rw-r--r--src/backend/utils/fmgr/fmgr.c3
-rw-r--r--src/include/catalog/pg_proc.h4
-rw-r--r--src/include/utils/builtins.h4
-rw-r--r--src/pl/plperl/plperl.c7
-rw-r--r--src/pl/plpgsql/src/pl_comp.c3
-rw-r--r--src/pl/plpgsql/src/pl_exec.c26
-rw-r--r--src/pl/tcl/pltcl.c6
-rw-r--r--src/test/regress/regress.c3
39 files changed, 252 insertions, 237 deletions
diff --git a/contrib/spi/autoinc.c b/contrib/spi/autoinc.c
index 804e1d6383..f8b86217e7 100644
--- a/contrib/spi/autoinc.c
+++ b/contrib/spi/autoinc.c
@@ -53,12 +53,13 @@ autoinc(PG_FUNCTION_ARGS)
for (i = 0; i < nargs;)
{
- text *seqname;
int attnum = SPI_fnumber(tupdesc, args[i]);
int32 val;
+ Datum seqname;
if (attnum < 0)
- elog(ERROR, "autoinc (%s): there is no attribute %s", relname, args[i]);
+ elog(ERROR, "autoinc (%s): there is no attribute %s",
+ relname, args[i]);
if (SPI_gettypeid(tupdesc, attnum) != INT4OID)
elog(ERROR, "autoinc (%s): attribute %s must be of INT4 type",
relname, args[i]);
@@ -73,13 +74,12 @@ autoinc(PG_FUNCTION_ARGS)
i++;
chattrs[chnattrs] = attnum;
- seqname = textin(args[i]);
- newvals[chnattrs] = DirectFunctionCall1(nextval,
- PointerGetDatum(seqname));
+ seqname = DirectFunctionCall1(textin,
+ CStringGetDatum(args[i]));
+ newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
if (DatumGetInt32(newvals[chnattrs]) == 0)
- newvals[chnattrs] = DirectFunctionCall1(nextval,
- PointerGetDatum(seqname));
- pfree(seqname);
+ newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
+ pfree(DatumGetTextP(seqname));
chnattrs++;
i++;
}
diff --git a/contrib/spi/insert_username.c b/contrib/spi/insert_username.c
index 61b4150084..978a873ec9 100644
--- a/contrib/spi/insert_username.c
+++ b/contrib/spi/insert_username.c
@@ -62,7 +62,7 @@ insert_username(PG_FUNCTION_ARGS)
relname, args[0]);
/* create fields containing name */
- newval = PointerGetDatum(textin(GetPgUserName()));
+ newval = DirectFunctionCall1(textin, CStringGetDatum(GetPgUserName()));
/* construct new tuple */
rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newval, NULL);
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index d3e7a4719e..d239fff1ef 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1121,7 +1121,8 @@ RelationTruncateIndexes(Relation heapRelation)
/* If a valid where predicate, compute predicate Node */
if (VARSIZE(&index->indpred) != 0)
{
- predString = textout(&index->indpred);
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&index->indpred)));
oldPred = stringToNode(predString);
pfree(predString);
}
@@ -1602,8 +1603,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
values[Anum_pg_attrdef_adrelid - 1] = RelationGetRelid(rel);
values[Anum_pg_attrdef_adnum - 1] = attnum;
- values[Anum_pg_attrdef_adbin - 1] = PointerGetDatum(textin(adbin));
- values[Anum_pg_attrdef_adsrc - 1] = PointerGetDatum(textin(adsrc));
+ values[Anum_pg_attrdef_adbin - 1] = DirectFunctionCall1(textin,
+ CStringGetDatum(adbin));
+ values[Anum_pg_attrdef_adsrc - 1] = DirectFunctionCall1(textin,
+ CStringGetDatum(adsrc));
adrel = heap_openr(AttrDefaultRelationName, RowExclusiveLock);
tuple = heap_formtuple(adrel->rd_att, values, nulls);
heap_insert(adrel, tuple);
@@ -1685,8 +1688,10 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
values[Anum_pg_relcheck_rcrelid - 1] = RelationGetRelid(rel);
values[Anum_pg_relcheck_rcname - 1] = PointerGetDatum(namein(ccname));
- values[Anum_pg_relcheck_rcbin - 1] = PointerGetDatum(textin(ccbin));
- values[Anum_pg_relcheck_rcsrc - 1] = PointerGetDatum(textin(ccsrc));
+ values[Anum_pg_relcheck_rcbin - 1] = DirectFunctionCall1(textin,
+ CStringGetDatum(ccbin));
+ values[Anum_pg_relcheck_rcsrc - 1] = DirectFunctionCall1(textin,
+ CStringGetDatum(ccsrc));
rcrel = heap_openr(RelCheckRelationName, RowExclusiveLock);
tuple = heap_formtuple(rcrel->rd_att, values, nulls);
heap_insert(rcrel, tuple);
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index b3219bcb2b..afb5b607b7 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -680,11 +680,13 @@ UpdateIndexRelation(Oid indexoid,
if (predicate != NULL)
{
predString = nodeToString(predicate);
- predText = textin(predString);
+ predText = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum(predString)));
pfree(predString);
}
else
- predText = textin("");
+ predText = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum("")));
predLen = VARSIZE(predText);
itupLen = predLen + sizeof(FormData_pg_index);
@@ -824,11 +826,13 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
if (newPred != NULL)
{
predString = nodeToString(newPred);
- predText = textin(predString);
+ predText = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum(predString)));
pfree(predString);
}
else
- predText = textin("");
+ predText = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum("")));
/* open the index system catalog relation */
pg_index = heap_openr(IndexRelationName, RowExclusiveLock);
@@ -1337,7 +1341,7 @@ IndexesAreActive(Oid relid, bool confirmCommitted)
elog(ERROR, "IndexesAreActive couldn't lock %u", relid);
if (((Form_pg_class) GETSTRUCT(&tuple))->relkind != RELKIND_RELATION &&
((Form_pg_class) GETSTRUCT(&tuple))->relkind != RELKIND_TOASTVALUE)
- elog(ERROR, "relation %u isn't an relation", relid);
+ elog(ERROR, "relation %u isn't an indexable relation", relid);
isactive = ((Form_pg_class) GETSTRUCT(&tuple))->relhasindex;
ReleaseBuffer(buffer);
if (isactive)
@@ -2080,7 +2084,8 @@ reindex_index(Oid indexId, bool force)
/* If a valid where predicate, compute predicate Node */
if (VARSIZE(&index->indpred) != 0)
{
- predString = textout(&index->indpred);
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&index->indpred)));
oldPred = stringToNode(predString);
pfree(predString);
}
diff --git a/src/backend/catalog/pg_aggregate.c b/src/backend/catalog/pg_aggregate.c
index 87eead2aa4..53f3496fee 100644
--- a/src/backend/catalog/pg_aggregate.c
+++ b/src/backend/catalog/pg_aggregate.c
@@ -238,12 +238,14 @@ AggregateCreate(char *aggName,
values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(fret);
if (agginitval1)
- values[Anum_pg_aggregate_agginitval1 - 1] = PointerGetDatum(textin(agginitval1));
+ values[Anum_pg_aggregate_agginitval1 - 1] =
+ DirectFunctionCall1(textin, CStringGetDatum(agginitval1));
else
nulls[Anum_pg_aggregate_agginitval1 - 1] = 'n';
if (agginitval2)
- values[Anum_pg_aggregate_agginitval2 - 1] = PointerGetDatum(textin(agginitval2));
+ values[Anum_pg_aggregate_agginitval2 - 1] =
+ DirectFunctionCall1(textin, CStringGetDatum(agginitval2));
else
nulls[Anum_pg_aggregate_agginitval2 - 1] = 'n';
@@ -277,7 +279,7 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
Oid transtype,
typinput,
typelem;
- text *textInitVal;
+ Datum textInitVal;
char *strInitVal;
Datum initVal;
@@ -312,17 +314,15 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
initValAttno = Anum_pg_aggregate_agginitval2;
}
- textInitVal = (text *) fastgetattr(tup, initValAttno,
- RelationGetDescr(aggRel),
- isNull);
- if (!PointerIsValid(textInitVal))
- *isNull = true;
+ textInitVal = fastgetattr(tup, initValAttno,
+ RelationGetDescr(aggRel),
+ isNull);
if (*isNull)
{
heap_close(aggRel, AccessShareLock);
return PointerGetDatum(NULL);
}
- strInitVal = textout(textInitVal);
+ strInitVal = DatumGetCString(DirectFunctionCall1(textout, textInitVal));
heap_close(aggRel, AccessShareLock);
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index 0e009fa0eb..00f02eef41 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -156,7 +156,8 @@ ProcedureCreate(char *procedureName,
*/
text *prosrctext;
- prosrctext = textin(prosrc);
+ prosrctext = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum(prosrc)));
tup = SearchSysCacheTuple(PROSRC,
PointerGetDatum(prosrctext),
0, 0, 0);
@@ -306,8 +307,10 @@ ProcedureCreate(char *procedureName,
values[i++] = Int32GetDatum(perbyte_cpu); /* properbyte_cpu */
values[i++] = Int32GetDatum(percall_cpu); /* propercall_cpu */
values[i++] = Int32GetDatum(outin_ratio); /* prooutin_ratio */
- values[i++] = (Datum) textin(prosrc); /* prosrc */
- values[i++] = (Datum) textin(probin); /* probin */
+ values[i++] = DirectFunctionCall1(textin, /* prosrc */
+ CStringGetDatum(prosrc));
+ values[i++] = DirectFunctionCall1(textin, /* probin */
+ CStringGetDatum(probin));
rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index 75ceb2b848..bef1f43e21 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -167,32 +167,29 @@ TypeShellMakeWithOpenRelation(Relation pg_type_desc, char *typeName)
}
/* ----------------
- * initialize *values with the type name and
+ * initialize *values with the type name and dummy values
* ----------------
*/
i = 0;
namestrcpy(&name, typeName);
- values[i++] = NameGetDatum(&name); /* 1 */
- values[i++] = (Datum) InvalidOid; /* 2 */
- values[i++] = (Datum) (int16) 0; /* 3 */
- values[i++] = (Datum) (int16) 0; /* 4 */
- values[i++] = (Datum) (bool) 0; /* 5 */
- values[i++] = (Datum) (bool) 0; /* 6 */
- values[i++] = (Datum) (bool) 0; /* 7 */
- values[i++] = (Datum) (bool) 0; /* 8 */
- values[i++] = (Datum) InvalidOid; /* 9 */
- values[i++] = (Datum) InvalidOid; /* 10 */
- values[i++] = (Datum) InvalidOid; /* 11 */
- values[i++] = (Datum) InvalidOid; /* 12 */
- values[i++] = (Datum) InvalidOid; /* 13 */
- values[i++] = (Datum) InvalidOid; /* 14 */
- values[i++] = (Datum) 'p'; /* 15 */
- values[i++] = (Datum) 'i'; /* 16 */
-
- /*
- * ... and fill typdefault with a bogus value
- */
- values[i++] = (Datum) textin(typeName); /* 15 */
+ values[i++] = NameGetDatum(&name); /* 1 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 2 */
+ values[i++] = Int16GetDatum(0); /* 3 */
+ values[i++] = Int16GetDatum(0); /* 4 */
+ values[i++] = BoolGetDatum(false); /* 5 */
+ values[i++] = BoolGetDatum(false); /* 6 */
+ values[i++] = BoolGetDatum(false); /* 7 */
+ values[i++] = BoolGetDatum(false); /* 8 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 9 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 10 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 11 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 12 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 13 */
+ values[i++] = ObjectIdGetDatum(InvalidOid); /* 14 */
+ values[i++] = CharGetDatum('p'); /* 15 */
+ values[i++] = CharGetDatum('i'); /* 16 */
+ values[i++] = DirectFunctionCall1(textin,
+ CStringGetDatum(typeName)); /* 17 */
/* ----------------
* create a new type tuple with FormHeapTuple
@@ -460,9 +457,8 @@ TypeCreate(char *typeName,
* initialize the default value for this type.
* ----------------
*/
- values[i] = (Datum) textin(PointerIsValid(defaultTypeValue) /* 17 */
- ? defaultTypeValue : "-"); /* XXX default
- * typdefault */
+ values[i] = DirectFunctionCall1(textin, /* 17 */
+ CStringGetDatum(defaultTypeValue ? defaultTypeValue : "-"));
/* ----------------
* open pg_type and begin a scan for the type name.
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 6767f771b1..ef4fc5c095 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -515,8 +515,8 @@ update_attstats(Oid relid, int natts, VacAttrStats *vacattrstats)
*/
if (VacAttrStatsLtGtValid(stats) && stats->initialized)
{
- float32data nullratio;
- float32data bestratio;
+ float4 nullratio;
+ float4 bestratio;
FmgrInfo out_function;
char *out_string;
double best_cnt_d = stats->best_cnt,
@@ -541,26 +541,28 @@ update_attstats(Oid relid, int natts, VacAttrStats *vacattrstats)
values[i++] = ObjectIdGetDatum(relid); /* starelid */
values[i++] = Int16GetDatum(attp->attnum); /* staattnum */
values[i++] = ObjectIdGetDatum(stats->op_cmplt); /* staop */
- /* hack: this code knows float4 is pass-by-ref */
- values[i++] = Float32GetDatum(&nullratio); /* stanullfrac */
- values[i++] = Float32GetDatum(&bestratio); /* stacommonfrac */
+ values[i++] = Float4GetDatum(nullratio); /* stanullfrac */
+ values[i++] = Float4GetDatum(bestratio); /* stacommonfrac */
out_string = DatumGetCString(FunctionCall3(&out_function,
stats->best,
ObjectIdGetDatum(stats->typelem),
Int32GetDatum(stats->attr->atttypmod)));
- values[i++] = PointerGetDatum(textin(out_string)); /* stacommonval */
+ values[i++] = DirectFunctionCall1(textin, /* stacommonval */
+ CStringGetDatum(out_string));
pfree(out_string);
out_string = DatumGetCString(FunctionCall3(&out_function,
stats->min,
ObjectIdGetDatum(stats->typelem),
Int32GetDatum(stats->attr->atttypmod)));
- values[i++] = PointerGetDatum(textin(out_string)); /* staloval */
+ values[i++] = DirectFunctionCall1(textin, /* staloval */
+ CStringGetDatum(out_string));
pfree(out_string);
out_string = DatumGetCString(FunctionCall3(&out_function,
stats->max,
ObjectIdGetDatum(stats->typelem),
Int32GetDatum(stats->attr->atttypmod)));
- values[i++] = PointerGetDatum(textin(out_string)); /* stahival */
+ values[i++] = DirectFunctionCall1(textin, /* stahival */
+ CStringGetDatum(out_string));
pfree(out_string);
stup = heap_formtuple(sd->rd_att, values, nulls);
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c
index 831966cf32..ee9dfb9471 100644
--- a/src/backend/commands/command.c
+++ b/src/backend/commands/command.c
@@ -788,7 +788,6 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup)
HeapTuple htup,
indexTuple;
Form_pg_index index;
- Form_pg_relcheck relcheck;
Form_pg_class pgcform = (Form_pg_class) NULL;
int i;
bool checkok = true;
@@ -807,13 +806,13 @@ RemoveColumnReferences(Oid reloid, int attnum, bool checkonly, HeapTuple reltup)
while (HeapTupleIsValid(htup = systable_getnext(sysscan)))
{
+ Form_pg_relcheck relcheck;
char *ccbin;
Node *node;
relcheck = (Form_pg_relcheck) GETSTRUCT(htup);
- ccbin = textout(&relcheck->rcbin);
- if (!ccbin)
- continue;
+ ccbin = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&relcheck->rcbin)));
node = stringToNode(ccbin);
pfree(ccbin);
if (find_attribute_in_node(node, attnum))
@@ -1322,10 +1321,12 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
BYTEAOID,
-1, 0, false);
- /* XXX what if owning relation is temp? need we mark toasttable too? */
- /* XXX How do we know? No naming collisions possible because names */
- /* are OID based. And toast table disappears when master table */
- /* is destroyed. So what is it good for anyway? Jan */
+ /*
+ * Note: the toast relation is considered a "normal" relation even if
+ * its master relation is a temp table. There cannot be any naming
+ * collision, and the toast rel will be destroyed when its master is,
+ * so there's no need to handle the toast rel as temp.
+ */
heap_create_with_catalog(toast_relname, tupdesc, RELKIND_TOASTVALUE,
false, true);
@@ -1399,7 +1400,7 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
heap_freetuple(reltup);
/*
- * Close relatons and make changes visible
+ * Close relations and make changes visible
*/
heap_close(class_rel, NoLock);
heap_close(rel, NoLock);
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 2b9bf4d772..c76912f332 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -151,7 +151,7 @@ CreateComments(Oid oid, char *comment)
}
i = 0;
values[i++] = ObjectIdGetDatum(oid);
- values[i++] = (Datum) textin(comment);
+ values[i++] = DirectFunctionCall1(textin, CStringGetDatum(comment));
}
/*** Now, open pg_description and attempt to find the old tuple ***/
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 69ff2ef600..173b72d434 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -676,7 +676,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
indexNatts[i] = natts;
if (VARSIZE(&pgIndexP[i]->indpred) != 0)
{
- predString = textout(&pgIndexP[i]->indpred);
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&pgIndexP[i]->indpred)));
indexPred[i] = stringToNode(predString);
pfree(predString);
/* make dummy ExprContext for use by ExecQual */
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 13751e1ab1..e7d6f4de9f 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -101,7 +101,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
new_record[Anum_pg_database_datname - 1] = NameGetDatum(namein(dbname));
new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(user_id);
new_record[Anum_pg_database_encoding - 1] = Int32GetDatum(encoding);
- new_record[Anum_pg_database_datpath - 1] = PointerGetDatum(textin(locbuf));
+ new_record[Anum_pg_database_datpath - 1] = DirectFunctionCall1(textin,
+ CStringGetDatum(locbuf));
tuple = heap_formtuple(pg_database_dsc, new_record, new_record_nulls);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index e4fd0f0456..6b165c97f8 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -304,7 +304,8 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
{
char *predString;
- predString = textout(&index->indpred);
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&index->indpred)));
oldPred = stringToNode(predString);
pfree(predString);
}
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index 9b5f7c1ddf..ec8aec7005 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -117,10 +117,11 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
i = 0;
values[i++] = PointerGetDatum(languageName);
- values[i++] = Int8GetDatum((bool) 1);
- values[i++] = Int8GetDatum(stmt->pltrusted);
+ values[i++] = BoolGetDatum(true); /* lanispl */
+ values[i++] = BoolGetDatum(stmt->pltrusted);
values[i++] = ObjectIdGetDatum(procTup->t_data->t_oid);
- values[i++] = (Datum) textin(stmt->plcompiler);
+ values[i++] = DirectFunctionCall1(textin,
+ CStringGetDatum(stmt->plcompiler));
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 968ae569ee..80fca6a38a 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -377,7 +377,8 @@ setval(PG_FUNCTION_ARGS)
static char *
get_seq_name(text *seqin)
{
- char *rawname = textout(seqin);
+ char *rawname = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(seqin)));
int rawlen = strlen(rawname);
char *seqname;
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 488a6f7f5e..32dc8af6f0 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -121,7 +121,8 @@ write_password_file(Relation rel)
CRYPT_PWD_FILE_SEPSTR
"%s\n",
nameout(DatumGetName(datum_n)),
- null_p ? "" : textout((text *) datum_p),
+ null_p ? "" :
+ DatumGetCString(DirectFunctionCall1(textout, datum_p)),
null_v ? "\\N" :
DatumGetCString(DirectFunctionCall1(nabstimeout, datum_v))
);
@@ -257,7 +258,8 @@ CreateUser(CreateUserStmt *stmt)
new_record[Anum_pg_shadow_usecatupd - 1] = (Datum) (stmt->createuser);
if (stmt->password)
- new_record[Anum_pg_shadow_passwd - 1] = PointerGetDatum(textin(stmt->password));
+ new_record[Anum_pg_shadow_passwd - 1] =
+ DirectFunctionCall1(textin, CStringGetDatum(stmt->password));
if (stmt->validUntil)
new_record[Anum_pg_shadow_valuntil - 1] =
DirectFunctionCall1(nabstimein, CStringGetDatum(stmt->validUntil));
@@ -424,13 +426,15 @@ AlterUser(AlterUserStmt *stmt)
/* password */
if (stmt->password)
{
- new_record[Anum_pg_shadow_passwd - 1] = PointerGetDatum(textin(stmt->password));
+ new_record[Anum_pg_shadow_passwd - 1] =
+ DirectFunctionCall1(textin, CStringGetDatum(stmt->password));
new_record_nulls[Anum_pg_shadow_passwd - 1] = ' ';
}
else
{
/* leave as is */
- new_record[Anum_pg_shadow_passwd - 1] = heap_getattr(tuple, Anum_pg_shadow_passwd, pg_shadow_dsc, &null);
+ new_record[Anum_pg_shadow_passwd - 1] =
+ heap_getattr(tuple, Anum_pg_shadow_passwd, pg_shadow_dsc, &null);
new_record_nulls[Anum_pg_shadow_passwd - 1] = null ? 'n' : ' ';
}
@@ -444,7 +448,8 @@ AlterUser(AlterUserStmt *stmt)
else
{
/* leave as is */
- new_record[Anum_pg_shadow_valuntil - 1] = heap_getattr(tuple, Anum_pg_shadow_valuntil, pg_shadow_dsc, &null);
+ new_record[Anum_pg_shadow_valuntil - 1] =
+ heap_getattr(tuple, Anum_pg_shadow_valuntil, pg_shadow_dsc, &null);
new_record_nulls[Anum_pg_shadow_valuntil - 1] = null ? 'n' : ' ';
}
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index c349aaeb9c..b7a22df264 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -850,7 +850,8 @@ ExecOpenIndices(RelationInfo *resultRelationInfo)
{
char *predString;
- predString = textout(&indexStruct->indpred);
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&indexStruct->indpred)));
predicate = (PredInfo *) stringToNode(predString);
pfree(predString);
}
diff --git a/src/backend/libpq/be-pqexec.c b/src/backend/libpq/be-pqexec.c
index 16e40f5554..20580898c3 100644
--- a/src/backend/libpq/be-pqexec.c
+++ b/src/backend/libpq/be-pqexec.c
@@ -360,7 +360,9 @@ pqtest_PQfn(char *q)
else
{
pqargs[k].len = VAR_LENGTH_ARG;
- pqargs[k].u.ptr = (int *) textin(fields[j]);
+ pqargs[k].u.ptr = (int *)
+ DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum(fields[j])));
printf("pqtest_PQfn: arg %d is text %s\n", k, fields[j]); /* debug */
}
}
@@ -405,9 +407,8 @@ pqtest(struct varlena * vlena)
* get the query
* ----------------
*/
- q = textout(vlena);
- if (q == NULL)
- return -1;
+ q = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(vlena)));
switch (q[0])
{
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 67cf40d991..ef4efe1bb5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1658,7 +1658,8 @@ match_special_index_operator(Expr *clause, Oid opclass, Oid relam,
case OID_VARCHAR_LIKE_OP:
case OID_NAME_LIKE_OP:
/* the right-hand const is type text for all of these */
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like,
&prefix, &rest) != Pattern_Prefix_None;
if (prefix)
@@ -1671,7 +1672,8 @@ match_special_index_operator(Expr *clause, Oid opclass, Oid relam,
case OID_VARCHAR_REGEXEQ_OP:
case OID_NAME_REGEXEQ_OP:
/* the right-hand const is type text for all of these */
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex,
&prefix, &rest) != Pattern_Prefix_None;
if (prefix)
@@ -1684,7 +1686,8 @@ match_special_index_operator(Expr *clause, Oid opclass, Oid relam,
case OID_VARCHAR_ICREGEXEQ_OP:
case OID_NAME_ICREGEXEQ_OP:
/* the right-hand const is type text for all of these */
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC,
&prefix, &rest) != Pattern_Prefix_None;
if (prefix)
@@ -1784,7 +1787,8 @@ expand_indexqual_conditions(List *indexquals)
case OID_NAME_LIKE_OP:
/* the right-hand const is type text for all of these */
constvalue = ((Const *) rightop)->constvalue;
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like,
&prefix, &rest);
resultquals = nconc(resultquals,
@@ -1801,7 +1805,8 @@ expand_indexqual_conditions(List *indexquals)
case OID_NAME_REGEXEQ_OP:
/* the right-hand const is type text for all of these */
constvalue = ((Const *) rightop)->constvalue;
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex,
&prefix, &rest);
resultquals = nconc(resultquals,
@@ -1818,7 +1823,8 @@ expand_indexqual_conditions(List *indexquals)
case OID_NAME_ICREGEXEQ_OP:
/* the right-hand const is type text for all of these */
constvalue = ((Const *) rightop)->constvalue;
- patt = textout((text *) DatumGetPointer(constvalue));
+ patt = DatumGetCString(DirectFunctionCall1(textout,
+ constvalue));
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC,
&prefix, &rest);
resultquals = nconc(resultquals,
@@ -1965,7 +1971,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...
@@ -1973,7 +1978,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/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 601670ee08..3200831371 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -125,8 +125,10 @@ find_secondary_indexes(Query *root, Index relid)
info->indproc = index->indproc; /* functional index ?? */
if (VARSIZE(&index->indpred) != 0) /* partial index ?? */
{
- char *predString = textout(&index->indpred);
+ char *predString;
+ predString = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&index->indpred)));
info->indpred = (List *) stringToNode(predString);
pfree(predString);
}
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 555f7c35f5..cb416d8e71 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -77,7 +77,8 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
if (!con->constisnull)
{
/* We know the source constant is really of type 'text' */
- char *val = textout((text *) con->constvalue);
+ char *val = DatumGetCString(DirectFunctionCall1(textout,
+ con->constvalue));
newcon->constvalue = stringTypeDatum(targetType, val, atttypmod);
pfree(val);
diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c
index 6f945208f3..964e3ec9da 100644
--- a/src/backend/parser/parse_node.c
+++ b/src/backend/parser/parse_node.c
@@ -462,7 +462,7 @@ make_const(Value *value)
break;
case T_String:
- val = PointerGetDatum(textin(strVal(value)));
+ val = DirectFunctionCall1(textin, CStringGetDatum(strVal(value)));
typeid = UNKNOWNOID;/* will be coerced later */
typelen = -1; /* variable len */
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 5b5c003cee..7b438a87db 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -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 e44290be31..150a230e9f 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -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 d3610a223f..e81a630183 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -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 4b189bd10f..f8d7e8e36f 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -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 76e9e62861..e963636646 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -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 1d94a70958..0b578899c8 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -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);
}
diff --git a/src/backend/utils/cache/fcache.c b/src/backend/utils/cache/fcache.c
index 3bcec9d11a..3bb7056616 100644
--- a/src/backend/utils/cache/fcache.c
+++ b/src/backend/utils/cache/fcache.c
@@ -70,7 +70,7 @@ init_fcache(Oid foid,
Form_pg_type typeStruct;
FunctionCachePtr retval;
int nargs;
- text *tmp;
+ Datum tmp;
bool isNull;
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
@@ -212,14 +212,14 @@ init_fcache(Oid foid,
if (procedureStruct->prolang == SQLlanguageId)
{
- tmp = (text *) SysCacheGetAttr(PROCOID,
- procedureTuple,
- Anum_pg_proc_prosrc,
- &isNull);
+ tmp = SysCacheGetAttr(PROCOID,
+ procedureTuple,
+ Anum_pg_proc_prosrc,
+ &isNull);
if (isNull)
elog(ERROR, "init_fcache: null prosrc for procedure %u",
foid);
- retval->src = textout(tmp);
+ retval->src = DatumGetCString(DirectFunctionCall1(textout, tmp));
retval->bin = (char *) NULL;
}
else
@@ -229,14 +229,14 @@ init_fcache(Oid foid,
retval->bin = (char *) NULL;
else
{
- tmp = (text *) SysCacheGetAttr(PROCOID,
- procedureTuple,
- Anum_pg_proc_probin,
- &isNull);
+ tmp = SysCacheGetAttr(PROCOID,
+ procedureTuple,
+ Anum_pg_proc_probin,
+ &isNull);
if (isNull)
elog(ERROR, "init_fcache: null probin for procedure %u",
foid);
- retval->bin = textout(tmp);
+ retval->bin = DatumGetCString(DirectFunctionCall1(textout, tmp));
}
}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index ed06fd0829..8b29bd4179 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1901,7 +1901,7 @@ AttrDefaultFetch(Relation relation)
IndexScanDesc sd = (IndexScanDesc) NULL;
HeapScanDesc adscan = (HeapScanDesc) NULL;
RetrieveIndexResult indexRes;
- struct varlena *val;
+ Datum val;
bool isnull;
int found;
int i;
@@ -1959,16 +1959,17 @@ AttrDefaultFetch(Relation relation)
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
RelationGetRelationName(relation));
- val = (struct varlena *) fastgetattr(htup,
- Anum_pg_attrdef_adbin,
- adrel->rd_att, &isnull);
+ val = fastgetattr(htup,
+ Anum_pg_attrdef_adbin,
+ adrel->rd_att, &isnull);
if (isnull)
elog(NOTICE, "AttrDefaultFetch: adbin IS NULL for attr %s in rel %s",
NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname),
RelationGetRelationName(relation));
else
attrdef[i].adbin = MemoryContextStrdup(CacheMemoryContext,
- textout(val));
+ DatumGetCString(DirectFunctionCall1(textout,
+ val)));
break;
}
if (hasindex)
@@ -2008,7 +2009,7 @@ RelCheckFetch(Relation relation)
HeapScanDesc rcscan = (HeapScanDesc) NULL;
RetrieveIndexResult indexRes;
Name rcname;
- struct varlena *val;
+ Datum val;
bool isnull;
int found;
bool hasindex;
@@ -2066,14 +2067,15 @@ RelCheckFetch(Relation relation)
RelationGetRelationName(relation));
check[found].ccname = MemoryContextStrdup(CacheMemoryContext,
NameStr(*rcname));
- val = (struct varlena *) fastgetattr(htup,
- Anum_pg_relcheck_rcbin,
- rcrel->rd_att, &isnull);
+ val = fastgetattr(htup,
+ Anum_pg_relcheck_rcbin,
+ rcrel->rd_att, &isnull);
if (isnull)
elog(ERROR, "RelCheckFetch: rcbin IS NULL for rel %s",
RelationGetRelationName(relation));
check[found].ccbin = MemoryContextStrdup(CacheMemoryContext,
- textout(val));
+ DatumGetCString(DirectFunctionCall1(textout,
+ val)));
found++;
if (hasindex)
ReleaseBuffer(buffer);
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index cf7a5ca42c..e589c41cda 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -71,21 +71,17 @@ fmgr_dynamic(Oid functionId)
prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
Anum_pg_proc_prosrc, &isnull);
- if (isnull || !PointerIsValid(prosrcattr))
- {
+ if (isnull)
elog(ERROR, "fmgr: Could not extract prosrc for %u from pg_proc",
functionId);
- }
- prosrcstring = textout((text *) DatumGetPointer(prosrcattr));
+ prosrcstring = DatumGetCString(DirectFunctionCall1(textout, prosrcattr));
probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
Anum_pg_proc_probin, &isnull);
- if (isnull || !PointerIsValid(probinattr))
- {
+ if (isnull)
elog(ERROR, "fmgr: Could not extract probin for %u from pg_proc",
functionId);
- }
- probinstring = textout((text *) DatumGetPointer(probinattr));
+ probinstring = DatumGetCString(DirectFunctionCall1(textout, probinattr));
user_fn = load_external_function(probinstring, prosrcstring);
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index b005520826..ae32bb8424 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -164,7 +164,8 @@ fmgr_info(Oid functionId, FmgrInfo *finfo)
* stored in prosrc (it doesn't have to be the same as the
* name of the alias!)
*/
- prosrc = textout(&(procedureStruct->prosrc));
+ prosrc = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procedureStruct->prosrc)));
fbp = fmgr_lookupByName(prosrc);
if (fbp == NULL)
elog(ERROR, "fmgr_info: function %s not in internal table",
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 868f28df09..17c59aa681 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -129,9 +129,9 @@ DATA(insert OID = 44 ( regprocin PGUID 12 f t f t 1 f 24 "0" 100 0 0 100
DESCR("(internal)");
DATA(insert OID = 45 ( regprocout PGUID 12 f t f t 1 f 23 "0" 100 0 0 100 regprocout - ));
DESCR("(internal)");
-DATA(insert OID = 46 ( textin PGUID 11 f t t t 1 f 25 "0" 100 0 0 100 textin - ));
+DATA(insert OID = 46 ( textin PGUID 12 f t t t 1 f 25 "0" 100 0 0 100 textin - ));
DESCR("(internal)");
-DATA(insert OID = 47 ( textout PGUID 11 f t t t 1 f 23 "0" 100 0 0 100 textout - ));
+DATA(insert OID = 47 ( textout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 textout - ));
DESCR("(internal)");
DATA(insert OID = 48 ( tidin PGUID 11 f t t t 1 f 27 "0" 100 0 0 100 tidin - ));
DESCR("(internal)");
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 7b3b234ae1..1f77f10217 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -436,8 +436,8 @@ extern int32 varcharlen(char *arg);
extern int32 varcharoctetlen(char *arg);
/* varlena.c */
-extern text *textin(char *inputText);
-extern char *textout(text *vlena);
+extern Datum textin(PG_FUNCTION_ARGS);
+extern Datum textout(PG_FUNCTION_ARGS);
extern text *textcat(text *arg1, text *arg2);
extern bool texteq(text *arg1, text *arg2);
extern bool textne(text *arg1, text *arg2);
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index cb4cf6894e..648b055913 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -594,8 +594,8 @@ plperl_func_handler(PG_FUNCTION_ARGS)
* through the reference.
*
************************************************************/
- proc_source = textout(&(procStruct->prosrc));
-
+ proc_source = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procStruct->prosrc)));
/************************************************************
* Create the procedure in the interpreter
@@ -789,7 +789,8 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
"}\n"
"unset i v\n\n", -1);
- proc_source = textout(&(procStruct->prosrc));
+ proc_source = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procStruct->prosrc)));
Tcl_DStringAppend(&proc_internal_body, proc_source, -1);
pfree(proc_source);
Tcl_DStringAppendElement(&proc_internal_def,
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index feb0161878..411ccfc6a4 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -142,7 +142,8 @@ plpgsql_compile(Oid fn_oid, int functype)
* ----------
*/
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
- proc_source = textout(&(procStruct->prosrc));
+ proc_source = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procStruct->prosrc)));
plpgsql_setinput(proc_source, functype);
plpgsql_error_funcname = nameout(&(procStruct->proname));
plpgsql_error_lineno = 0;
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 6cebae5696..11441563ec 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -606,7 +606,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
rec_new->tupdesc = trigdata->tg_relation->rd_att;
rec_old->tup = NULL;
rec_old->tupdesc = NULL;
- var->value = (Datum) textin("INSERT");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("INSERT"));
}
else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
{
@@ -614,7 +614,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
rec_new->tupdesc = trigdata->tg_relation->rd_att;
rec_old->tup = trigdata->tg_trigtuple;
rec_old->tupdesc = trigdata->tg_relation->rd_att;
- var->value = (Datum) textin("UPDATE");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("UPDATE"));
}
else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
{
@@ -622,13 +622,13 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
rec_new->tupdesc = NULL;
rec_old->tup = trigdata->tg_trigtuple;
rec_old->tupdesc = trigdata->tg_relation->rd_att;
- var->value = (Datum) textin("DELETE");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("DELETE"));
}
else
{
rec_new->tup = NULL;
rec_new->tupdesc = NULL;
- var->value = (Datum) textin("UNKNOWN");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("UNKNOWN"));
}
/* ----------
@@ -642,20 +642,20 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
var = (PLpgSQL_var *) (estate.datums[func->tg_when_varno]);
var->isnull = false;
if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
- var->value = (Datum) textin("BEFORE");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("BEFORE"));
else if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
- var->value = (Datum) textin("AFTER");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("AFTER"));
else
- var->value = (Datum) textin("UNKNOWN");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("UNKNOWN"));
var = (PLpgSQL_var *) (estate.datums[func->tg_level_varno]);
var->isnull = false;
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
- var->value = (Datum) textin("ROW");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("ROW"));
else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
- var->value = (Datum) textin("STATEMENT");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("STATEMENT"));
else
- var->value = (Datum) textin("UNKNOWN");
+ var->value = DirectFunctionCall1(textin, CStringGetDatum("UNKNOWN"));
var = (PLpgSQL_var *) (estate.datums[func->tg_relid_varno]);
var->isnull = false;
@@ -682,7 +682,8 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
{
estate.trig_argv = palloc(sizeof(Datum) * estate.trig_nargs);
for (i = 0; i < trigdata->tg_trigger->tgnargs; i++)
- estate.trig_argv[i] = (Datum) textin(trigdata->tg_trigger->tgargs[i]);
+ estate.trig_argv[i] = DirectFunctionCall1(textin,
+ CStringGetDatum(trigdata->tg_trigger->tgargs[i]));
}
/* ----------
@@ -1611,7 +1612,8 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt)
if (value < 0 || value >= estate->trig_nargs)
extval = "<OUT_OF_RANGE>";
else
- extval = textout((text *) (estate->trig_argv[value]));
+ extval = DatumGetCString(DirectFunctionCall1(textout,
+ estate->trig_argv[value]));
}
plpgsql_dstring_append(&ds, extval);
}
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 9ee18cc9b5..231eb23e9a 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -561,7 +561,8 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
sprintf(buf, "array set %d $__PLTcl_Tup_%d\n", i + 1, i + 1);
Tcl_DStringAppend(&proc_internal_body, buf, -1);
}
- proc_source = textout(&(procStruct->prosrc));
+ proc_source = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procStruct->prosrc)));
Tcl_DStringAppend(&proc_internal_body, proc_source, -1);
pfree(proc_source);
Tcl_DStringAppendElement(&proc_internal_def,
@@ -836,7 +837,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
"}\n"
"unset i v\n\n", -1);
- proc_source = textout(&(procStruct->prosrc));
+ proc_source = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(&procStruct->prosrc)));
Tcl_DStringAppend(&proc_internal_body, proc_source, -1);
pfree(proc_source);
Tcl_DStringAppendElement(&proc_internal_def,
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 971b58c6b9..13d6707249 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -524,7 +524,8 @@ ttdummy(PG_FUNCTION_ARGS)
}
{
- text *seqname = textin("ttdummy_seq");
+ text *seqname = DatumGetTextP(DirectFunctionCall1(textin,
+ CStringGetDatum("ttdummy_seq")));
newoff = DirectFunctionCall1(nextval,
PointerGetDatum(seqname));