[svn:parrot] r41574 - trunk/src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Sep 30 13:32:00 UTC 2009


Author: bacek
Date: Wed Sep 30 13:31:59 2009
New Revision: 41574
URL: https://trac.parrot.org/parrot/changeset/41574

Log:
[core][cage] Implement HashIteratorKey.set_pointer_keyed_int to find contract breakage

Modified:
   trunk/src/pmc/hashiterator.pmc
   trunk/src/pmc/hashiteratorkey.pmc
   trunk/src/pmc/orderedhashiterator.pmc

Modified: trunk/src/pmc/hashiterator.pmc
==============================================================================
--- trunk/src/pmc/hashiterator.pmc	Wed Sep 30 13:00:09 2009	(r41573)
+++ trunk/src/pmc/hashiterator.pmc	Wed Sep 30 13:31:59 2009	(r41574)
@@ -230,9 +230,8 @@
                 "StopIteration");
 
         ret = pmc_new(INTERP, enum_class_HashIteratorKey);
-        /* Poke directly into HIK. We don't want to create any kind of public API for this */
-        PARROT_HASHITERATORKEY(ret)->parrot_hash = attrs->parrot_hash;
-        PARROT_HASHITERATORKEY(ret)->bucket      = attrs->bucket;
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 0, attrs->parrot_hash);
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 1, attrs->bucket);
 
         /* Move to next bucket */
         advance_to_next(INTERP, SELF);

Modified: trunk/src/pmc/hashiteratorkey.pmc
==============================================================================
--- trunk/src/pmc/hashiteratorkey.pmc	Wed Sep 30 13:00:09 2009	(r41573)
+++ trunk/src/pmc/hashiteratorkey.pmc	Wed Sep 30 13:31:59 2009	(r41574)
@@ -35,6 +35,7 @@
     VTABLE PMC* get_pmc() {
         Parrot_HashIteratorKey_attributes *attrs =
                 PARROT_HASHITERATORKEY(SELF);
+
         return hash_key_to_pmc(INTERP, attrs->parrot_hash, attrs->bucket->key);
     }
 
@@ -62,6 +63,28 @@
         return hash_key_to_string(INTERP, attrs->parrot_hash, attrs->bucket->key);
     }
 
+/*
+
+=item C<set_pointer_keyed_int()>
+
+Set pointers to Hash and HashBucket. Not really part of public API.
+
+=cut
+
+*/
+    VTABLE void set_pointer_keyed_int(INTVAL key, void *value) {
+        Parrot_HashIteratorKey_attributes *attrs =
+                PARROT_HASHITERATORKEY(SELF);
+
+        PARROT_ASSERT(value || !"Can't set NULL pointer into HashIteratorKey");
+
+        if (key == 0) {
+            attrs->parrot_hash = (Hash*)value;
+        }
+        else if (key == 1) {
+            attrs->bucket = (HashBucket*)value;
+        }
+    }
 
 }
 

Modified: trunk/src/pmc/orderedhashiterator.pmc
==============================================================================
--- trunk/src/pmc/orderedhashiterator.pmc	Wed Sep 30 13:00:09 2009	(r41573)
+++ trunk/src/pmc/orderedhashiterator.pmc	Wed Sep 30 13:31:59 2009	(r41574)
@@ -181,9 +181,8 @@
 
         /* Reuse HashIteratorKey */
         ret = pmc_new(INTERP, enum_class_HashIteratorKey);
-        /* Poke directly into HIK. We don't want to create any kind of public API for this */
-        PARROT_HASHITERATORKEY(ret)->parrot_hash = attrs->parrot_hash;
-        PARROT_HASHITERATORKEY(ret)->bucket      = bucket;
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 0, attrs->parrot_hash);
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 1, bucket);
 
         return ret;
     }
@@ -216,9 +215,8 @@
 
         /* Reuse HashIteratorKey */
         ret = pmc_new(INTERP, enum_class_HashIteratorKey);
-        /* Poke directly into HIK. We don't want to create any kind of public API for this */
-        PARROT_HASHITERATORKEY(ret)->parrot_hash = attrs->parrot_hash;
-        PARROT_HASHITERATORKEY(ret)->bucket      = bucket;
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 0, attrs->parrot_hash);
+        VTABLE_set_pointer_keyed_int(INTERP, ret, 1, bucket);
 
         return ret;
     }


More information about the parrot-commits mailing list