mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
06f2a86f1a
commit
9cadf0c039
5 changed files with 35 additions and 35 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Mon Jan 7 20:15:49 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* include/ruby/ruby.h (RUBY_EVENT_SPECIFIED_LINE): make it special.
|
||||
|
|
34
eval.c
34
eval.c
|
@ -1039,6 +1039,17 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
require 'mkmf'
|
||||
create_makefile('refinement')
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#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();
|
||||
}
|
|
@ -1,7 +1,12 @@
|
|||
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::TestCase
|
|||
|
||||
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::TestCase
|
|||
|
||||
def test_using_method_cache
|
||||
assert_in_out_err([], <<-INPUT, %w(:M1 :M2), /Refinements are experimental/)
|
||||
require "refinement"
|
||||
|
||||
class C
|
||||
def foo
|
||||
"original"
|
||||
|
|
Loading…
Reference in a new issue