mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
vm.c: generalize pre-dispatch argument count check for C methods
Replace check_method_noarg() with check_argument_count() that validates min <= argc <= max using the full aspec stored in mrb_method_t.flags. This catches ArgumentError earlier at dispatch time, before entering the C function. The old check only handled the special case of aspec==0 (NOARG). The new check extracts REQ, OPT, REST, POST, KEY, and KDICT from the aspec and validates accordingly. Keyword hash is counted as a positional arg only when the method doesn't accept keywords. Remove MRB_METHOD_NOARG_P macro from proc.h (subsumed by aspec check). Fix 15 incorrect aspec declarations across the codebase that were exposed by the stricter enforcement. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1564,7 +1564,7 @@ static const mrb_mt_entry array_ext_rom_entries[] = {
|
||||
MRB_MT_ENTRY(ary_fetch, MRB_SYM(__fetch), MRB_ARGS_REQ(3)),
|
||||
MRB_MT_ENTRY(ary_insert, MRB_SYM(insert), MRB_ARGS_ARG(1,-1)),
|
||||
MRB_MT_ENTRY(ary_deconstruct, MRB_SYM(deconstruct), MRB_ARGS_NONE()),
|
||||
MRB_MT_ENTRY(ary_product_group, MRB_SYM(__product_group), MRB_ARGS_REQ(4)),
|
||||
MRB_MT_ENTRY(ary_product_group, MRB_SYM(__product_group), MRB_ARGS_REQ(3)),
|
||||
MRB_MT_ENTRY(ary_combination_init, MRB_SYM(__combination_init), MRB_ARGS_REQ(2)),
|
||||
MRB_MT_ENTRY(ary_combination_next, MRB_SYM(__combination_next), MRB_ARGS_REQ(1)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user