vm_method.c: make initialize methods private

* id.c (Init_id), template/id.h.tmpl: add initialize_{copy,clone,dup}
  and respond_to_missing?.
* vm_method.c (rb_method_entry_make): make above methods private.
  [Feature #6539]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-12-01 09:16:52 +00:00
Родитель 0a8575c800
Коммит cf9d17a3d3
5 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Dec 1 18:16:49 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* id.c (Init_id), template/id.h.tmpl: add initialize_{copy,clone,dup}
and respond_to_missing?.
* vm_method.c (rb_method_entry_make): make above methods private.
[Feature #6539]
Sat Dec 1 16:40:22 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* test/ruby/test_thread.rb: move ConditionVariable related test

4
id.c
Просмотреть файл

@ -26,6 +26,7 @@ Init_id(void)
REGISTER_SYMID(idIFUNC, "<IFUNC>");
REGISTER_SYMID(idCFUNC, "<CFUNC>");
REGISTER_SYMID(idRespond_to, "respond_to?");
REGISTER_SYMID(idRespond_to_missing, "respond_to_missing?");
REGISTER_SYMID(id_core_set_method_alias, "core#set_method_alias");
REGISTER_SYMID(id_core_set_variable_alias, "core#set_variable_alias");
@ -54,5 +55,8 @@ Init_id(void)
REGISTER_SYMID(idSend, "send");
REGISTER_SYMID(id__send__, "__send__");
REGISTER_SYMID(idInitialize, "initialize");
REGISTER_SYMID(idInitialize_copy, "initialize_copy");
REGISTER_SYMID(idInitialize_clone, "initialize_clone");
REGISTER_SYMID(idInitialize_dup, "initialize_dup");
REGISTER_SYMID(idUScore, "_");
}

Просмотреть файл

@ -28,6 +28,9 @@ method_ids = %w[
Send
__send__
Initialize
Initialize_copy
Initialize_clone
Initialize_dup
UScore
Bitblt
Answer
@ -42,6 +45,7 @@ token_op_ids = %w[
preserved_ids = %w[
NULL
Respond_to
Respond_to_missing
IFUNC
CFUNC
_core_set_method_alias

Просмотреть файл

@ -1,3 +1,4 @@
# -*- coding: us-ascii -*-
require 'test/unit'
require_relative 'envutil'
@ -31,6 +32,10 @@ class TestMethod < Test::Unit::TestCase
end
class T
def initialize; end
def initialize_copy(*) super end
def initialize_clone(*) super end
def initialize_dup(*) super end
def respond_to_missing?(*) super end
def normal_method; end
end
module M
@ -329,6 +334,10 @@ class TestMethod < Test::Unit::TestCase
def test_default_accessibility
assert T.public_instance_methods.include?(:normal_method), 'normal methods are public by default'
assert !T.public_instance_methods.include?(:initialize), '#initialize is private'
assert !T.public_instance_methods.include?(:initialize_copy), '#initialize_copy is private'
assert !T.public_instance_methods.include?(:initialize_clone), '#initialize_clone is private'
assert !T.public_instance_methods.include?(:initialize_dup), '#initialize_dup is private'
assert !T.public_instance_methods.include?(:respond_to_missing?), '#respond_to_missing? is private'
assert !M.public_instance_methods.include?(:func), 'module methods are private by default'
assert M.public_instance_methods.include?(:meth), 'normal methods are public by default'
end

Просмотреть файл

@ -190,7 +190,9 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
if (!FL_TEST(klass, FL_SINGLETON) &&
type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
type != VM_METHOD_TYPE_ZSUPER &&
(mid == rb_intern("initialize") || mid == rb_intern("initialize_copy"))) {
(mid == idInitialize || mid == idInitialize_copy ||
mid == idInitialize_clone || mid == idInitialize_dup ||
mid == idRespond_to_missing)) {
noex = NOEX_PRIVATE | noex;
}