diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-02-08 01:30:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-02-08 01:30:22 +0000 |
commit | 12bdb15e710104bb041add9f86a7f177112f78f6 (patch) | |
tree | bc4c29efe5986049002c03f8f04a0c95968716a9 /ruby.c | |
parent | c1db3a49a4c13370e7d814a1847e4fa54355d332 (diff) |
ruby.c: err ambiguous feature name [ci skip]
* ruby.c (feature_option): raise a runtime error if ambiguous
feature name is given, in the future. [Bug #12050]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -70,6 +70,7 @@ char *getenv(); X(rubyopt) \ X(frozen_string_literal) \ /* END OF FEATURES */ +#define AMBIGUOUS_FEATURE_NAMES 0 /* no ambiguous feature names now */ #define DEFINE_FEATURE(bit) feature_##bit, enum feature_flag_bits { EACH_FEATURES(DEFINE_FEATURE) @@ -756,14 +757,35 @@ feature_option(const char *str, int len, void *arg, const unsigned int enable) { unsigned int *argp = arg; unsigned int mask = ~0U; +#if AMBIGUOUS_FEATURE_NAMES + unsigned int set = 0U; + int matched = 0; +#define SET_FEATURE(bit) \ + if (NAME_MATCH_P(#bit, str, len)) {set |= mask = FEATURE_BIT(bit); ++matched;} +#else #define SET_FEATURE(bit) \ if (NAME_MATCH_P(#bit, str, len)) {mask = FEATURE_BIT(bit); goto found;} +#endif EACH_FEATURES(SET_FEATURE); if (NAME_MATCH_P("all", str, len)) { found: *argp = (*argp & ~mask) | (mask & enable); return; } +#if AMBIGUOUS_FEATURE_NAMES + if (matched == 1) goto found; + if (matched > 1) { + VALUE mesg = rb_sprintf("ambiguous feature: `%.*s' (", len, str); +#define ADD_FEATURE(bit) \ + if (FEATURE_BIT(bit) & set) { \ + rb_str_cat_cstr(mesg, #bit); \ + if (--matched) rb_str_cat_cstr(mesg, ", "); \ + } + EACH_FEATURES(ADD_FEATURE); + rb_str_cat_cstr(mesg, ")"); + rb_exc_raise(rb_exc_new_str(rb_eRuntimeError, mesg)); + } +#endif rb_warn("unknown argument for --%s: `%.*s'", enable ? "enable" : "disable", len, str); rb_warn("features are [gems, did-you-mean, rubyopt, frozen-string-literal]."); |