aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-08 01:30:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-08 01:30:22 +0000
commit930637983c8cfbc5a1418c95944ecbc78a3920ef (patch)
treebc4c29efe5986049002c03f8f04a0c95968716a9 /ruby.c
parentc82f51c0ce7e85a3092ab21ba684058b8f255fde (diff)
downloadruby-930637983c8cfbc5a1418c95944ecbc78a3920ef.tar.gz
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.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/ruby.c b/ruby.c
index 25a55a5c87..a06d88cc3a 100644
--- a/ruby.c
+++ b/ruby.c
@@ -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].");