Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use instance_method to get method object #11965

Closed
wants to merge 1 commit into from

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Oct 30, 2024

instead of method().

There is a bug around define_method, so this patch is workaround.

instead of `method()`.

There is a bug around `define_method`, so this patch is workaround.
@ko1
Copy link
Contributor Author

ko1 commented Oct 30, 2024

module M
  def foo = 1
  self.extend M
end

3.times{
  module M
    alias foo2 foo
    remove_method :foo
    def foo = 2
  ensure
    alias foo foo2
    remove_method :foo2
  end

  p M.foo

  original_foo = M.method(:foo)

  M.class_eval do
    remove_method :foo
    def foo = 3
  end

  M.class_eval do
    remove_method :foo
    define_method :foo, original_foo
  end
}

This is repro-code (RUBY_DEBUG should be 1).

@ko1
Copy link
Contributor Author

ko1 commented Oct 30, 2024

This patch solves this kind of error:

Assertion Failed: /tmp/ruby/src/trunk-repeat20-asserts/vm_method.c:225:clear_method_cache_by_id_in_class:RB_TYPE_P(owner, T_CLASS): owner: T_MODULE
ruby 3.4.0dev (2024-10-30T14:22:08Z master 1e1a37220b) +PRISM [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0031 p:---- s:0181 e:000180 CFUNC  :remove_method
c:0030 p:0005 s:0176 e:000175 BLOCK  /tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1366 [FINISH]
c:0029 p:---- s:0173 e:000172 CFUNC  :class_eval
c:0028 p:0030 s:0169 e:000168 METHOD /tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1365
c:0027 p:0037 s:0160 e:000159 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit/testcase.rb:202
c:0026 p:0052 s:0154 e:000153 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit/testcase.rb:170
c:0025 p:0083 s:0145 e:000144 BLOCK  /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1671 [FINISH]
c:0024 p:---- s:0138 e:000137 CFUNC  :map
c:0023 p:0103 s:0134 e:000133 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1658
c:0022 p:0035 s:0122 e:000121 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1362
c:0021 p:0010 s:0115 e:000113 BLOCK  /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:823
c:0020 p:0027 s:0109 E:0007e0 METHOD <internal:array>:42
c:0019 p:0047 s:0103 E:002658 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:821
c:0018 p:0008 s:0096 E:000718 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:858
c:0017 p:0130 s:0089 E:000bf8 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1604
c:0016 p:0016 s:0076 E:000d68 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1299
c:0015 p:0005 s:0071 E:002130 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1769
c:0014 p:0006 s:0067 E:002198 BLOCK  /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1756
c:0013 p:0027 s:0063 E:002520 METHOD <internal:array>:42
c:0012 p:0042 s:0057 E:002168 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1755
c:0011 p:0013 s:0052 E:002558 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1799
c:0010 p:0008 s:0047 E:002590 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1046
c:0009 p:0008 s:0041 E:000e90 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:891
c:0008 p:0017 s:0035 E:0025c8 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:145
c:0007 p:0008 s:0030 E:000ec8 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1283
c:0006 p:0032 s:0025 E:000ef0 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1882
c:0005 p:0009 s:0021 E:000f28 METHOD /tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1886
c:0004 p:0065 s:0016 E:0023b8 TOP    /tmp/ruby/src/trunk-repeat20-asserts/tool/test/runner.rb:14 [FINISH]
c:0003 p:---- s:0011 e:000010 CFUNC  :require_relative
c:0002 p:0005 s:0006 E:0023e0 EVAL   /tmp/ruby/src/trunk-repeat20-asserts/test/runner.rb:5 [FINISH]
c:0001 p:0000 s:0003 E:0002c0 DUMMY  [FINISH]
-- Ruby level backtrace information ----------------------------------------
/tmp/ruby/src/trunk-repeat20-asserts/test/runner.rb:5:in '<main>'
/tmp/ruby/src/trunk-repeat20-asserts/test/runner.rb:5:in 'require_relative'
/tmp/ruby/src/trunk-repeat20-asserts/tool/test/runner.rb:14:in '<top (required)>'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1886:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1882:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1283:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:145:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:891:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1046:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1799:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1755:in '_run'
<internal:array>:42:in 'each'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1756:in 'block in _run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1769:in 'run_tests'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1299:in '_run_anything'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1604:in '_run_anything'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:858:in '_run_suites'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:821:in '_run_suites'
<internal:array>:42:in 'each'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:823:in 'block in _run_suites'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1362:in '_run_suite'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1658:in '_run_suite'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1658:in 'map'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit.rb:1671:in 'block in _run_suite'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit/testcase.rb:170:in 'run'
/tmp/ruby/src/trunk-repeat20-asserts/tool/lib/test/unit/testcase.rb:202:in 'run_test'
/tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1365:in 'test_errors_on_terminal_window_smaller_than_min_width'
/tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1365:in 'class_eval'
/tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1366:in 'block in test_errors_on_terminal_window_smaller_than_min_width'
/tmp/ruby/src/trunk-repeat20-asserts/test/error_highlight/test_error_highlight.rb:1366:in 'remove_method'
-- Threading information ---------------------------------------------------
Total ractor count: 1
Ruby thread count for this ractor: 2
-- C level backtrace information -------------------------------------------
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_print_backtrace+0x14) [0x7f61c60a1d1f] /tmp/ruby/src/trunk-repeat20-asserts/vm_dump.c:822
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_vm_bugreport) /tmp/ruby/src/trunk-repeat20-asserts/vm_dump.c:1151
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_assert_failure_detail+0x13e) [0x7f61c5d9967e] /tmp/ruby/src/trunk-repeat20-asserts/error.c:1190
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(clear_method_cache_by_id_in_class+0x386) [0x7f61c6076326] /tmp/ruby/src/trunk-repeat20-asserts/vm_method.c:225
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_class_foreach_subclass+0x3c) [0x7f61c5df24ac] /tmp/ruby/src/trunk-repeat20-asserts/class.c:198
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(remove_method+0xaf) [0x7f61c609463f] /tmp/ruby/src/trunk-repeat20-asserts/vm_method.c:1690
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_mod_remove_method+0x5b) [0x7f61c60947fb] /tmp/ruby/src/trunk-repeat20-asserts/vm_method.c:1736
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_cfp_consistent_p+0x0) [0x7f61c6073039] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3794
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_call_cfunc_with_frame_) /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3796
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_sendish+0x16a) [0x7f61c60778ca] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:5961
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_core+0x9b) [0x7f61c608590b] ../../src/trunk-repeat20-asserts/insns.def:898
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_loop+0x9) [0x7f61c608ca21] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2591
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_vm_exec) /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2567
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(yield_under+0x317) [0x7f61c60908f7] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:1646
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(specific_eval+0x57) [0x7f61c60986d7] /tmp/ruby/src/trunk-repeat20-asserts/vm_eval.c:2142
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_cfp_consistent_p+0x0) [0x7f61c6073039] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3794
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_call_cfunc_with_frame_) /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3796
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_sendish+0x16a) [0x7f61c60778ca] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:5961
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_core+0xf41) [0x7f61c60867b1] ../../src/trunk-repeat20-asserts/insns.def:851
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_loop+0x9) [0x7f61c608ca21] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2591
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_vm_exec) /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2567
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_yield+0x133) [0x7f61c6091823] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:1646
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_ary_collect+0x55) [0x7f61c5dd2b55] /tmp/ruby/src/trunk-repeat20-asserts/array.c:3618
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_cfp_consistent_p+0x0) [0x7f61c6073039] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3794
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_call_cfunc_with_frame_) /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3796
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_sendish+0x16a) [0x7f61c60778ca] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:5961
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_core+0xf41) [0x7f61c60867b1] ../../src/trunk-repeat20-asserts/insns.def:851
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_loop+0x9) [0x7f61c608cc15] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2591
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_vm_exec) /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2570
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(load_iseq_eval+0x45) [0x7f61c5f00fdf] /tmp/ruby/src/trunk-repeat20-asserts/load.c:781
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(require_internal) /tmp/ruby/src/trunk-repeat20-asserts/load.c:1287
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_require_string_internal+0x4b) [0x7f61c5f017c9] /tmp/ruby/src/trunk-repeat20-asserts/load.c:1386
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_f_require_relative) /tmp/ruby/src/trunk-repeat20-asserts/load.c:1041
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_cfp_consistent_p+0x0) [0x7f61c6073039] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3794
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_call_cfunc_with_frame_) /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:3796
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_sendish+0x16a) [0x7f61c60778ca] /tmp/ruby/src/trunk-repeat20-asserts/vm_insnhelper.c:5961
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_core+0x9b) [0x7f61c608590b] ../../src/trunk-repeat20-asserts/insns.def:898
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(vm_exec_loop+0x9) [0x7f61c608ca21] /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2591
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_vm_exec) /tmp/ruby/src/trunk-repeat20-asserts/vm.c:2567
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(rb_ec_exec_node+0xb1) [0x7f61c5e93711] /tmp/ruby/src/trunk-repeat20-asserts/eval.c:281
/tmp/ruby/build/trunk-repeat20-asserts/libruby.so.3.4(ruby_run_node+0x9b) [0x7f61c5e9a3db] /tmp/ruby/src/trunk-repeat20-asserts/eval.c:319
/tmp/ruby/build/trunk-repeat20-asserts/ruby(rb_main+0x21) [0x5581458d3186] /tmp/ruby/src/trunk-repeat20-asserts/main.c:43
/tmp/ruby/build/trunk-repeat20-asserts/ruby(main) /tmp/ruby/src/trunk-repeat20-asserts/main.c:62
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_call_main+0x7a) [0x7f61c59871ca] ../sysdeps/nptl/libc_start_call_main.h:58
/lib/x86_64-linux-gnu/libc.so.6(call_init+0x0) [0x7f61c598728b] ../csu/libc-start.c:360
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main_impl) ../csu/libc-start.c:347
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main) (null):0

@mame
Copy link
Member

mame commented Oct 31, 2024

I have created and merged ruby/error_highlight#56

@mame mame closed this Oct 31, 2024
ko1 added a commit to ko1/ruby that referenced this pull request Oct 31, 2024
`me->defined_class` should be 0 for method entries of
Modules. The current implementation violates this condition
when the aliased object was complemented cme.

This patch checks this condition
and fix ruby#11965 (comment)
ko1 added a commit to ko1/ruby that referenced this pull request Oct 31, 2024
`me->defined_class` should be 0 for method entries of
Modules.

This patch checks this condition
and fix ruby#11965 (comment)
ko1 added a commit that referenced this pull request Nov 1, 2024
`me->defined_class` should be 0 for method entries of
Modules.

This patch checks this condition
and fix #11965 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants