Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a098f2

Browse files
committed
Update array_iterator to use new fmgr interface.
1 parenta030113 commit8a098f2

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_typetyp_struct;
3939
booltypbyval;
4040
inttyplen;
41-
func_ptrproc_fn;
42-
intpronargs;
4341
intnitems,
44-
i,
45-
result;
42+
i;
43+
Datumresult;
4644
intndim,
4745
*dim;
4846
char*p;
49-
FmgrInfofinf;/* Tobias Gabele Jan 18 1999 */
50-
47+
FmgrInfofinfo;
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
case1:
100-
result= (int) (*proc_fn) (*p,value);
95+
result=FunctionCall2(&finfo,
96+
CharGetDatum(*p),
97+
value);
10198
break;
10299
case2:
103-
result= (int) (*proc_fn) (*(int16*)p,value);
100+
result=FunctionCall2(&finfo,
101+
Int16GetDatum(*(int16*)p),
102+
value);
104103
break;
105104
case3:
106105
case4:
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)

[8]ページ先頭

©2009-2025 Movatter.jp