Skip to content

Commit

Permalink
* eval.c (Init_eval): enable Refinements by default.
Browse files Browse the repository at this point in the history
  [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
  • Loading branch information
shugo committed Jan 7, 2013
1 parent 06f2a86 commit 9cadf0c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
12 changes: 12 additions & 0 deletions 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.
Expand Down
34 changes: 17 additions & 17 deletions eval.c
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");

Expand All @@ -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);

Expand All @@ -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
3 changes: 0 additions & 3 deletions ext/refinement/extconf.rb

This file was deleted.

10 changes: 0 additions & 10 deletions ext/refinement/refinement.c

This file was deleted.

11 changes: 6 additions & 5 deletions test/ruby/test_refinement.rb
@@ -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
Expand Down Expand Up @@ -391,8 +396,6 @@ def foo

def test_main_using
assert_in_out_err([], <<-INPUT, %w(:C :M), /Refinements are experimental/)
require "refinement"
class C
def foo
:C
Expand Down Expand Up @@ -467,8 +470,6 @@ def test_inspect

def test_using_method_cache
assert_in_out_err([], <<-INPUT, %w(:M1 :M2), /Refinements are experimental/)
require "refinement"
class C
def foo
"original"
Expand Down

0 comments on commit 9cadf0c

Please sign in to comment.