[pypy-svn] r70861 - pypy/branch/stringbuilder2/pypy/rlib

arigo at codespeak.net arigo at codespeak.net
Tue Jan 26 09:15:55 CET 2010


Author: arigo
Date: Tue Jan 26 09:15:55 2010
New Revision: 70861

Modified:
   pypy/branch/stringbuilder2/pypy/rlib/rgc.py
Log:
Fix for a bug that is hard to test: using raw_memcopy in that way would
also overwrite the header of the new object with a copy of the header of
the one.  This might make a few GC flags wrong.  This problem only
occurs after translation to C, though.



Modified: pypy/branch/stringbuilder2/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rlib/rgc.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rlib/rgc.py	Tue Jan 26 09:15:55 2010
@@ -285,19 +285,21 @@
     if llop.shrink_array(lltype.Bool, p, smallerlength):
         return p    # done by the GC
     # XXX we assume for now that the type of p is GcStruct containing a
-    # variable array, with no further pointers anywhere
+    # variable array, with no further pointers anywhere, and exactly one
+    # field in the fixed part -- like STR and UNICODE.
 
     TP = lltype.typeOf(p).TO
     newp = lltype.malloc(TP, smallerlength)
-    
-    source_addr = llmemory.cast_ptr_to_adr(p)
-    dest_addr   = llmemory.cast_ptr_to_adr(newp)
-    staticsize  = llmemory.offsetof(TP, TP._arrayfld)
-    llmemory.raw_memcopy(source_addr, dest_addr, staticsize)
+
+    assert len(TP._names) == 2
+    field = getattr(p, TP._names[0])
+    setattr(newp, TP._names[0], field)
 
     ARRAY = getattr(TP, TP._arrayfld)
-    source_addr += staticsize + llmemory.itemoffsetof(ARRAY, 0)
-    dest_addr   += staticsize + llmemory.itemoffsetof(ARRAY, 0)
+    offset = (llmemory.offsetof(TP, TP._arrayfld) +
+              llmemory.itemoffsetof(ARRAY, 0))
+    source_addr = llmemory.cast_ptr_to_adr(p)    + offset
+    dest_addr   = llmemory.cast_ptr_to_adr(newp) + offset
     llmemory.raw_memcopy(source_addr, dest_addr, 
                          llmemory.sizeof(ARRAY.OF) * smallerlength)
 



More information about the Pypy-commit mailing list