[svn:parrot] r45344 - branches/avl_string_cache/src/string

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Mar 31 08:06:32 UTC 2010


Author: bacek
Date: Wed Mar 31 08:06:31 2010
New Revision: 45344
URL: https://trac.parrot.org/parrot/changeset/45344

Log:
Always allocate new string constant from root interpreter. Fix crash when new constant allocated from thread-specific interpreter.

Modified:
   branches/avl_string_cache/src/string/api.c

Modified: branches/avl_string_cache/src/string/api.c
==============================================================================
--- branches/avl_string_cache/src/string/api.c	Wed Mar 31 07:18:28 2010	(r45343)
+++ branches/avl_string_cache/src/string/api.c	Wed Mar 31 08:06:31 2010	(r45344)
@@ -791,6 +791,9 @@
 {
     ASSERT_ARGS(Parrot_str_new_constant_ex)
     ConstStringTree *tree = interp->const_string_cache;
+    /* We should always allocate new constant string from root interpret */
+    /* Otherwise string will be destroyed */
+    Parrot_Interp    root_interp;
 
     /* Lookup old value */
     AVLStringNode node = {
@@ -806,20 +809,24 @@
     if (vv)
         return vv->value;
 
+    root_interp = interp;
+    while (root_interp->parent_interpreter)
+        root_interp = root_interp->parent_interpreter;
+
     /* Not found. Allocate new node and insert */
-    vv = (AVLStringNode*)Parrot_gc_allocate_fixed_size_storage(interp,
+    vv = (AVLStringNode*)Parrot_gc_allocate_fixed_size_storage(root_interp,
             sizeof (AVLStringNode));
     memset(vv, 0, sizeof (AVLStringNode));
 
     /* Fill it */
-    vv->str      = node.str;
     vv->length   = node.length;
     vv->encoding = node.encoding;
     vv->charset  = node.charset;
 
-    vv->value = Parrot_str_new_init(interp, buffer, len,
+    vv->value = Parrot_str_new_init(root_interp, buffer, len,
                        encoding, charset,
                        flags|PObj_constant_FLAG);
+    vv->str      = vv->value->strstart;
 
     TREE_INSERT(tree, avl_string_node_t, tree, vv);
 


More information about the parrot-commits mailing list