From b15f76556f9da3e17a9f17c97c9b611524a8d509 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Sep 2016 06:23:36 +0000 Subject: [PATCH] iseq.c: kwarg to compile * iseq.c (iseqw_s_compile, iseqw_s_compile_file): allow keyword arguments as the options. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/iseq.c b/iseq.c index 425850bde2..4f8fc29154 100644 --- a/iseq.c +++ b/iseq.c @@ -781,9 +781,18 @@ static VALUE iseqw_s_compile(int argc, VALUE *argv, VALUE self) { VALUE src, file = Qnil, path = Qnil, line = INT2FIX(1), opt = Qnil; + int i; + rb_secure(1); - rb_scan_args(argc, argv, "14", &src, &file, &path, &line, &opt); + i = rb_scan_args(argc, argv, "1*:", &src, NULL, &opt); + if (i > 4+NIL_P(opt)) rb_error_arity(argc, 1, 5); + switch (i) { + case 5: opt = argv[--i]; + case 4: line = argv[--i]; + case 3: path = argv[--i]; + case 2: file = argv[--i]; + } if (NIL_P(file)) file = rb_fstring_cstr(""); if (NIL_P(line)) line = INT2FIX(1); @@ -818,9 +827,14 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self) VALUE f; NODE *node; rb_compile_option_t option; + int i; rb_secure(1); - rb_scan_args(argc, argv, "11", &file, &opt); + i = rb_scan_args(argc, argv, "1*:", &file, NULL, &opt); + if (i > 1+NIL_P(opt)) rb_error_arity(argc, 1, 2); + switch (i) { + case 2: opt = argv[--i]; + } FilePathValue(file); file = rb_fstring(file); /* rb_io_t->pathv gets frozen anyways */