Project

General

Profile

Backport #5702 ยป bug5702.patch

nagachika (Tomoyuki Chikanaga), 02/11/2012 03:24 PM

View differences:

ChangeLog (revision 34538)
1
Sat Feb 11 02:39:09 2012  CHIKANAGA Tomoyuki  <nagachika00@gmail.com>
2

  
3
	* variable.c (set_const_visibility): clear inine-cache when constant's
4
	  visibility is modified. [ruby-dev:44929]
5

  
6
	* test/ruby/test_module.rb (test_private_constants_clear_inlinecache):
7
	  add test for it.
8

  
9
Sat Feb 11 02:39:09 2012  Yusuke Endoh  <mame@tsg.ne.jp>
10

  
11
	* variable.c (set_const_visibility): print a warning when no argument
12
	  is passwd to Module#private_constant.  [ruby-list:48558]
13

  
14
	* vm_method.c (set_method_visibility): ditto for
15
	  Module#private_class_method.
16

  
17
Sat Feb 11 02:39:09 2012  Yusuke Endoh  <mame@tsg.ne.jp>
18

  
19
	* variable.c (set_const_visibility): Module#private_constant has
20
	  changed the visibility of only the first argument.  Now it changes
21
	  all of them.  [ruby-list:48558]
22

  
23
	* test/ruby/test_module.rb: add a test for above.
24

  
1 25
Sat Feb 11 02:26:51 2012  Martin Bosslet  <Martin.Bosslet@googlemail.com>
2 26

  
3 27
	* lib/openssl/buffering.rb: Force multi-byte strings to be treated as
variable.c (revision 34538)
1952 1952
		 "Insecure: can't change constant visibility");
1953 1953
    }
1954 1954

  
1955
    if (argc == 0) {
1956
	rb_warning("%s with no argument is just ignored", rb_id2name(rb_frame_callee()));
1957
    }
1958

  
1955 1959
    for (i = 0; i < argc; i++) {
1956
	id = rb_to_id(argv[i]);
1957
	if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
1960
	VALUE val = argv[i];
1961
	id = rb_to_id(val);
1962
	if (RCLASS_CONST_TBL(mod) &&
1963
	    st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
1958 1964
	    ((rb_const_entry_t*)v)->flag = flag;
1959
	    return;
1960 1965
	}
1961
	rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
1966
	else {
1967
	    if ( i > 0 )
1968
		rb_clear_cache_by_class(mod);
1969
	    rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
1970
	}
1962 1971
    }
1963 1972
    rb_clear_cache_by_class(mod);
1964 1973
}
vm_method.c (revision 34538)
961 961
{
962 962
    int i;
963 963
    secure_visibility(self);
964

  
965
    if (argc == 0) {
966
	rb_warning("%s with no argument is just ignored", rb_id2name(rb_frame_callee()));
967
    }
968

  
964 969
    for (i = 0; i < argc; i++) {
965 970
	rb_export_method(self, rb_to_id(argv[i]), ex);
966 971
    }
version.h (revision 34538)
1 1
#define RUBY_VERSION "1.9.3"
2
#define RUBY_PATCHLEVEL 83
2
#define RUBY_PATCHLEVEL 84
3 3

  
4 4
#define RUBY_RELEASE_DATE "2012-02-11"
5 5
#define RUBY_RELEASE_YEAR 2012
test/ruby/test_module.rb (revision 34538)
1019 1019
    assert_raise(NameError) { c::FOO }
1020 1020
  end
1021 1021

  
1022
  def test_private_constant2
1023
    c = Class.new
1024
    c.const_set(:FOO, "foo")
1025
    c.const_set(:BAR, "bar")
1026
    assert_equal("foo", c::FOO)
1027
    assert_equal("bar", c::BAR)
1028
    c.private_constant(:FOO, :BAR)
1029
    assert_raise(NameError) { c::FOO }
1030
    assert_raise(NameError) { c::BAR }
1031
    assert_equal("foo", c.class_eval("FOO"))
1032
    assert_equal("bar", c.class_eval("BAR"))
1033
  end
1034

  
1022 1035
  class PrivateClass
1023 1036
  end
1024 1037
  private_constant :PrivateClass
......
1066 1079
    assert_in_out_err([], src, %w(Object :ok), [])
1067 1080
  end
1068 1081

  
1082
  def test_private_constants_clear_inlinecache
1083
    bug5702 = '[ruby-dev:44929]'
1084
    src = <<-INPUT
1085
    class A
1086
      C = :Const
1087
      def self.get_C
1088
        A::C
1089
      end
1090
      # fill cache
1091
      A.get_C
1092
      private_constant :C, :D rescue nil
1093
      begin
1094
        A.get_C
1095
      rescue NameError
1096
        puts "A.get_C"
1097
      end
1098
    end
1099
    INPUT
1100
    assert_in_out_err([], src, %w(A.get_C), [], bug5702)
1101
  end
1102

  
1069 1103
  def test_constant_lookup_in_method_defined_by_class_eval
1070 1104
    src = <<-INPUT
1071 1105
      class A