mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements
of orignal crefs. It fixes segmentation fault when calling refined method in duplicate module. [ruby-dev:48878] [Bug #10885] * vm_core.h, class.c: change accordingly. * test/ruby/test_refinement.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
513fefdd1f
commit
e660f776c0
5 changed files with 62 additions and 20 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Sun Feb 22 15:56:06 2015 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
|
* vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements
|
||||||
|
of orignal crefs. It fixes segmentation fault when calling
|
||||||
|
refined method in duplicate module. [ruby-dev:48878] [Bug #10885]
|
||||||
|
|
||||||
|
* vm_core.h, class.c: change accordingly.
|
||||||
|
|
||||||
|
* test/ruby/test_refinement.rb: add a test for above.
|
||||||
|
|
||||||
Sun Feb 22 10:43:37 2015 Koichi Sasada <ko1@atdot.net>
|
Sun Feb 22 10:43:37 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (rb_objspace_call_finalizer): control GC execution during
|
* gc.c (rb_objspace_call_finalizer): control GC execution during
|
||||||
|
|
21
class.c
21
class.c
|
@ -240,25 +240,6 @@ rb_class_new(VALUE super)
|
||||||
return rb_class_boot(super);
|
return rb_class_boot(super);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
|
|
||||||
{
|
|
||||||
NODE *new_node;
|
|
||||||
while (node) {
|
|
||||||
if (node->nd_clss == old_klass) {
|
|
||||||
new_node = NEW_CREF(new_klass);
|
|
||||||
RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next);
|
|
||||||
*new_cref_ptr = new_node;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
new_node = NEW_CREF(node->nd_clss);
|
|
||||||
node = node->nd_next;
|
|
||||||
*new_cref_ptr = new_node;
|
|
||||||
new_cref_ptr = &new_node->nd_next;
|
|
||||||
}
|
|
||||||
*new_cref_ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
|
@ -268,7 +249,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
|
||||||
NODE *new_cref;
|
NODE *new_cref;
|
||||||
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
|
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
|
||||||
GetISeqPtr(newiseqval, iseq);
|
GetISeqPtr(newiseqval, iseq);
|
||||||
rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
|
rb_vm_rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
|
||||||
RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref);
|
RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref);
|
||||||
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
|
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
|
||||||
RB_GC_GUARD(newiseqval);
|
RB_GC_GUARD(newiseqval);
|
||||||
|
|
|
@ -1400,6 +1400,34 @@ class TestRefinement < Test::Unit::TestCase
|
||||||
INPUT
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_call_refined_method_in_duplicate_module
|
||||||
|
bug10885 = '[ruby-dev:48878]'
|
||||||
|
assert_in_out_err([], <<-INPUT, [], [], bug10885)
|
||||||
|
module M
|
||||||
|
refine Object do
|
||||||
|
def raise
|
||||||
|
# do nothing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
using M
|
||||||
|
def m0
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
using M
|
||||||
|
def M.m1
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.dup.m0
|
||||||
|
M.dup.m1
|
||||||
|
INPUT
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def eval_using(mod, s)
|
def eval_using(mod, s)
|
||||||
|
|
|
@ -1003,6 +1003,8 @@ void rb_gc_mark_machine_stack(rb_thread_t *th);
|
||||||
|
|
||||||
int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
|
int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
|
||||||
|
|
||||||
|
void rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr);
|
||||||
|
|
||||||
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
|
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
|
||||||
|
|
||||||
#define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
|
#define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
|
||||||
|
|
|
@ -264,6 +264,27 @@ rb_vm_get_cref(const rb_iseq_t *iseq, const VALUE *ep)
|
||||||
return cref;
|
return cref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
|
||||||
|
{
|
||||||
|
NODE *new_node;
|
||||||
|
while (node) {
|
||||||
|
if (node->nd_clss == old_klass) {
|
||||||
|
new_node = NEW_CREF(new_klass);
|
||||||
|
COPY_CREF_OMOD(new_node, node);
|
||||||
|
RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next);
|
||||||
|
*new_cref_ptr = new_node;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new_node = NEW_CREF(node->nd_clss);
|
||||||
|
COPY_CREF_OMOD(new_node, node);
|
||||||
|
node = node->nd_next;
|
||||||
|
*new_cref_ptr = new_node;
|
||||||
|
new_cref_ptr = &new_node->nd_next;
|
||||||
|
}
|
||||||
|
*new_cref_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static NODE *
|
static NODE *
|
||||||
vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
|
vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue