summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-13 04:51:21 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-13 04:51:21 +0000
commite782ca865b3353870fd0fe5f45709c4997366d1a (patch)
tree26a0ed286df89aa89f2f184c995dd526e16327df
parent8f8764fd314c0ba92095e27842b8a6d04a028d7f (diff)
merge revision(s) 33935,33936,33987: [Backport #5702]
* variable.c (set_const_visibility): Module#private_constant has changed the visibility of only the first argument. Now it changes all of them. [ruby-list:48558] * test/ruby/test_module.rb: add a test for above. * variable.c (set_const_visibility): print a warning when no argument is passwd to Module#private_constant. [ruby-list:48558] * vm_method.c (set_method_visibility): ditto for Module#private_class_method. * variable.c (set_const_visibility): clear inine-cache when constant's visibility is modified. [ruby-dev:44929] * test/ruby/test_module.rb (test_private_constants_clear_inlinecache): add test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog24
-rw-r--r--test/ruby/test_module.rb34
-rw-r--r--variable.c17
-rw-r--r--version.h2
-rw-r--r--vm_method.c5
5 files changed, 77 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 089a73d3df..05ea1385d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -233,6 +233,30 @@ Sat Feb 11 02:39:09 2012 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_module.rb: add a test for above.
+Sat Feb 11 02:39:09 2012 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
+
+ * variable.c (set_const_visibility): clear inine-cache when constant's
+ visibility is modified. [ruby-dev:44929]
+
+ * test/ruby/test_module.rb (test_private_constants_clear_inlinecache):
+ add test for it.
+
+Sat Feb 11 02:39:09 2012 Yusuke Endoh <mame@tsg.ne.jp>
+
+ * variable.c (set_const_visibility): print a warning when no argument
+ is passwd to Module#private_constant. [ruby-list:48558]
+
+ * vm_method.c (set_method_visibility): ditto for
+ Module#private_class_method.
+
+Sat Feb 11 02:39:09 2012 Yusuke Endoh <mame@tsg.ne.jp>
+
+ * variable.c (set_const_visibility): Module#private_constant has
+ changed the visibility of only the first argument. Now it changes
+ all of them. [ruby-list:48558]
+
+ * test/ruby/test_module.rb: add a test for above.
+
Sat Feb 11 02:26:51 2012 Martin Bosslet <Martin.Bosslet@googlemail.com>
* lib/openssl/buffering.rb: Force multi-byte strings to be treated as
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 198fcee978..6176f484bc 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1077,6 +1077,19 @@ class TestModule < Test::Unit::TestCase
assert_raise(NameError) { c::FOO }
end
+ def test_private_constant2
+ c = Class.new
+ c.const_set(:FOO, "foo")
+ c.const_set(:BAR, "bar")
+ assert_equal("foo", c::FOO)
+ assert_equal("bar", c::BAR)
+ c.private_constant(:FOO, :BAR)
+ assert_raise(NameError) { c::FOO }
+ assert_raise(NameError) { c::BAR }
+ assert_equal("foo", c.class_eval("FOO"))
+ assert_equal("bar", c.class_eval("BAR"))
+ end
+
class PrivateClass
end
private_constant :PrivateClass
@@ -1124,6 +1137,27 @@ class TestModule < Test::Unit::TestCase
assert_in_out_err([], src, %w(Object :ok), [])
end
+ def test_private_constants_clear_inlinecache
+ bug5702 = '[ruby-dev:44929]'
+ src = <<-INPUT
+ class A
+ C = :Const
+ def self.get_C
+ A::C
+ end
+ # fill cache
+ A.get_C
+ private_constant :C, :D rescue nil
+ begin
+ A.get_C
+ rescue NameError
+ puts "A.get_C"
+ end
+ end
+ INPUT
+ assert_in_out_err([], src, %w(A.get_C), [], bug5702)
+ end
+
def test_constant_lookup_in_method_defined_by_class_eval
src = <<-INPUT
class A
diff --git a/variable.c b/variable.c
index ed6f3debd9..caadf71909 100644
--- a/variable.c
+++ b/variable.c
@@ -1952,13 +1952,22 @@ set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag)
"Insecure: can't change constant visibility");
}
+ if (argc == 0) {
+ rb_warning("%s with no argument is just ignored", rb_id2name(rb_frame_callee()));
+ }
+
for (i = 0; i < argc; i++) {
- id = rb_to_id(argv[i]);
- if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
+ VALUE val = argv[i];
+ id = rb_to_id(val);
+ if (RCLASS_CONST_TBL(mod) &&
+ st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
((rb_const_entry_t*)v)->flag = flag;
- return;
}
- rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
+ else {
+ if ( i > 0 )
+ rb_clear_cache_by_class(mod);
+ rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
+ }
}
rb_clear_cache_by_class(mod);
}
diff --git a/version.h b/version.h
index 95b74bd521..97f5d67299 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 104
+#define RUBY_PATCHLEVEL 105
#define RUBY_RELEASE_DATE "2012-02-13"
#define RUBY_RELEASE_YEAR 2012
diff --git a/vm_method.c b/vm_method.c
index 7cf816a66a..6e336036e8 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -963,6 +963,11 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, rb_method_flag_t ex)
{
int i;
secure_visibility(self);
+
+ if (argc == 0) {
+ rb_warning("%s with no argument is just ignored", rb_id2name(rb_frame_callee()));
+ }
+
for (i = 0; i < argc; i++) {
rb_export_method(self, rb_to_id(argv[i]), ex);
}