Skip to content

Instantly share code, notes, and snippets.

@alloy
Created July 12, 2011 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alloy/1078981 to your computer and use it in GitHub Desktop.
Save alloy/1078981 to your computer and use it in GitHub Desktop.
diff --git a/array.c b/array.c
index b4a1c7f..30d68f0 100644
--- a/array.c
+++ b/array.c
@@ -1194,6 +1194,9 @@ rary_copy(VALUE rcv, VALUE klass)
return dup;
}
+void
+init_copy(VALUE dest, VALUE obj);
+
VALUE
rary_dup(VALUE ary, SEL sel)
{
@@ -1204,6 +1207,7 @@ rary_dup(VALUE ary, SEL sel)
assert(rb_klass_is_rary(klass));
VALUE dup = rary_copy(ary, klass);
+ init_copy(dup, ary);
if (OBJ_TAINTED(ary)) {
OBJ_TAINT(dup);
diff --git a/hash.c b/hash.c
index 065d4f2..4ed7b56 100644
--- a/hash.c
+++ b/hash.c
@@ -157,6 +157,9 @@ rhash_copy(VALUE rcv, VALUE klass)
return (VALUE)dup;
}
+void
+init_copy(VALUE dest, VALUE obj);
+
VALUE
rhash_dup(VALUE rcv, SEL sel)
{
@@ -167,6 +170,7 @@ rhash_dup(VALUE rcv, SEL sel)
assert(rb_klass_is_rhash(klass));
VALUE dup = rhash_copy(rcv, klass);
+ init_copy(dup, rcv);
OBJ_INFECT(dup, rcv);
return dup;
diff --git a/object.c b/object.c
index dc8ae7b..3803edf 100644
--- a/object.c
+++ b/object.c
@@ -189,7 +189,7 @@ rb_obj_class(VALUE obj)
return rb_class_real(CLASS_OF(obj), true);
}
-static void
+void
init_copy(VALUE dest, VALUE obj)
{
if (OBJ_FROZEN(dest)) {
diff --git a/string.c b/string.c
index 55361db..94b0411 100644
--- a/string.c
+++ b/string.c
@@ -1822,6 +1822,9 @@ rstr_copy(VALUE rcv, VALUE klass)
return dup;
}
+void
+init_copy(VALUE dest, VALUE obj);
+
static VALUE
rstr_dup(VALUE str, SEL sel)
{
@@ -1832,6 +1835,7 @@ rstr_dup(VALUE str, SEL sel)
assert(rb_klass_is_rstr(klass));
VALUE dup = rstr_copy(str, klass);
+ init_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