aboutsummaryrefslogtreecommitdiff
path: root/contrib/array/array_iterator.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-05-29 20:30:11 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-05-29 20:30:11 +0000
commit8a098f2f5dbd280275f4d966fe99f47abffb70c8 (patch)
tree073d3aee4f55cf3fb6cb56070fc9a35427c5138e /contrib/array/array_iterator.c
parenta030113197005635bb6b36203f67b777ca086e22 (diff)
downloadpostgresql-8a098f2f5dbd280275f4d966fe99f47abffb70c8.tar.gz
postgresql-8a098f2f5dbd280275f4d966fe99f47abffb70c8.zip
Update array_iterator to use new fmgr interface.
Diffstat (limited to 'contrib/array/array_iterator.c')
-rw-r--r--contrib/array/array_iterator.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/contrib/array/array_iterator.c b/contrib/array/array_iterator.c
index 3bee2e468a1..447d5c6443e 100644
--- a/contrib/array/array_iterator.c
+++ b/contrib/array/array_iterator.c
@@ -38,16 +38,13 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
Form_pg_type typ_struct;
bool typbyval;
int typlen;
- func_ptr proc_fn;
- int pronargs;
int nitems,
- i,
- result;
+ i;
+ Datum result;
int ndim,
*dim;
char *p;
- FmgrInfo finf; /* Tobias Gabele Jan 18 1999 */
-
+ FmgrInfo finfo;
/* Sanity checks */
if ((array == (ArrayType *) NULL)
@@ -66,7 +63,8 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
}
/* Lookup element type information */
- typ_tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(elemtype), 0, 0, 0);
+ typ_tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(elemtype),
+ 0, 0, 0);
if (!HeapTupleIsValid(typ_tuple))
{
elog(ERROR, "array_iterator: cache lookup failed for type %u", elemtype);
@@ -77,18 +75,15 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
typbyval = typ_struct->typbyval;
/* Lookup the function entry point */
- proc_fn = (func_ptr) NULL;
- fmgr_info(proc, &finf); /* Tobias Gabele Jan 18 1999 */
- proc_fn = finf.fn_addr; /* Tobias Gabele Jan 18 1999 */
- pronargs = finf.fn_nargs; /* Tobias Gabele Jan 18 1999 */
- if ((proc_fn == NULL) || (pronargs != 2))
+ fmgr_info(proc, &finfo);
+ if (finfo.fn_nargs != 2)
{
- elog(ERROR, "array_iterator: fmgr_info lookup failed for oid %u", proc);
+ elog(ERROR, "array_iterator: proc %u does not take 2 args", proc);
return (0);
}
/* Scan the array and apply the operator to each element */
- result = 0;
+ result = BoolGetDatum(false);
p = ARR_DATA_PTR(array);
for (i = 0; i < nitems; i++)
{
@@ -97,27 +92,33 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
switch (typlen)
{
case 1:
- result = (int) (*proc_fn) (*p, value);
+ result = FunctionCall2(&finfo,
+ CharGetDatum(*p),
+ value);
break;
case 2:
- result = (int) (*proc_fn) (*(int16 *) p, value);
+ result = FunctionCall2(&finfo,
+ Int16GetDatum(*(int16 *) p),
+ value);
break;
case 3:
case 4:
- result = (int) (*proc_fn) (*(int32 *) p, value);
+ result = FunctionCall2(&finfo,
+ Int32GetDatum(*(int32 *) p),
+ value);
break;
}
p += typlen;
}
else
{
- result = (int) (*proc_fn) (p, value);
+ result = FunctionCall2(&finfo, PointerGetDatum(p), value);
if (typlen > 0)
p += typlen;
else
p += INTALIGN(*(int32 *) p);
}
- if (result)
+ if (DatumGetBool(result))
{
if (!and)
return (1);
@@ -129,7 +130,7 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
}
}
- if (and && result)
+ if (and && DatumGetBool(result))
return (1);
else
return (0);