diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-15 16:51:57 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:43 -0400 |
commit | 11096da6cc655b301b91e985e9ba1bad748e91bf (patch) | |
tree | 2fe798797e627cc55738f4352ac17f3174ff93bb /ruby.c | |
parent | d11ea2520e24fdc7114a6400f00c96d241665bff (diff) |
Improve YJIT command line option parsing
Previously, options such as "--yjit123" would enable YJIT. Additionally,
the error message for argument parsing mentioned "--jit-..." instead of
"--yjit-...".
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -1050,31 +1050,44 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen #define opt_match_arg(s, l, name) \ opt_match(s, l, name) && (*(s) ? 1 : (rb_raise(rb_eRuntimeError, "--jit-" name " needs an argument"), 0)) -static void +#define yjit_opt_match_noarg(s, l, name) \ + opt_match(s, l, name) && (*(s) ? (rb_warn("argument to --yjit-" name " is ignored"), 1) : 1) +#define yjit_opt_match_arg(s, l, name) \ + opt_match(s, l, name) && (*(s) && *(s+1) ? 1 : (rb_raise(rb_eRuntimeError, "--yjit-" name " needs an argument"), 0)) + +static bool setup_yjit_options(const char *s, struct rb_yjit_options *yjit_opt) { - if (*s != '-') return; - const size_t l = strlen(++s); + const char prefix[] = "yjit-"; + if (strncmp(prefix, s, sizeof(prefix)-1) != 0) { + return false; + } + s += sizeof(prefix)-1; + const size_t l = strlen(s); + if (l == 0) { + return false; + } - if (opt_match_arg(s, l, "exec-mem-size")) { + if (yjit_opt_match_arg(s, l, "exec-mem-size")) { yjit_opt->exec_mem_size = atoi(s + 1); } - else if (opt_match_arg(s, l, "call-threshold")) { + else if (yjit_opt_match_arg(s, l, "call-threshold")) { yjit_opt->call_threshold = atoi(s + 1); } - else if (opt_match_arg(s, l, "max-versions")) { + else if (yjit_opt_match_arg(s, l, "max-versions")) { yjit_opt->max_versions = atoi(s + 1); } - else if (opt_match_noarg(s, l, "greedy-versioning")) { + else if (yjit_opt_match_noarg(s, l, "greedy-versioning")) { yjit_opt->greedy_versioning = true; } - else if (opt_match_noarg(s, l, "stats")) { + else if (yjit_opt_match_noarg(s, l, "stats")) { yjit_opt->gen_stats = true; } else { rb_raise(rb_eRuntimeError, "invalid yjit option `%s' (--help will show valid yjit options)", s); } + return true; } #if USE_MJIT @@ -1490,9 +1503,8 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) rb_warn("MJIT support is disabled."); #endif } - else if (strncmp("yjit", s, 4) == 0) { + else if (strcmp("yjit", s) == 0 || setup_yjit_options(s, &opt->yjit)) { FEATURE_SET(opt->features, FEATURE_BIT(yjit)); - setup_yjit_options(s + 4, &opt->yjit); } else if (strcmp("yydebug", s) == 0) { if (envopt) goto noenvopt_long; |