summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-20 00:17:25 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-20 00:17:25 (GMT)
commitc267d24ef0b4955ee5d0538707ed47d1b6278699 (patch)
tree7cc4faa9287f8400cfec82f20e1900def66a705b /vm.c
parent895b44dcf6d94e58f3daaf78d58453e2735ee827 (diff)
* 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
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/vm.c b/vm.c
index 929144d..de8be50 100644
--- a/vm.c
+++ b/vm.c
@@ -136,10 +136,17 @@ vm_cref_dup(const rb_cref_t *cref)
{
VALUE klass = CREF_CLASS(cref);
const rb_scope_visibility_t *visi = CREF_SCOPE_VISI(cref);
- rb_cref_t *next_cref = CREF_NEXT(cref);
+ rb_cref_t *next_cref = CREF_NEXT(cref), *new_cref;
int pushed_by_eval = CREF_PUSHED_BY_EVAL(cref);
- return vm_cref_new(klass, visi->method_visi, visi->module_func, next_cref, pushed_by_eval);
+ new_cref = vm_cref_new(klass, visi->method_visi, visi->module_func, next_cref, pushed_by_eval);
+
+ if (!NIL_P(CREF_REFINEMENTS(cref))) {
+ CREF_REFINEMENTS_SET(new_cref, rb_hash_dup(CREF_REFINEMENTS(cref)));
+ CREF_OMOD_SHARED_UNSET(new_cref);
+ }
+
+ return new_cref;
}
static rb_cref_t *
@@ -1192,6 +1199,15 @@ rb_vm_cref(void)
return rb_vm_get_cref(cfp->ep);
}
+rb_cref_t *
+rb_vm_cref_replace_with_duplicated_cref(void)
+{
+ rb_thread_t *th = GET_THREAD();
+ rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
+ rb_cref_t *cref = vm_cref_replace_with_duplicated_cref(cfp->ep);
+ return cref;
+}
+
const rb_cref_t *
rb_vm_cref_in_context(VALUE self, VALUE cbase)
{