* object.c (rb_obj_clone): singleton class should be attached
singleton object to. a patch by Satoshi Shiba <shiba AT rvm.jp> at [ruby-dev:44460]. [Bug #5274] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c4d77cb4ad
commit
125b62e76d
@ -1,3 +1,9 @@
|
|||||||
|
Mon Sep 19 07:54:17 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* object.c (rb_obj_clone): singleton class should be attached
|
||||||
|
singleton object to. a patch by Satoshi Shiba <shiba AT rvm.jp>
|
||||||
|
at [ruby-dev:44460]. [Bug #5274]
|
||||||
|
|
||||||
Sat Sep 17 23:34:10 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Sep 17 23:34:10 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (parser_data_type): inherit the core type in ripper so
|
* parse.y (parser_data_type): inherit the core type in ripper so
|
||||||
|
7
object.c
7
object.c
@ -273,12 +273,17 @@ VALUE
|
|||||||
rb_obj_clone(VALUE obj)
|
rb_obj_clone(VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE clone;
|
VALUE clone;
|
||||||
|
VALUE singleton;
|
||||||
|
|
||||||
if (rb_special_const_p(obj)) {
|
if (rb_special_const_p(obj)) {
|
||||||
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
|
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
|
||||||
}
|
}
|
||||||
clone = rb_obj_alloc(rb_obj_class(obj));
|
clone = rb_obj_alloc(rb_obj_class(obj));
|
||||||
RBASIC(clone)->klass = rb_singleton_class_clone(obj);
|
singleton = rb_singleton_class_clone(obj);
|
||||||
|
RBASIC(clone)->klass = singleton;
|
||||||
|
if (FL_TEST(singleton, FL_SINGLETON)) {
|
||||||
|
rb_singleton_class_attached(singleton, clone);
|
||||||
|
}
|
||||||
RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT) | FL_TEST(clone, FL_UNTRUSTED)) & ~(FL_FREEZE|FL_FINALIZE|FL_MARK);
|
RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT) | FL_TEST(clone, FL_UNTRUSTED)) & ~(FL_FREEZE|FL_FINALIZE|FL_MARK);
|
||||||
init_copy(clone, obj);
|
init_copy(clone, obj);
|
||||||
rb_funcall(clone, id_init_clone, 1, obj);
|
rb_funcall(clone, id_init_clone, 1, obj);
|
||||||
|
@ -258,4 +258,12 @@ class TestClass < Test::Unit::TestCase
|
|||||||
END
|
END
|
||||||
assert_equal(42, PrivateClass.new.foo)
|
assert_equal(42, PrivateClass.new.foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
StrClone = String.clone
|
||||||
|
Class.new(StrClone)
|
||||||
|
|
||||||
|
def test_cloned_class
|
||||||
|
bug5274 = StrClone.new("[ruby-dev:44460]")
|
||||||
|
assert_equal(bug5274, Marshal.load(Marshal.dump(bug5274)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user