1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Improved error messages for mjit option

and default jit-verbose to 1 if no argument.
This commit is contained in:
Nobuyoshi Nakada 2020-06-23 09:34:18 +09:00
parent c3ba2db48b
commit 9ce2066209
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

41
ruby.c
View file

@ -1005,34 +1005,45 @@ set_option_encoding_once(const char *type, VALUE *name, const char *e, long elen
static void static void
setup_mjit_options(const char *s, struct mjit_options *mjit_opt) setup_mjit_options(const char *s, struct mjit_options *mjit_opt)
{ {
#define opt_match(s, l, name) \
((((l) > rb_strlen_lit(name)) ? (s)[rb_strlen_lit(name)] == '=' : \
(l) == rb_strlen_lit(name)) && \
memcmp((s), name, rb_strlen_lit(name)) == 0 && \
(((s) += rb_strlen_lit(name)), 1))
#define opt_match_noarg(s, l, name) \
opt_match(s, l, name) && (*(s) ? (rb_warn("argument to --jit-" name " is ignored"), 1) : 1)
#define opt_match_arg(s, l, name) \
opt_match(s, l, name) && (*(s) ? 1 : (rb_raise(rb_eRuntimeError, "--jit-" name " needs an argument"), 0))
if (*s != '-') return;
const size_t l = strlen(++s);
if (*s == 0) return; if (*s == 0) return;
else if (strcmp(s, "-warnings") == 0) { else if (opt_match_noarg(s, l, "warnings")) {
mjit_opt->warnings = 1; mjit_opt->warnings = 1;
} }
else if (strncmp(s, "-debug=", 7) == 0) { else if (opt_match(s, l, "debug")) {
mjit_opt->debug_flags = strdup(s + 7); if (*s)
mjit_opt->debug_flags = strdup(s + 1);
else
mjit_opt->debug = 1;
} }
else if (strcmp(s, "-debug") == 0) { else if (opt_match_noarg(s, l, "wait")) {
mjit_opt->debug = 1;
}
else if (strcmp(s, "-wait") == 0) {
mjit_opt->wait = 1; mjit_opt->wait = 1;
} }
else if (strcmp(s, "-save-temps") == 0) { else if (opt_match_noarg(s, l, "save-temps")) {
mjit_opt->save_temps = 1; mjit_opt->save_temps = 1;
} }
else if (strncmp(s, "-verbose=", 9) == 0) { else if (opt_match(s, l, "verbose")) {
mjit_opt->verbose = atoi(s + 9); mjit_opt->verbose = *s ? atoi(s + 1) : 1;
} }
else if (strncmp(s, "-max-cache=", 11) == 0) { else if (opt_match_arg(s, l, "max-cache")) {
mjit_opt->max_cache_size = atoi(s + 11); mjit_opt->max_cache_size = atoi(s + 1);
} }
else if (strncmp(s, "-min-calls=", 11) == 0) { else if (opt_match_arg(s, l, "min-calls")) {
mjit_opt->min_calls = atoi(s + 11); mjit_opt->min_calls = atoi(s + 1);
} }
else { else {
rb_raise(rb_eRuntimeError, rb_raise(rb_eRuntimeError,
"invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1); "invalid MJIT option `%s' (--help will show valid MJIT options)", s);
} }
} }
#endif #endif