-
-
Save Watson1978/1210522 to your computer and use it in GitHub Desktop.
MacRuby : ticket #1262
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/array.c b/array.c | |
index b4a1c7f..ac31015 100644 | |
--- a/array.c | |
+++ b/array.c | |
@@ -1203,14 +1203,10 @@ rary_dup(VALUE ary, SEL sel) | |
} | |
assert(rb_klass_is_rary(klass)); | |
- VALUE dup = rary_copy(ary, klass); | |
+ VALUE dup = rary_alloc(klass, 0); | |
+ rb_obj_invoke_initialize_copy(dup, ary); | |
- if (OBJ_TAINTED(ary)) { | |
- OBJ_TAINT(dup); | |
- } | |
- if (OBJ_UNTRUSTED(ary)) { | |
- OBJ_UNTRUST(dup); | |
- } | |
+ OBJ_INFECT(dup, ary); | |
return dup; | |
} | |
diff --git a/hash.c b/hash.c | |
index 065d4f2..6f073d9 100644 | |
--- a/hash.c | |
+++ b/hash.c | |
@@ -145,18 +145,6 @@ rhash_alloc(VALUE klass, SEL sel) | |
return (VALUE)hash; | |
} | |
-static VALUE | |
-rhash_copy(VALUE rcv, VALUE klass) | |
-{ | |
- NEWOBJ(dup, rb_hash_t); | |
- dup->basic.flags = 0; | |
- dup->basic.klass = klass; | |
- GC_WB(&dup->tbl, st_copy(RHASH(rcv)->tbl)); | |
- GC_WB(&dup->ifnone, RHASH(rcv)->ifnone); | |
- dup->has_proc_default = RHASH(rcv)->has_proc_default; | |
- return (VALUE)dup; | |
-} | |
- | |
VALUE | |
rhash_dup(VALUE rcv, SEL sel) | |
{ | |
@@ -166,7 +154,8 @@ rhash_dup(VALUE rcv, SEL sel) | |
} | |
assert(rb_klass_is_rhash(klass)); | |
- VALUE dup = rhash_copy(rcv, klass); | |
+ VALUE dup = rhash_alloc(klass, 0); | |
+ rb_obj_invoke_initialize_copy(dup, rcv); | |
OBJ_INFECT(dup, rcv); | |
return dup; | |
diff --git a/macruby_internal.h b/macruby_internal.h | |
index e60bf37..d088e9e 100644 | |
--- a/macruby_internal.h | |
+++ b/macruby_internal.h | |
@@ -91,6 +91,9 @@ rb_objc_release(void *addr) | |
// MacRubyIntern.h | |
+/* object.c */ | |
+void rb_obj_invoke_initialize_copy(VALUE dest, VALUE obj); | |
+ | |
/* enumerator.c */ | |
VALUE rb_enumeratorize(VALUE, SEL, int, VALUE *); | |
#define RETURN_ENUMERATOR(obj, argc, argv) \ | |
diff --git a/object.c b/object.c | |
index dc8ae7b..ac4240a 100644 | |
--- a/object.c | |
+++ b/object.c | |
@@ -221,6 +221,12 @@ init_copy(VALUE dest, VALUE obj) | |
rb_vm_call(dest, selInitializeCopy, 1, &obj); | |
} | |
+void | |
+rb_obj_invoke_initialize_copy(VALUE dest, VALUE obj) | |
+{ | |
+ init_copy(dest, obj); | |
+} | |
+ | |
/* | |
* call-seq: | |
* obj.clone -> an_object | |
diff --git a/string.c b/string.c | |
index fc1cb08..641a9e6 100644 | |
--- a/string.c | |
+++ b/string.c | |
@@ -1831,14 +1831,6 @@ rstr_initialize(VALUE self, SEL sel, int argc, VALUE *argv) | |
} | |
static VALUE | |
-rstr_copy(VALUE rcv, VALUE klass) | |
-{ | |
- VALUE dup = rstr_alloc(klass, 0); | |
- rstr_replace(dup, 0, rcv); | |
- return dup; | |
-} | |
- | |
-static VALUE | |
rstr_dup(VALUE str, SEL sel) | |
{ | |
VALUE klass = CLASS_OF(str); | |
@@ -1847,7 +1839,8 @@ rstr_dup(VALUE str, SEL sel) | |
} | |
assert(rb_klass_is_rstr(klass)); | |
- VALUE dup = rstr_copy(str, klass); | |
+ VALUE dup = rstr_alloc(klass, 0); | |
+ rb_obj_invoke_initialize_copy(dup, str); | |
OBJ_INFECT(dup, str); | |
return dup; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment