mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* object.c (init_copy): rename copy_object as initialize_copy,
since it works as copy constructor. * eval.c (rb_add_method): initialize_copy should always be private, like initialize. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81882bac13
commit
6e52d10fe6
12 changed files with 61 additions and 55 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon May 19 13:58:03 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* object.c (init_copy): rename copy_object as initialize_copy,
|
||||
since it works as copy constructor.
|
||||
|
||||
* eval.c (rb_add_method): initialize_copy should always be
|
||||
private, like initialize.
|
||||
|
||||
Mon May 19 13:51:50 2003 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* re.c (rb_reg_quote): \n \r \f \v quoting was wrong.
|
||||
|
|
2
array.c
2
array.c
|
@ -1941,7 +1941,7 @@ Init_Array()
|
|||
rb_define_alloc_func(rb_cArray, ary_alloc);
|
||||
rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
|
||||
rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);
|
||||
rb_define_method(rb_cArray, "copy_object", rb_ary_replace, 1);
|
||||
rb_define_method(rb_cArray, "initialize_copy", rb_ary_replace, 1);
|
||||
|
||||
rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0);
|
||||
rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0);
|
||||
|
|
40
eval.c
40
eval.c
|
@ -266,26 +266,26 @@ rb_add_method(klass, mid, node, noex)
|
|||
}
|
||||
if (!FL_TEST(klass, FL_SINGLETON) &&
|
||||
node && nd_type(node) != NODE_ZSUPER &&
|
||||
mid == rb_intern("initialize")) {
|
||||
noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER);
|
||||
}
|
||||
else if (FL_TEST(klass, FL_SINGLETON) && node && nd_type(node) == NODE_CFUNC &&
|
||||
mid == rb_intern("allocate")) {
|
||||
rb_warn("defining %s.allocate is deprecated; use rb_define_alloc_func()",
|
||||
rb_class2name(rb_iv_get(klass, "__attached__")));
|
||||
mid = ID_ALLOCATOR;
|
||||
}
|
||||
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
|
||||
rb_clear_cache_by_id(mid);
|
||||
body = NEW_METHOD(node, noex);
|
||||
st_insert(RCLASS(klass)->m_tbl, mid, (st_data_t)body);
|
||||
if (node && mid != ID_ALLOCATOR && ruby_running) {
|
||||
if (FL_TEST(klass, FL_SINGLETON)) {
|
||||
rb_funcall(rb_iv_get(klass, "__attached__"), singleton_added, 1, ID2SYM(mid));
|
||||
}
|
||||
else {
|
||||
rb_funcall(klass, added, 1, ID2SYM(mid));
|
||||
}
|
||||
(mid == rb_intern("initialize" )|| mid == rb_intern("initialize_copy"))) {
|
||||
noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER);
|
||||
}
|
||||
else if (FL_TEST(klass, FL_SINGLETON) && node && nd_type(node) == NODE_CFUNC &&
|
||||
mid == rb_intern("allocate")) {
|
||||
rb_warn("defining %s.allocate is deprecated; use rb_define_alloc_func()",
|
||||
rb_class2name(rb_iv_get(klass, "__attached__")));
|
||||
mid = ID_ALLOCATOR;
|
||||
}
|
||||
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
|
||||
rb_clear_cache_by_id(mid);
|
||||
body = NEW_METHOD(node, noex);
|
||||
st_insert(RCLASS(klass)->m_tbl, mid, (st_data_t)body);
|
||||
if (node && mid != ID_ALLOCATOR && ruby_running) {
|
||||
if (FL_TEST(klass, FL_SINGLETON)) {
|
||||
rb_funcall(rb_iv_get(klass, "__attached__"), singleton_added, 1, ID2SYM(mid));
|
||||
}
|
||||
else {
|
||||
rb_funcall(klass, added, 1, ID2SYM(mid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
4
file.c
4
file.c
|
@ -2260,7 +2260,7 @@ rb_stat_init(obj, fname)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_stat_copy_object(copy, orig)
|
||||
rb_stat_init_copy(copy, orig)
|
||||
VALUE copy, orig;
|
||||
{
|
||||
struct stat *nst;
|
||||
|
@ -2915,7 +2915,7 @@ Init_File()
|
|||
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
|
||||
rb_define_alloc_func(rb_cStat, rb_stat_s_alloc);
|
||||
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
|
||||
rb_define_method(rb_cStat, "copy_object", rb_stat_copy_object, 1);
|
||||
rb_define_method(rb_cStat, "initialize_copy", rb_stat_init_copy, 1);
|
||||
|
||||
rb_include_module(rb_cStat, rb_mComparable);
|
||||
|
||||
|
|
2
hash.c
2
hash.c
|
@ -1742,7 +1742,7 @@ Init_Hash()
|
|||
rb_define_alloc_func(rb_cHash, hash_alloc);
|
||||
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
|
||||
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
|
||||
rb_define_method(rb_cHash,"copy_object", rb_hash_replace, 1);
|
||||
rb_define_method(rb_cHash,"initialize_copy", rb_hash_replace, 1);
|
||||
rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
|
||||
|
||||
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
|
||||
|
|
4
io.c
4
io.c
|
@ -2467,7 +2467,7 @@ rb_io_reopen(argc, argv, file)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_io_copy_object(dest, io)
|
||||
rb_io_init_copy(dest, io)
|
||||
VALUE dest, io;
|
||||
{
|
||||
OpenFile *fptr, *orig;
|
||||
|
@ -3925,7 +3925,7 @@ Init_IO()
|
|||
rb_define_hooked_variable("$.", &lineno, 0, lineno_setter);
|
||||
rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
|
||||
|
||||
rb_define_method(rb_cIO, "copy_object", rb_io_copy_object, 1);
|
||||
rb_define_method(rb_cIO, "initialize_copy", rb_io_init_copy, 1);
|
||||
rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
|
||||
|
||||
rb_define_method(rb_cIO, "print", rb_io_print, -1);
|
||||
|
|
|
@ -158,7 +158,7 @@ num_coerce_relop(x, y)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
num_copy_object(x, y)
|
||||
num_init_copy(x, y)
|
||||
VALUE x, y;
|
||||
{
|
||||
/* Numerics are immutable values, which should not be copied */
|
||||
|
@ -1767,7 +1767,7 @@ Init_Numeric()
|
|||
rb_cNumeric = rb_define_class("Numeric", rb_cObject);
|
||||
|
||||
rb_include_module(rb_cNumeric, rb_mComparable);
|
||||
rb_define_method(rb_cNumeric, "copy_object", num_copy_object, 1);
|
||||
rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1);
|
||||
rb_define_method(rb_cNumeric, "coerce", num_coerce, 1);
|
||||
|
||||
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
|
||||
|
|
32
object.c
32
object.c
|
@ -31,9 +31,7 @@ VALUE rb_cTrueClass;
|
|||
VALUE rb_cFalseClass;
|
||||
VALUE rb_cSymbol;
|
||||
|
||||
static ID eq, eql;
|
||||
static ID inspect;
|
||||
static ID copy_obj;
|
||||
static ID id_eq, id_eql, id_inspect, id_init_copy;
|
||||
|
||||
VALUE
|
||||
rb_equal(obj1, obj2)
|
||||
|
@ -42,7 +40,7 @@ rb_equal(obj1, obj2)
|
|||
VALUE result;
|
||||
|
||||
if (obj1 == obj2) return Qtrue;
|
||||
result = rb_funcall(obj1, eq, 1, obj2);
|
||||
result = rb_funcall(obj1, id_eq, 1, obj2);
|
||||
if (RTEST(result)) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -51,7 +49,7 @@ int
|
|||
rb_eql(obj1, obj2)
|
||||
VALUE obj1, obj2;
|
||||
{
|
||||
return RTEST(rb_funcall(obj1, eql, 1, obj2));
|
||||
return RTEST(rb_funcall(obj1, id_eql, 1, obj2));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -106,7 +104,7 @@ rb_obj_class(obj)
|
|||
}
|
||||
|
||||
static void
|
||||
copy_object(dest, obj)
|
||||
init_copy(dest, obj)
|
||||
VALUE dest, obj;
|
||||
{
|
||||
if (OBJ_FROZEN(dest)) {
|
||||
|
@ -114,7 +112,7 @@ copy_object(dest, obj)
|
|||
}
|
||||
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
|
||||
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
|
||||
rb_funcall(dest, copy_obj, 1, obj);
|
||||
rb_funcall(dest, id_init_copy, 1, obj);
|
||||
if (FL_TEST(obj, FL_EXIVAR)) {
|
||||
rb_copy_generic_ivar(dest, obj);
|
||||
}
|
||||
|
@ -143,7 +141,7 @@ rb_obj_clone(obj)
|
|||
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
|
||||
}
|
||||
clone = rb_obj_alloc(rb_obj_class(obj));
|
||||
copy_object(clone, obj);
|
||||
init_copy(clone, obj);
|
||||
RBASIC(clone)->klass = rb_singleton_class_clone(obj);
|
||||
RBASIC(clone)->flags = RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT);
|
||||
|
||||
|
@ -160,19 +158,19 @@ rb_obj_dup(obj)
|
|||
rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
|
||||
}
|
||||
dup = rb_obj_alloc(rb_obj_class(obj));
|
||||
copy_object(dup, obj);
|
||||
init_copy(dup, obj);
|
||||
|
||||
return dup;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_obj_copy_object(obj, orig)
|
||||
rb_obj_init_copy(obj, orig)
|
||||
VALUE obj, orig;
|
||||
{
|
||||
if (obj == orig) return obj;
|
||||
rb_check_frozen(obj);
|
||||
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
|
||||
rb_raise(rb_eTypeError, "copy_object should take same class object");
|
||||
rb_raise(rb_eTypeError, "initialize_copy should take same class object");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
@ -204,7 +202,7 @@ VALUE
|
|||
rb_inspect(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
return rb_obj_as_string(rb_funcall(obj, inspect, 0, 0));
|
||||
return rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1406,7 +1404,7 @@ Init_Object()
|
|||
|
||||
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
|
||||
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
|
||||
rb_define_method(rb_mKernel, "copy_object", rb_obj_copy_object, 1);
|
||||
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
|
||||
|
||||
rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
|
||||
rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
|
||||
|
@ -1541,8 +1539,8 @@ Init_Object()
|
|||
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
|
||||
rb_define_global_const("FALSE", Qfalse);
|
||||
|
||||
eq = rb_intern("==");
|
||||
eql = rb_intern("eql?");
|
||||
inspect = rb_intern("inspect");
|
||||
copy_obj = rb_intern("copy_object");
|
||||
id_eq = rb_intern("==");
|
||||
id_eql = rb_intern("eql?");
|
||||
id_inspect = rb_intern("inspect");
|
||||
id_init_copy = rb_intern("initialize_copy");
|
||||
}
|
||||
|
|
8
re.c
8
re.c
|
@ -582,7 +582,7 @@ match_alloc(klass)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
match_copy_object(obj, orig)
|
||||
match_init_copy(obj, orig)
|
||||
VALUE obj, orig;
|
||||
{
|
||||
if (obj == orig) return obj;
|
||||
|
@ -1482,7 +1482,7 @@ rb_reg_options(re)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_reg_copy_object(copy, re)
|
||||
rb_reg_init_copy(copy, re)
|
||||
VALUE copy, re;
|
||||
{
|
||||
if (copy == re) return copy;
|
||||
|
@ -1732,7 +1732,7 @@ Init_Regexp()
|
|||
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
|
||||
|
||||
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
|
||||
rb_define_method(rb_cRegexp, "copy_object", rb_reg_copy_object, 1);
|
||||
rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
|
||||
rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
|
||||
rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
|
||||
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
|
||||
|
@ -1758,7 +1758,7 @@ Init_Regexp()
|
|||
rb_define_alloc_func(rb_cMatch, match_alloc);
|
||||
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
||||
|
||||
rb_define_method(rb_cMatch, "copy_object", match_copy_object, 1);
|
||||
rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
|
||||
rb_define_method(rb_cMatch, "size", match_size, 0);
|
||||
rb_define_method(rb_cMatch, "length", match_size, 0);
|
||||
rb_define_method(rb_cMatch, "offset", match_offset, 1);
|
||||
|
|
2
string.c
2
string.c
|
@ -3236,7 +3236,7 @@ Init_String()
|
|||
rb_include_module(rb_cString, rb_mEnumerable);
|
||||
rb_define_alloc_func(rb_cString, str_alloc);
|
||||
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
|
||||
rb_define_method(rb_cString, "copy_object", rb_str_replace, 1);
|
||||
rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
|
||||
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
|
||||
rb_define_method(rb_cString, "==", rb_str_equal, 1);
|
||||
rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
|
||||
|
|
4
struct.c
4
struct.c
|
@ -422,7 +422,7 @@ rb_struct_to_a(s)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_struct_copy_object(copy, s)
|
||||
rb_struct_init_copy(copy, s)
|
||||
VALUE copy, s;
|
||||
{
|
||||
if (copy == s) return copy;
|
||||
|
@ -642,7 +642,7 @@ Init_Struct()
|
|||
rb_define_singleton_method(rb_cStruct, "new", rb_struct_s_def, -1);
|
||||
|
||||
rb_define_method(rb_cStruct, "initialize", rb_struct_initialize, -2);
|
||||
rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);
|
||||
rb_define_method(rb_cStruct, "initialize_copy", rb_struct_init_copy, 1);
|
||||
|
||||
rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
|
||||
rb_define_method(rb_cStruct, "eql?", rb_struct_eql, 1);
|
||||
|
|
6
time.c
6
time.c
|
@ -783,7 +783,7 @@ time_modify(time)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
time_copy_object(copy, time)
|
||||
time_init_copy(copy, time)
|
||||
VALUE copy, time;
|
||||
{
|
||||
struct time_object *tobj, *tcopy;
|
||||
|
@ -805,7 +805,7 @@ time_dup(time)
|
|||
VALUE time;
|
||||
{
|
||||
VALUE dup = time_s_alloc(rb_cTime);
|
||||
time_copy_object(dup, time);
|
||||
time_init_copy(dup, time);
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
@ -1415,7 +1415,7 @@ Init_Time()
|
|||
rb_define_method(rb_cTime, "<=>", time_cmp, 1);
|
||||
rb_define_method(rb_cTime, "eql?", time_eql, 1);
|
||||
rb_define_method(rb_cTime, "hash", time_hash, 0);
|
||||
rb_define_method(rb_cTime, "copy_object", time_copy_object, 1);
|
||||
rb_define_method(rb_cTime, "initialize_copy", time_init_copy, 1);
|
||||
|
||||
rb_define_method(rb_cTime, "localtime", time_localtime, 0);
|
||||
rb_define_method(rb_cTime, "gmtime", time_gmtime, 0);
|
||||
|
|
Loading…
Reference in a new issue