Project

General

Profile

Bug #4537 ยป attr-visibility-4537.patch

jeremyevans0 (Jeremy Evans), 08/01/2019 12:08 AM

View differences:

test/ruby/test_module.rb
705 705
    assert_equal(false, o.respond_to?(:bar=))
706 706
  end
707 707

  
708
  def test_attr_public_at_toplevel
709
    eval(<<-END, TOPLEVEL_BINDING)
710
      String.send(:attr_accessor, :x)
711
      String.send(:attr, :y)
712
      String.send(:attr_reader, :z)
713
      String.send(:attr_writer, :w)
714
    END
715
    s = ""
716
    assert_nil s.x
717
    s.x = 1
718
    assert_equal 1, s.x
719

  
720
    assert_nil s.y
721
    s.instance_variable_set(:@y, 2)
722
    assert_equal 2, s.y
723

  
724
    assert_nil s.z
725
    s.instance_variable_set(:@z, 3)
726
    assert_equal 3, s.z
727

  
728
    s.w = 4
729
    assert_equal 4, s.instance_variable_get(:@w)
730
  ensure
731
    [:x, :x=, :y, :z, :w=].each do |meth|
732
      String.undef_method(meth) rescue nil
733
    end
734
  end
735

  
708 736
  def test_const_get_evaled
709 737
    c1 = Class.new
710 738
    c2 = Class.new(c1)
vm.c
1383 1383
    const rb_execution_context_t *ec = GET_EC();
1384 1384
    const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
1385 1385
    const rb_cref_t *cref;
1386
    if (cfp->self != self) return NULL;
1386
    if (!cfp || cfp->self != self) return NULL;
1387 1387
    if (!vm_env_cref_by_cref(cfp->ep)) return NULL;
1388 1388
    cref = vm_get_cref(cfp->ep);
1389 1389
    if (CREF_CLASS(cref) != cbase) return NULL;
vm_method.c
1135 1135
    vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
1136 1136
}
1137 1137

  
1138
const rb_cref_t *rb_vm_cref_in_context(VALUE self, VALUE cbase);
1138 1139
void
1139 1140
rb_attr(VALUE klass, ID id, int read, int write, int ex)
1140 1141
{
1141 1142
    ID attriv;
1142 1143
    rb_method_visibility_t visi;
1143 1144
    const rb_execution_context_t *ec = GET_EC();
1145
    const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass);
1144 1146

  
1145
    if (!ex) {
1147
    if (!ex || !cref) {
1146 1148
	visi = METHOD_VISI_PUBLIC;
1147 1149
    }
1148 1150
    else {
1149
-