Permalink
Browse files

* vm_eval.c (yield_under, eval_under): do not activate refinements

  of the receiver in module_eval and instance_eval.

* eval.c (ruby_Init_refinement): undef Class#refine.

* eval.c (ruby_Init_refinement): remove Module#using.

* eval.c (ruby_Init_refinement): main.using should be private.

* eval.c (rb_mod_refine): the argument of Module#refine should not
  be a module.

* insns.def (defineclass): do not activate refinements in a class or
  module.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent c36d15f commit 537297d1cbcd2ed97488774e67c4fc001282a658 @shugo shugo committed Dec 7, 2012
Showing with 96 additions and 502 deletions.
  1. +17 −0 ChangeLog
  2. +6 −82 eval.c
  3. +0 −1 insns.def
  4. +71 −351 test/ruby/test_refinement.rb
  5. +0 −2 vm_eval.c
  6. +2 −66 vm_insnhelper.c
View
@@ -1,3 +1,20 @@
+Sat Dec 8 00:10:34 2012 Shugo Maeda <shugo@ruby-lang.org>
+
+ * vm_eval.c (yield_under, eval_under): do not activate refinements
+ of the receiver in module_eval and instance_eval.
+
+ * eval.c (ruby_Init_refinement): undef Class#refine.
+
+ * eval.c (ruby_Init_refinement): remove Module#using.
+
+ * eval.c (ruby_Init_refinement): main.using should be private.
+
+ * eval.c (rb_mod_refine): the argument of Module#refine should not
+ be a module.
+
+ * insns.def (defineclass): do not activate refinements in a class or
+ module.
+
Fri Dec 7 23:42:11 2012 Shugo Maeda <shugo@ruby-lang.org>
* ext/refinement/refinement.c: include ruby/ruby.h instead of the
View
@@ -1039,16 +1039,6 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
return module;
}
-static
-void check_class_or_module(VALUE obj)
-{
- if (!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)) {
- VALUE str = rb_inspect(obj);
- rb_raise(rb_eTypeError, "%s is not a class/module",
- StringValuePtr(str));
- }
-}
-
static VALUE
hidden_identity_hash_new()
{
@@ -1064,7 +1054,7 @@ rb_using_refinement(NODE *cref, VALUE klass, VALUE module)
{
VALUE iclass, c, superclass = klass;
- check_class_or_module(klass);
+ Check_Type(klass, T_CLASS);
Check_Type(module, T_MODULE);
if (NIL_P(cref->nd_refinements)) {
cref->nd_refinements = hidden_identity_hash_new();
@@ -1098,17 +1088,6 @@ rb_using_refinement(NODE *cref, VALUE klass, VALUE module)
rb_hash_aset(cref->nd_refinements, klass, iclass);
}
-void rb_using_module(NODE *cref, VALUE module);
-
-static int
-using_module_i(VALUE module, VALUE val, VALUE arg)
-{
- NODE *cref = (NODE *) arg;
-
- rb_using_module(cref, module);
- return ST_CONTINUE;
-}
-
static int
using_refinement(VALUE klass, VALUE module, VALUE arg)
{
@@ -1123,70 +1102,14 @@ rb_using_module(NODE *cref, VALUE module)
{
ID id_refinements;
VALUE refinements;
- ID id_using_modules;
- VALUE using_modules;
- check_class_or_module(module);
- CONST_ID(id_using_modules, "__using_modules__");
- using_modules = rb_attr_get(module, id_using_modules);
- if (!NIL_P(using_modules)) {
- rb_hash_foreach(using_modules, using_module_i, (VALUE) cref);
- }
+ Check_Type(module, T_MODULE);
CONST_ID(id_refinements, "__refinements__");
refinements = rb_attr_get(module, id_refinements);
if (NIL_P(refinements)) return;
rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
}
-
-static int
-check_cyclic_using(VALUE mod, VALUE _, VALUE search)
-{
- VALUE using_modules;
- ID id_using_modules;
- CONST_ID(id_using_modules, "__using_modules__");
-
- if (mod == search) {
- rb_raise(rb_eArgError, "cyclic using detected");
- }
-
- using_modules = rb_attr_get(mod, id_using_modules);
- if (!NIL_P(using_modules)) {
- rb_hash_foreach(using_modules, check_cyclic_using, search);
- }
-
- return ST_CONTINUE;
-}
-
-/*
- * call-seq:
- * using(module) -> self
- *
- * Import class refinements from <i>module</i> into the receiver.
- */
-
-static VALUE
-rb_mod_using(VALUE self, VALUE module)
-{
- NODE *cref = rb_vm_cref();
- ID id_using_modules;
- VALUE using_modules;
-
- Check_Type(module, T_MODULE);
- check_cyclic_using(module, 0, self);
- CONST_ID(id_using_modules, "__using_modules__");
- using_modules = rb_attr_get(self, id_using_modules);
- if (NIL_P(using_modules)) {
- using_modules = hidden_identity_hash_new();
- rb_ivar_set(self, id_using_modules, using_modules);
- }
- rb_hash_aset(using_modules, module, Qtrue);
- rb_using_module(cref, module);
- rb_clear_cache();
- rb_funcall(module, rb_intern("used"), 1, self);
- return self;
-}
-
VALUE rb_refinement_module_get_refined_class(VALUE module)
{
ID id_refined_class;
@@ -1245,7 +1168,7 @@ rb_mod_refine(VALUE module, VALUE klass)
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "no block given");
}
- check_class_or_module(klass);
+ Check_Type(klass, T_CLASS);
CONST_ID(id_refinements, "__refinements__");
refinements = rb_attr_get(module, id_refinements);
if (NIL_P(refinements)) {
@@ -1645,10 +1568,11 @@ Init_eval(void)
void
ruby_Init_refinement(void)
{
- rb_define_private_method(rb_cModule, "using", rb_mod_using, 1);
rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1);
+ rb_undef_method(rb_cClass, "refine");
rb_define_method(rb_cModule, "refinements", rb_mod_refinements, 0);
- rb_define_singleton_method(rb_vm_top_self(), "using", top_using, 1);
+ rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
+ "using", top_using, 1);
}
#if defined __GNUC__ && __GNUC__ >= 4
View
@@ -967,7 +967,6 @@ defineclass
klass, 0, VM_ENVVAL_BLOCK_PTR(GET_BLOCK_PTR()),
class_iseq->iseq_encoded, GET_SP(),
class_iseq->local_size, 0);
- rb_vm_using_modules(class_iseq->cref_stack, klass);
RESTORE_REGS();
INC_VM_STATE_VERSION();
Oops, something went wrong.

0 comments on commit 537297d

Please sign in to comment.