Project

General

Profile

Bug #9321 ยป rb_mod_const_missing_with_tests_redefined.patch

drkaes (Stefan Kaes), 12/31/2013 07:39 PM

View differences:

eval.c
977 977
void
978 978
rb_frame_pop(void)
979 979
{
980
    ID mid;
981
    VALUE klass;
980 982
    rb_thread_t *th = GET_THREAD();
983
    rb_control_frame_t *cfp = th->cfp;
984
    if (rb_thread_method_id_and_class(th, &mid, &klass)) {
985
        ID called_id = frame_called_id(cfp);
986
        if (called_id) {
987
            mid = called_id;
988
        }
989
        EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, klass, mid, klass, Qnil);
990
        RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, mid);
991
    }
981 992
    th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
982 993
}
983 994

  
test/ruby/test_settracefunc.rb
1066 1066
      :b_return
1067 1067
    ], events)
1068 1068
  end
1069

  
1070
  def test_const_missing
1071
    bug59398 = '[ruby-core:59398]'
1072
    events = []
1073
    assert !defined?(MISSING_CONSTANT_59398)
1074
    TracePoint.new(:c_call, :c_return, :call, :return){|tp|
1075
      next unless tp.defined_class == Module
1076
      # rake/ext/module.rb aliases :const_missing and Ruby uses the aliased name
1077
      # but this only happens when running the full test suite
1078
      events << [tp.event,tp.method_id] if tp.method_id == :const_missing || tp.method_id == :rake_original_const_missing
1079
    }.enable{
1080
      MISSING_CONSTANT_59398 rescue nil
1081
    }
1082
    if events.map{|e|e[1]}.include?(:rake_original_const_missing)
1083
      assert_equal([
1084
        [:call, :const_missing],
1085
        [:c_call, :rake_original_const_missing],
1086
        [:c_return, :rake_original_const_missing],
1087
        [:return, :const_missing],
1088
      ], events, bug59398)
1089
    else
1090
      assert_equal([
1091
        [:c_call, :const_missing],
1092
        [:c_return, :const_missing]
1093
      ], events, bug59398)
1094
    end
1095
  end
1096

  
1097
  class AliasedRubyMethod
1098
    def foo; 1; end;
1099
    alias bar foo
1100
  end
1101
  def test_aliased_ruby_method
1102
    events = []
1103
    aliased = AliasedRubyMethod.new
1104
    TracePoint.new(:call, :return){|tp|
1105
      events << [tp.event, tp.method_id]
1106
    }.enable{
1107
      aliased.bar
1108
    }
1109
    assert_equal([
1110
      [:call, :foo],
1111
      [:return, :foo]
1112
    ], events, "should use original method name for tracing ruby methods")
1113
  end
1114
  class AliasedCMethod < Hash
1115
    alias original_size size
1116
    def size; original_size; end
1117
  end
1118

  
1119
  def test_aliased_c_method
1120
    events = []
1121
    aliased = AliasedCMethod.new
1122
    TracePoint.new(:call, :return, :c_call, :c_return){|tp|
1123
      events << [tp.event, tp.method_id]
1124
    }.enable{
1125
      aliased.size
1126
    }
1127
    assert_equal([
1128
      [:call, :size],
1129
      [:c_call, :original_size],
1130
      [:c_return, :original_size],
1131
      [:return, :size]
1132
    ], events, "should use alias method name for tracing c methods")
1133
  end
1134

  
1069 1135
end