-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/06/2015 12:39 AM, Michael Paquier wrote:
>> Yeah, particularly the use of first_optarg makes things harder
>> to follow in the code with this patch. A C wrapper has the
>> disadvantage to decentralize the argument checks to many places
>> making the flow harder to follow hence using
>> get_fn_expr_argtype() with PG_NARGS would be the way to go, at
>> least to me. This way, you can easily find how many arguments
>> there are, and which value is assigned to which variable before
>> moving on to the real processing.
>
> Just to be clear I mean that: if (PG_NARGS() == 5) { if
> (get_fn_expr_argtype(fcinfo->flinfo, 1) == TYPEOID) var =
> PG_GETARG_BOOL(1) [...]
Actually, I had in mind something like:
8<---------------------
int i;
int numargs;
int *argtypes;
numargs = PG_NARGS();
argtypes = palloc(numargs * sizeof(int));
for (i = 0; i < numargs; i++) argtypes[i] = get_fn_expr_argtype(fcinfo->flinfo, i);
if ((numargs == 4 || numargs == 5) && argtypes[0] == TEXTOID && argtypes[1] == TEXTOID && argtypes[2] == INT4OID
&& argtypes[3] == BOOLOID)
{ [...]
}
else if ((numargs == 3 || numargs == 4) && argtypes[0] == TEXTOID && argtypes[1] == INT4OID && argtypes[2] ==
BOOLOID)
{ [...]
8<---------------------
etc.
If the highest number of arguments is always checked first, the
pattern is not ambiguous even with the extra anyelement.
- --
Joe Conway
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBAgAGBQJVmovZAAoJEDfy90M199hlzDsP/j/v76Ecv3VtZ+02Lo9mUVp6
mf+ZTLgw2OE4sNI6PL2MeVzu5ayZAkHxPRAah9rR1A7nDNEyZovi3dymFRHeiJ6Z
rowjkdZiRX/xlV5s6RHrdmX6DkVkBeGcKMuIKB/Tud2uPCiuBULkcUuD1OvlxsCs
W0E+hsuYmpGtsH8Vth+ciKiBUDX/BVWCOnqZXISRf6BZ5BjzITOEuCyn4EChx2o4
9gOGPTf3P/4I3buuDuV+DEmO1N4L07VvSWb9e92NrdS3VI1ae8YJu3u248WVmdPY
+qHg0J7jLGYBFRZ+isC7p8OX7PANCm88GvMCqklZdPo+/76n4J6x5MJfjinQEfXN
rbScwRh3O1DCimw404WqYSGKGEcX7MtUt98h+//nMft3aEz1gRnsuopnM/eRmQcS
wYlbBYon5YEdamx2o5AP6NX5zFU+6HBcKcznCFQtcsaJeh03yz9zILuCWxg4dWNj
T5aVCYu58PN4ELKP3yF5wN2UUSE4/OZJHgvIrHF8LiDOSdygvfADdUAmfD0sry48
tjbL9GC7JwHxqQ8qYktDMogxZo+s3TBsmw3NsnYXrNYwObbGCP9J0K0zV76ukMEc
V1qiMXD4/gddkKXJz0cVfcActrDqEltKDPTCdhLpoc4Gb59mrohgk+j75f2af14V
+n/AvaymgwdKjQpBhaTb
=tESF
-----END PGP SIGNATURE-----