aboutsummaryrefslogtreecommitdiffstats
path: root/interpret.h
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-12-06 22:06:26 +0200
committerArnold D. Robbins <arnold@skeeve.com>2016-12-06 22:06:26 +0200
commitf2b6d100d8958a9c811c950f113a0ce38a25d484 (patch)
tree53c03280dab7f88134bbcdad1279f13cf12b0cf6 /interpret.h
parent0dd8054d05d8286f2f7cbcf85456c6953a9b6146 (diff)
downloadegawk-f2b6d100d8958a9c811c950f113a0ce38a25d484.tar.gz
egawk-f2b6d100d8958a9c811c950f113a0ce38a25d484.tar.bz2
egawk-f2b6d100d8958a9c811c950f113a0ce38a25d484.zip
Add min_required and max_expected arg counts to API.
Diffstat (limited to 'interpret.h')
-rw-r--r--interpret.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/interpret.h b/interpret.h
index da8e0604..2cefc14c 100644
--- a/interpret.h
+++ b/interpret.h
@@ -956,8 +956,21 @@ arrayfor:
case Op_ext_builtin:
{
int arg_count = pc->expr_count;
+ int min_req = pc[1].min_required;
+ int max_expect = pc[1].max_expected;
awk_value_t result;
+ if (min_req == 0 && max_expect == 0 && arg_count > min_req)
+ fatal(_("%s: cannot be called with arguments"), pc[1].func_name);
+
+ if (min_req > 0 && arg_count < min_req)
+ fatal(_("%s: expects at least %d arguments, called with %d arguments"),
+ pc[1].func_name, min_req, arg_count);
+
+ if (do_lint && arg_count > max_expect)
+ lintwarn(_("%s: called with %d arguments, only expecting %d"),
+ pc[1].func_name, arg_count, max_expect);
+
PUSH_CODE(pc);
r = awk_value_to_node(pc->extfunc(arg_count, & result));
(void) POP_CODE();
@@ -1093,7 +1106,8 @@ match_re:
npc[0].expr_count = arg_count; /* actual argument count */
npc[1] = pc[1];
npc[1].func_name = fname; /* name of the builtin */
- npc[1].expr_count = bc->expr_count; /* defined max # of arguments */
+ npc[1].min_required = bc->min_required;
+ npc[1].max_expected = bc->max_expected;
ni = npc;
JUMPTO(ni);
} else