[pypy-svn] r54571 - in pypy/branch/io-improvements/pypy: rpython rpython/lltypesystem rpython/memory rpython/memory/gctransform rpython/memory/test translator/c/test

fijal at codespeak.net fijal at codespeak.net
Thu May 8 20:36:05 CEST 2008


Author: fijal
Date: Thu May  8 20:36:02 2008
New Revision: 54571

Modified:
   pypy/branch/io-improvements/pypy/rpython/llinterp.py
   pypy/branch/io-improvements/pypy/rpython/lltypesystem/llheap.py
   pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py
   pypy/branch/io-improvements/pypy/rpython/memory/gcwrapper.py
   pypy/branch/io-improvements/pypy/rpython/memory/test/test_gc.py
   pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py
   pypy/branch/io-improvements/pypy/translator/c/test/test_boehm.py
Log:
* Adapt to changes in rgc
* Create missing methods in llheap


Modified: pypy/branch/io-improvements/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/llinterp.py	Thu May  8 20:36:02 2008
@@ -700,11 +700,11 @@
     def op_malloc_resizable_buffer(self, obj, flags, size):
         return self.heap.malloc_resizable_buffer(obj, size)
 
-    def op_resize_buffer(self, obj, new_size):
-        return self.heap.resize_buffer(obj, new_size)
+    def op_resize_buffer(self, obj, old_size, new_size):
+        return self.heap.resize_buffer(obj, old_size, new_size)
 
-    def op_finish_building_buffer(self, obj):
-        return self.heap.finish_building_buffer(obj)
+    def op_finish_building_buffer(self, obj, size):
+        return self.heap.finish_building_buffer(obj, size)
 
     def op_free(self, obj, flavor):
         assert isinstance(flavor, str)

Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/llheap.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/llheap.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/llheap.py	Thu May  8 20:36:02 2008
@@ -19,3 +19,18 @@
     return weakref_create(objgetter())
 
 malloc_nonmovable = malloc
+
+def malloc_resizable_buffer(TP, size):
+    return malloc(TP, size)
+
+def resize_buffer(buf, old_size, new_size):
+    ll_str = malloc(typeOf(buf).TO, new_size)
+    for i in range(old_size):
+        ll_str.chars[i] = buf.chars[i]
+    return ll_str
+
+def finish_building_buffer(buf, final_size):
+    ll_str = malloc(typeOf(buf).TO, final_size)
+    for i in range(final_size):
+        ll_str.chars[i] = buf.chars[i]
+    return ll_str

Modified: pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py	Thu May  8 20:36:02 2008
@@ -598,7 +598,9 @@
 
     def gct_finish_building_buffer(self, hop):
         op = hop.spaceop
-        return hop.genop('same_as', op.args, resultvar=op.result)
+        if self._can_realloc():
+            return self._gct_resize_buffer_realloc(hop)
+        return hop.genop('same_as', [op.args[0]], resultvar=op.result)
 
     def varsize_malloc_helper(self, hop, flags, meth, extraargs):
         def intconst(c): return rmodel.inputconst(lltype.Signed, c)

Modified: pypy/branch/io-improvements/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/gcwrapper.py	Thu May  8 20:36:02 2008
@@ -60,18 +60,18 @@
             gctypelayout.zero_gc_pointers(result)
         return result
 
-    def resize_buffer(self, obj, new_size):
+    def resize_buffer(self, obj, old_size, new_size):
         T = lltype.typeOf(obj).TO
         buf = self.malloc_resizable_buffer(T, new_size)
         # copy contents
         arrayfld = T._arrayfld
         new_arr = getattr(buf, arrayfld)
         old_arr = getattr(obj, arrayfld)
-        for i in range(len(old_arr)):
+        for i in range(old_size):
             new_arr[i] = old_arr[i]
         return buf
 
-    def finish_building_buffer(self, obj):
+    def finish_building_buffer(self, obj, size):
         return obj
 
     def free(self, TYPE, flavor='gc'):

Modified: pypy/branch/io-improvements/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/test/test_gc.py	Thu May  8 20:36:02 2008
@@ -437,9 +437,9 @@
         def f():
             ptr = rgc.resizable_buffer_of_shape(STR, 1)
             ptr.chars[0] = 'a'
-            ptr = rgc.resize_buffer(ptr, 2)
+            ptr = rgc.resize_buffer(ptr, 1, 2)
             ptr.chars[1] = 'b'
-            return len(hlstr(rgc.finish_building_buffer(ptr)))
+            return len(hlstr(rgc.finish_building_buffer(ptr, 2)))
 
         assert self.interpret(f, []) == 2
 

Modified: pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py	Thu May  8 20:36:02 2008
@@ -498,11 +498,11 @@
         from pypy.rlib import rgc
 
         def f():
-            ptr = rgc.resizable_buffer_of_shape(STR, 1)
+            ptr = rgc.resizable_buffer_of_shape(STR, 2)
             ptr.chars[0] = 'a'
-            ptr = rgc.resize_buffer(ptr, 2)
+            ptr = rgc.resize_buffer(ptr, 1, 2)
             ptr.chars[1] = 'b'
-            return len(hlstr(rgc.finish_building_buffer(ptr)))
+            return len(hlstr(rgc.finish_building_buffer(ptr, 2)))
 
         run = self.runner(f)
         assert run([]) == 2

Modified: pypy/branch/io-improvements/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/branch/io-improvements/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/branch/io-improvements/pypy/translator/c/test/test_boehm.py	Thu May  8 20:36:02 2008
@@ -383,11 +383,11 @@
         from pypy.rlib import rgc
 
         def f():
-            ptr = rgc.resizable_buffer_of_shape(STR, 1)
+            ptr = rgc.resizable_buffer_of_shape(STR, 2)
             ptr.chars[0] = 'a'
-            ptr = rgc.resize_buffer(ptr, 2)
+            ptr = rgc.resize_buffer(ptr, 1, 2)
             ptr.chars[1] = 'b'
-            return hlstr(rgc.finish_building_buffer(ptr)) == "ab"
+            return hlstr(rgc.finish_building_buffer(ptr, 2)) == "ab"
 
         run = self.getcompiled(f)
         assert run() == True



More information about the Pypy-commit mailing list