* vm.c (rb_vm_cref_replace_with_duplicated_cref): added.

CREFs should not be shared by methods between `using'.
  [Bug #11247]

* vm_insnhelper.c (vm_cref_replace_with_duplicated_cref): ditto.

* vm.c (vm_cref_dup): should copy refinements correctly.

* eval.c: use rb_vm_cref_replace_with_duplicated_cref().

* eval_intern.h: add a decl. of
  rb_vm_cref_replace_with_duplicated_cref().

* vm_eval.c (eval_string_with_cref): do not need to pass
  scope's CREF because VM can find out CREF from stack frames.

* test/ruby/test_refinement.rb: add a test.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-11-20 00:17:25 +00:00
parent 895b44dcf6
commit c267d24ef0
7 changed files with 167 additions and 8 deletions

5
eval.c
View file

@ -1284,7 +1284,6 @@ rb_mod_refine(VALUE module, VALUE klass)
static VALUE
mod_using(VALUE self, VALUE module)
{
const rb_cref_t *cref = rb_vm_cref();
rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD());
if (prev_frame_func()) {
@ -1294,7 +1293,7 @@ mod_using(VALUE self, VALUE module)
if (prev_cfp && prev_cfp->self != self) {
rb_raise(rb_eRuntimeError, "Module#using is not called on self");
}
rb_using_module(cref, module);
rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
return self;
}
@ -1427,7 +1426,7 @@ top_using(VALUE self, VALUE module)
if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
rb_raise(rb_eRuntimeError, "main.using is permitted only at toplevel");
}
rb_using_module(cref, module);
rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
return self;
}