Skip to content

Commit

Permalink
* vm.c (rb_thread_mark): mark a working Proc of bmethod
Browse files Browse the repository at this point in the history
  (a method defined by define_method) even if the method was removed.
  We could not trace working Proc object which represents the body
  of bmethod if the method was removed (alias/undef/overridden).
  Simply, it was mark miss.
  This patch by Kazuki Tsujimoto. [Bug ruby#7825]
  NOTE: We can brush up this marking because we do not need to mark
  `me' on each living control frame. We need to mark `me's
  only if `me' was free'ed. This is future work after Ruby 2.0.0.
* test/ruby/test_method.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Feb 16, 2013
1 parent 7cbeff9 commit b4add2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Sat Feb 16 16:08:35 2013 Koichi Sasada <[email protected]>

* vm.c (rb_thread_mark): mark a working Proc of bmethod
(a method defined by define_method) even if the method was removed.
We could not trace working Proc object which represents the body
of bmethod if the method was removed (alias/undef/overridden).
Simply, it was mark miss.
This patch by Kazuki Tsujimoto. [Bug #7825]

NOTE: We can brush up this marking because we do not need to mark
`me' on each living control frame. We need to mark `me's
only if `me' was free'ed. This is future work after Ruby 2.0.0.

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

Sat Feb 16 15:45:56 2013 Koichi Sasada <[email protected]>

* proc.c (rb_binding_new_with_cfp): create binding object even if
Expand Down
14 changes: 14 additions & 0 deletions test/ruby/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,18 @@ def foo
}
assert_equal(c, c.instance_method(:foo).owner, bug7836)
end

def test_gced_bmethod
assert_normal_exit %q{
require 'irb'
IRB::Irb.module_eval do
define_method(:eval_input) do
IRB::Irb.module_eval { alias_method :eval_input, :to_s }
GC.start
Kernel
end
end
IRB.start
}, '[Bug #7825]'
end
end
6 changes: 5 additions & 1 deletion vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,11 @@ rb_thread_mark(void *ptr)
if (iseq) {
rb_gc_mark(RUBY_VM_NORMAL_ISEQ_P(iseq) ? iseq->self : (VALUE)iseq);
}
if (cfp->me) ((rb_method_entry_t *)cfp->me)->mark = 1;
if (cfp->me) {
/* TODO: marking `me' can be more sophisticated way */
((rb_method_entry_t *)cfp->me)->mark = 1;
rb_mark_method_entry(cfp->me);
}
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
}
Expand Down

0 comments on commit b4add2a

Please sign in to comment.