[svn:parrot] r40081 - trunk/src

bacek at svn.parrot.org bacek at svn.parrot.org
Tue Jul 14 14:20:53 UTC 2009


Author: bacek
Date: Tue Jul 14 14:20:53 2009
New Revision: 40081
URL: https://trac.parrot.org/parrot/changeset/40081

Log:
[cage] Put big assert to parrot_hash_put to prevent using non-constant
keys or values in constant Hash.

Modified:
   trunk/src/hash.c

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	Tue Jul 14 14:20:33 2009	(r40080)
+++ trunk/src/hash.c	Tue Jul 14 14:20:53 2009	(r40081)
@@ -1303,6 +1303,20 @@
     const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
     HashBucket   *bucket  = hash->bi[hashval & hash->mask];
 
+    /* Very complex assert that we'll not put non-constant stuff into constant hash */
+    PARROT_ASSERT(
+        PMC_IS_NULL(hash->container)
+        || !(PObj_constant_TEST(hash->container))
+        || (
+            !(hash->key_type == Hash_key_type_STRING)
+            || PObj_constant_TEST((PObj *)key))
+        && (
+            !((hash->entry_type == enum_type_PMC) || (hash->entry_type == enum_type_STRING))
+            || PObj_constant_TEST((PObj *)value)
+        )
+        || !"Use non-constant key or value in constant hash"
+    );
+
     while (bucket) {
         /* store hash_val or not */
         if ((hash->compare)(interp, key, bucket->key) == 0)


More information about the parrot-commits mailing list