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

ruby-changes:26678

From: shugo <ko1@a...>
Date: Mon, 7 Jan 2013 20:24:33 +0900 (JST)
Subject: [ruby-changes:26678] shugo:r38729 (trunk): * eval.c (Init_eval): enable Refinements by default.

shugo	2013-01-07 20:22:31 +0900 (Mon, 07 Jan 2013)

  New Revision: 38729

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

  Log:
    * eval.c (Init_eval): enable Refinements by default.
      [ruby-core:51286] [Bug #7667]
    
    * eval.c (rb_mod_refine, top_using): show a warning when
      Module#refine or main.using is called at the first time.
    
    * ext/refinement/*: removed the extension library "refinement".
    
    * test/ruby/test_refinement.rb: fix for the above changes.

  Removed files:
    trunk/ext/refinement/extconf.rb
    trunk/ext/refinement/refinement.c
  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/test/ruby/test_refinement.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38728)
+++ ChangeLog	(revision 38729)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan  7 20:15:49 2013  Shugo Maeda  <shugo@r...>
+
+	* eval.c (Init_eval): enable Refinements by default.
+	  [ruby-core:51286] [Bug #7667]
+
+	* eval.c (rb_mod_refine, top_using): show a warning when
+	  Module#refine or main.using is called at the first time.
+
+	* ext/refinement/*: removed the extension library "refinement".
+
+	* test/ruby/test_refinement.rb: fix for the above changes.
+
 Mon Jan  7 17:34:22 2013  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/ruby.h (RUBY_EVENT_SPECIFIED_LINE): make it special.
Index: eval.c
===================================================================
--- eval.c	(revision 38728)
+++ eval.c	(revision 38729)
@@ -1039,6 +1039,17 @@ rb_mod_prepend(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/eval.c#L1039
     return module;
 }
 
+static void
+warn_refinements_once()
+{
+    static int warned = 0;
+
+    if (warned)
+	return;
+    rb_warn("Refinements are experimental, and the behavior may change in future versions of Ruby!");
+    warned = 1;
+}
+
 static VALUE
 hidden_identity_hash_new()
 {
@@ -1170,6 +1181,7 @@ rb_mod_refine(VALUE module, VALUE klass) https://github.com/ruby/ruby/blob/trunk/eval.c#L1181
     rb_thread_t *th = GET_THREAD();
     rb_block_t *block = rb_vm_control_frame_block_ptr(th->cfp);
 
+    warn_refinements_once();
     if (!block) {
         rb_raise(rb_eArgError, "no block given");
     }
@@ -1334,6 +1346,7 @@ top_using(VALUE self, VALUE module) https://github.com/ruby/ruby/blob/trunk/eval.c#L1346
     NODE *cref = rb_vm_cref();
     rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD());
 
+    warn_refinements_once();
     if (cref->nd_next || (prev_cfp && prev_cfp->me)) {
 	rb_raise(rb_eRuntimeError, "using is permitted only at toplevel");
     }
@@ -1527,6 +1540,8 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1540
     rb_define_private_method(rb_cModule, "include", rb_mod_include, -1);
     rb_define_private_method(rb_cModule, "prepend_features", rb_mod_prepend_features, 1);
     rb_define_private_method(rb_cModule, "prepend", rb_mod_prepend, -1);
+    rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1);
+    rb_undef_method(rb_cClass, "refine");
 
     rb_undef_method(rb_cClass, "module_function");
 
@@ -1537,6 +1552,8 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1552
     rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1);
 
     rb_define_singleton_method(rb_vm_top_self(), "include", top_include, -1);
+    rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
+			     "using", top_using, 1);
 
     rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
 
@@ -1548,20 +1565,3 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1565
     OBJ_TAINT(exception_error);
     OBJ_FREEZE(exception_error);
 }
-
-#if defined __GNUC__ && __GNUC__ >= 4
-#pragma GCC visibility push(default)
-#endif
-
-void
-ruby_Init_refinement(void)
-{
-    rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1);
-    rb_undef_method(rb_cClass, "refine");
-    rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
-			     "using", top_using, 1);
-}
-
-#if defined __GNUC__ && __GNUC__ >= 4
-#pragma GCC visibility pop
-#endif
Index: ext/refinement/extconf.rb
===================================================================
--- ext/refinement/extconf.rb	(revision 38728)
+++ ext/refinement/extconf.rb	(revision 38729)
@@ -1,3 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/refinement/extconf.rb#L0
-require 'mkmf'
-create_makefile('refinement')
-
Index: ext/refinement/refinement.c
===================================================================
--- ext/refinement/refinement.c	(revision 38728)
+++ ext/refinement/refinement.c	(revision 38729)
@@ -1,10 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/refinement/refinement.c#L0
-#include "ruby/ruby.h"
-
-void ruby_Init_refinement(void);
-
-void
-Init_refinement(void)
-{
-    rb_warn("Refinements are experimental, and the behavior may change in future versions of Ruby!");
-    ruby_Init_refinement();
-}
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 38728)
+++ test/ruby/test_refinement.rb	(revision 38729)
@@ -1,7 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1
 require 'test/unit'
 require_relative 'envutil'
 
-EnvUtil.suppress_warning {require "refinement"}
+# to supress warnings for future calls of Module#refine
+EnvUtil.suppress_warning do
+  Module.new {
+    refine(Object) {}
+  }
+end
 
 class TestRefinement < Test::Unit::TestCase
   class Foo
@@ -391,8 +396,6 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L396
 
   def test_main_using
     assert_in_out_err([], <<-INPUT, %w(:C :M), /Refinements are experimental/)
-      require "refinement"
-
       class C
         def foo
           :C
@@ -467,8 +470,6 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L470
 
   def test_using_method_cache
     assert_in_out_err([], <<-INPUT, %w(:M1 :M2), /Refinements are experimental/)
-      require "refinement"
-
       class C
         def foo
           "original"

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

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