Skip to content

Commit 8a098f2

Browse files
committed
Update array_iterator to use new fmgr interface.
1 parent a030113 commit 8a098f2

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

contrib/array/array_iterator.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
3838
Form_pg_type typ_struct;
3939
bool typbyval;
4040
int typlen;
41-
func_ptr proc_fn;
42-
int pronargs;
4341
int nitems,
44-
i,
45-
result;
42+
i;
43+
Datum result;
4644
int ndim,
4745
*dim;
4846
char *p;
49-
FmgrInfo finf; /* Tobias Gabele Jan 18 1999 */
50-
47+
FmgrInfo finfo;
5148

5249
/* Sanity checks */
5350
if ((array == (ArrayType *) NULL)
@@ -66,7 +63,8 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
6663
}
6764

6865
/* Lookup element type information */
69-
typ_tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(elemtype), 0, 0, 0);
66+
typ_tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(elemtype),
67+
0, 0, 0);
7068
if (!HeapTupleIsValid(typ_tuple))
7169
{
7270
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)
7775
typbyval = typ_struct->typbyval;
7876

7977
/* Lookup the function entry point */
80-
proc_fn = (func_ptr) NULL;
81-
fmgr_info(proc, &finf); /* Tobias Gabele Jan 18 1999 */
82-
proc_fn = finf.fn_addr; /* Tobias Gabele Jan 18 1999 */
83-
pronargs = finf.fn_nargs; /* Tobias Gabele Jan 18 1999 */
84-
if ((proc_fn == NULL) || (pronargs != 2))
78+
fmgr_info(proc, &finfo);
79+
if (finfo.fn_nargs != 2)
8580
{
86-
elog(ERROR, "array_iterator: fmgr_info lookup failed for oid %u", proc);
81+
elog(ERROR, "array_iterator: proc %u does not take 2 args", proc);
8782
return (0);
8883
}
8984

9085
/* Scan the array and apply the operator to each element */
91-
result = 0;
86+
result = BoolGetDatum(false);
9287
p = ARR_DATA_PTR(array);
9388
for (i = 0; i < nitems; i++)
9489
{
@@ -97,27 +92,33 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
9792
switch (typlen)
9893
{
9994
case 1:
100-
result = (int) (*proc_fn) (*p, value);
95+
result = FunctionCall2(&finfo,
96+
CharGetDatum(*p),
97+
value);
10198
break;
10299
case 2:
103-
result = (int) (*proc_fn) (*(int16 *) p, value);
100+
result = FunctionCall2(&finfo,
101+
Int16GetDatum(*(int16 *) p),
102+
value);
104103
break;
105104
case 3:
106105
case 4:
107-
result = (int) (*proc_fn) (*(int32 *) p, value);
106+
result = FunctionCall2(&finfo,
107+
Int32GetDatum(*(int32 *) p),
108+
value);
108109
break;
109110
}
110111
p += typlen;
111112
}
112113
else
113114
{
114-
result = (int) (*proc_fn) (p, value);
115+
result = FunctionCall2(&finfo, PointerGetDatum(p), value);
115116
if (typlen > 0)
116117
p += typlen;
117118
else
118119
p += INTALIGN(*(int32 *) p);
119120
}
120-
if (result)
121+
if (DatumGetBool(result))
121122
{
122123
if (!and)
123124
return (1);
@@ -129,7 +130,7 @@ array_iterator(Oid elemtype, Oid proc, int and, ArrayType *array, Datum value)
129130
}
130131
}
131132

132-
if (and && result)
133+
if (and && DatumGetBool(result))
133134
return (1);
134135
else
135136
return (0);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy