[前][次][番号順一覧][スレッド一覧]

ruby-changes:39840

From: nobu <ko1@a...>
Date: Wed, 23 Sep 2015 23:44:01 +0900 (JST)
Subject: [ruby-changes:39840] nobu:r51921 (trunk): ruby.c: feature bits

nobu	2015-09-23 23:43:45 +0900 (Wed, 23 Sep 2015)

  New Revision: 51921

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51921

  Log:
    ruby.c: feature bits
    
    * ruby.c (enum feature_flag_bits, struct cmdline_options): turn
      negative logic disable bits into positive logic feature bits.

  Modified files:
    trunk/ruby.c
Index: ruby.c
===================================================================
--- ruby.c	(revision 51920)
+++ ruby.c	(revision 51921)
@@ -59,12 +59,12 @@ char *getenv(); https://github.com/ruby/ruby/blob/trunk/ruby.c#L59
 #define DEFAULT_RUBYGEMS_ENABLED "enabled"
 #endif
 
-#define DISABLE_BIT(bit) (1U << disable_##bit)
-enum disable_flag_bits {
-    disable_gems,
-    disable_did_you_mean,
-    disable_rubyopt,
-    disable_flag_count
+#define FEATURE_BIT(bit) (1U << feature_##bit)
+enum feature_flag_bits {
+    feature_gems,
+    feature_did_you_mean,
+    feature_rubyopt,
+    feature_flag_count
 };
 
 #define DUMP_BIT(bit) (1U << dump_##bit)
@@ -87,7 +87,7 @@ struct cmdline_options { https://github.com/ruby/ruby/blob/trunk/ruby.c#L87
     int do_loop, do_print;
     int do_line, do_split;
     int do_search;
-    unsigned int disable;
+    unsigned int features;
     int verbose;
     int safe_level;
     unsigned int setids;
@@ -116,8 +116,9 @@ cmdline_options_init(struct cmdline_opti https://github.com/ruby/ruby/blob/trunk/ruby.c#L116
     opt->src.enc.index = src_encoding_index;
     opt->ext.enc.index = -1;
     opt->intern.enc.index = -1;
+    opt->features = ~0U;
 #if DISABLE_RUBYGEMS
-    opt->disable |= DISABLE_BIT(gems);
+    opt->features &= ~FEATURE_BIT(gems);
 #endif
     return opt;
 }
@@ -710,12 +711,12 @@ moreswitches(const char *s, struct cmdli https://github.com/ruby/ruby/blob/trunk/ruby.c#L711
 static void
 enable_option(const char *str, int len, void *arg)
 {
-#define UNSET_WHEN_DISABLE(bit) UNSET_WHEN(#bit, DISABLE_BIT(bit), str, len)
-    UNSET_WHEN_DISABLE(gems);
-    UNSET_WHEN_DISABLE(did_you_mean);
-    UNSET_WHEN_DISABLE(rubyopt);
+#define SET_WHEN_ENABLE(bit) SET_WHEN(#bit, FEATURE_BIT(bit), str, len)
+    SET_WHEN_ENABLE(gems);
+    SET_WHEN_ENABLE(did_you_mean);
+    SET_WHEN_ENABLE(rubyopt);
     if (NAME_MATCH_P("all", str, len)) {
-	*(unsigned int *)arg = 0U;
+	*(unsigned int *)arg = ~0U;
 	return;
     }
     rb_warn("unknown argument for --enable: `%.*s'", len, str);
@@ -724,12 +725,12 @@ enable_option(const char *str, int len, https://github.com/ruby/ruby/blob/trunk/ruby.c#L725
 static void
 disable_option(const char *str, int len, void *arg)
 {
-#define SET_WHEN_DISABLE(bit) SET_WHEN(#bit, DISABLE_BIT(bit), str, len)
-    SET_WHEN_DISABLE(gems);
-    SET_WHEN_DISABLE(did_you_mean);
-    SET_WHEN_DISABLE(rubyopt);
+#define UNSET_WHEN_DISABLE(bit) UNSET_WHEN(#bit, FEATURE_BIT(bit), str, len)
+    UNSET_WHEN_DISABLE(gems);
+    UNSET_WHEN_DISABLE(did_you_mean);
+    UNSET_WHEN_DISABLE(rubyopt);
     if (NAME_MATCH_P("all", str, len)) {
-	*(unsigned int *)arg = ~0U;
+	*(unsigned int *)arg = 0U;
 	return;
     }
     rb_warn("unknown argument for --disable: `%.*s'", len, str);
@@ -1065,10 +1066,10 @@ proc_options(long argc, char **argv, str https://github.com/ruby/ruby/blob/trunk/ruby.c#L1066
                 ruby_verbose = Qtrue;
             }
 	    else if (is_option_with_arg("enable", Qtrue, Qtrue)) {
-		ruby_each_words(s, enable_option, &opt->disable);
+		ruby_each_words(s, enable_option, &opt->features);
 	    }
 	    else if (is_option_with_arg("disable", Qtrue, Qtrue)) {
-		ruby_each_words(s, disable_option, &opt->disable);
+		ruby_each_words(s, disable_option, &opt->features);
 	    }
 	    else if (is_option_with_arg("encoding", Qfalse, Qtrue)) {
 		char *p;
@@ -1324,7 +1325,7 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1325
 	return Qtrue;
     }
 
-    if (!(opt->disable & DISABLE_BIT(rubyopt)) &&
+    if ((opt->features & FEATURE_BIT(rubyopt)) &&
 	opt->safe_level == 0 && (s = getenv("RUBYOPT"))) {
 	VALUE src_enc_name = opt->src.enc.name;
 	VALUE ext_enc_name = opt->ext.enc.name;
@@ -1436,10 +1437,10 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1437
 	}
     }
     Init_ext();		/* load statically linked extensions before rubygems */
-    if (!(opt->disable & DISABLE_BIT(gems))) {
+    if (opt->features & FEATURE_BIT(gems)) {
 	rb_define_module("Gem");
     }
-    if (!(opt->disable & DISABLE_BIT(did_you_mean))) {
+    if (opt->features & FEATURE_BIT(did_you_mean)) {
 	rb_define_module("DidYouMean");
     }
     ruby_init_prelude();

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]