[svn:parrot] r48808 - trunk/src/string

nwellnhof at svn.parrot.org nwellnhof at svn.parrot.org
Mon Sep 6 00:35:40 UTC 2010


Author: nwellnhof
Date: Mon Sep  6 00:35:40 2010
New Revision: 48808
URL: https://trac.parrot.org/parrot/changeset/48808

Log:
Fix a GC-related bug in Parrot_str_clone

Using STRUCT_COPY and changing the flags afterwards can create an invalid
string header. If Parrot_gc_allocate_string_storage then triggers a GC run,
bad things can happen like external strings being compacted.

Modified:
   trunk/src/string/api.c

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Sun Sep  5 23:57:39 2010	(r48807)
+++ trunk/src/string/api.c	Mon Sep  6 00:35:40 2010	(r48808)
@@ -348,19 +348,18 @@
     const size_t alloc_size = s->bufused;
     STRING * const result = Parrot_gc_new_string_header(interp, 0);
 
-    /* Copy encoding/charset/etc */
-    STRUCT_COPY(result, s);
-
-    /* Clear COW flag. We own buffer */
-    PObj_get_FLAGS(result)  = PObj_is_string_FLAG
-                            | PObj_is_COWable_FLAG;
-
     /* Allocate new chunk of memory */
     Parrot_gc_allocate_string_storage(interp, result, alloc_size);
 
     /* and copy it over */
     mem_sys_memcopy(result->strstart, s->strstart, alloc_size);
 
+    result->strlen   = s->strlen;
+    result->bufused  = s->bufused;
+    result->hashval  = s->hashval;
+    result->encoding = s->encoding;
+    result->charset  = s->charset;
+
     return result;
 }
 


More information about the parrot-commits mailing list