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
This commit is contained in:
nobu 2016-02-08 01:30:22 +00:00
Родитель c1db3a49a4
Коммит 12bdb15e71
2 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Feb 8 10:30:10 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (feature_option): raise a runtime error if ambiguous
feature name is given, in the future. [Bug #12050]
Mon Feb 8 09:43:57 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
* common.mk: Removed enc/unicode/casefold.h from automatic build because

22
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].");