Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 741364b

Browse files
committed
Code review for commit d26888b.
Mostly, copy-edit the comments; but also fix it to not reject domains over arrays.
1 parent 42c6236 commit 741364b

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/backend/parser/parse_func.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
559559
* If it's a variadic function call, transform the last nvargs arguments
560560
* into an array --- unless it's an "any" variadic.
561561
*/
562-
if (nvargs > 0 && declared_arg_types[nargs - 1] != ANYOID)
562+
if (nvargs > 0 && vatype != ANYOID)
563563
{
564564
ArrayExpr *newa = makeNode(ArrayExpr);
565565
int non_var_args = nargs - nvargs;
@@ -587,19 +587,19 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
587587
}
588588

589589
/*
590-
* When function is called with an explicit VARIADIC labeled parameter,
591-
* and the declared_arg_type is "any", then sanity check the actual
592-
* parameter type now - it must be an array.
590+
* If an "any" variadic is called with explicit VARIADIC marking, insist
591+
* that the variadic parameter be of some array type.
593592
*/
594593
if (nargs > 0 && vatype == ANYOID && func_variadic)
595594
{
596-
Oid va_arr_typid = actual_arg_types[nargs - 1];
595+
Oid va_arr_typid = actual_arg_types[nargs - 1];
597596

598-
if (!OidIsValid(get_element_type(va_arr_typid)))
597+
if (!OidIsValid(get_base_element_type(va_arr_typid)))
599598
ereport(ERROR,
600599
(errcode(ERRCODE_DATATYPE_MISMATCH),
601600
errmsg("VARIADIC argument must be an array"),
602-
parser_errposition(pstate, exprLocation((Node *) llast(fargs)))));
601+
parser_errposition(pstate,
602+
exprLocation((Node *) llast(fargs)))));
603603
}
604604

605605
/* build the appropriate output structure */
@@ -1253,6 +1253,7 @@ func_get_detail(List *funcname,
12531253
*rettype = InvalidOid;
12541254
*retset = false;
12551255
*nvargs = 0;
1256+
*vatype = InvalidOid;
12561257
*true_typeids = NULL;
12571258
if (argdefaults)
12581259
*argdefaults = NIL;
@@ -1364,6 +1365,7 @@ func_get_detail(List *funcname,
13641365
*rettype = targetType;
13651366
*retset = false;
13661367
*nvargs = 0;
1368+
*vatype = InvalidOid;
13671369
*true_typeids = argtypes;
13681370
return FUNCDETAIL_COERCION;
13691371
}

src/backend/utils/adt/varlena.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,16 +3834,15 @@ concat_internal(const char *sepstr, int argidx,
38343834
return NULL;
38353835

38363836
/*
3837-
* Non-null argument had better be an array
3838-
*
3839-
* Correct values are ensured by parser check, but this function
3840-
* can be called directly, bypassing the parser, so we should do
3841-
* some minimal check too - this form of call requires correctly set
3842-
* expr argtype in flinfo.
3837+
* Non-null argument had better be an array. We assume that any call
3838+
* context that could let get_fn_expr_variadic return true will have
3839+
* checked that a VARIADIC-labeled parameter actually is an array. So
3840+
* it should be okay to just Assert that it's an array rather than
3841+
* doing a full-fledged error check.
38433842
*/
3844-
Assert(OidIsValid(get_fn_expr_argtype(fcinfo->flinfo, argidx)));
3845-
Assert(OidIsValid(get_element_type(get_fn_expr_argtype(fcinfo->flinfo, argidx))));
3843+
Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo, argidx))));
38463844

3845+
/* OK, safe to fetch the array value */
38473846
arr = PG_GETARG_ARRAYTYPE_P(argidx);
38483847

38493848
/*
@@ -4063,16 +4062,15 @@ text_format(PG_FUNCTION_ARGS)
40634062
else
40644063
{
40654064
/*
4066-
* Non-null argument had better be an array
4067-
*
4068-
* Correct values are ensured by parser check, but this function
4069-
* can be called directly, bypassing the parser, so we should do
4070-
* some minimal check too - this form of call requires correctly set
4071-
* expr argtype in flinfo.
4065+
* Non-null argument had better be an array. We assume that any
4066+
* call context that could let get_fn_expr_variadic return true
4067+
* will have checked that a VARIADIC-labeled parameter actually is
4068+
* an array. So it should be okay to just Assert that it's an
4069+
* array rather than doing a full-fledged error check.
40724070
*/
4073-
Assert(OidIsValid(get_fn_expr_argtype(fcinfo->flinfo, 1)));
4074-
Assert(OidIsValid(get_element_type(get_fn_expr_argtype(fcinfo->flinfo, 1))));
4071+
Assert(OidIsValid(get_base_element_type(get_fn_expr_argtype(fcinfo->flinfo, 1))));
40754072

4073+
/* OK, safe to fetch the array value */
40764074
arr = PG_GETARG_ARRAYTYPE_P(1);
40774075

40784076
/* Get info about array element type */

0 commit comments

Comments
 (0)