[macruby-changes] [3530] MacRuby/trunk/hash.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 15 14:44:43 PST 2010


Revision: 3530
          http://trac.macosforge.org/projects/ruby/changeset/3530
Author:   lsansonetti at apple.com
Date:     2010-02-15 14:44:42 -0800 (Mon, 15 Feb 2010)
Log Message:
-----------
Hash#clone: keep singleton classes

Modified Paths:
--------------
    MacRuby/trunk/hash.c

Modified: MacRuby/trunk/hash.c
===================================================================
--- MacRuby/trunk/hash.c	2010-02-15 22:44:17 UTC (rev 3529)
+++ MacRuby/trunk/hash.c	2010-02-15 22:44:42 UTC (rev 3530)
@@ -151,6 +151,18 @@
     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)
 {
@@ -160,22 +172,22 @@
     }
     assert(rb_klass_is_rhash(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;
+    VALUE dup = rhash_copy(rcv, klass);
+
     if (OBJ_TAINTED(rcv)) {
 	OBJ_TAINT(dup);
     }
-    return (VALUE)dup;
+    return dup;
 }
 
 static VALUE
 rhash_clone(VALUE rcv, SEL sel)
 {
-    VALUE clone = rhash_dup(rcv, 0);
+    VALUE clone = rhash_copy(rcv, CLASS_OF(rcv));
+
+    if (OBJ_TAINTED(rcv)) {
+	OBJ_TAINT(clone);
+    }
     if (OBJ_FROZEN(rcv)) {
 	OBJ_FREEZE(clone);
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100215/89dfd2ce/attachment.html>


More information about the macruby-changes mailing list