[pypy-svn] r70849 - in pypy/branch/stringbuilder2/pypy/rpython: . lltypesystem memory memory/test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 25 19:08:46 CET 2010
Author: arigo
Date: Mon Jan 25 19:08:46 2010
New Revision: 70849
Modified:
pypy/branch/stringbuilder2/pypy/rpython/llinterp.py
pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/llheap.py
pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py
pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py
Log:
Support 'shrink_array' in the llinterp and in gcwrapper
(not linked to the real gc yet).
Modified: pypy/branch/stringbuilder2/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/llinterp.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/llinterp.py Mon Jan 25 19:08:46 2010
@@ -754,6 +754,9 @@
self.llinterpreter.remember_free(obj)
self.heap.free(obj, flavor=flavor)
+ def op_shrink_array(self, obj, smallersize):
+ return self.heap.shrink_array(obj, smallersize)
+
def op_zero_gc_pointers_inside(self, obj):
raise NotImplementedError("zero_gc_pointers_inside")
Modified: pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/llheap.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/llheap.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/llheap.py Mon Jan 25 19:08:46 2010
@@ -20,20 +20,9 @@
malloc_nonmovable = malloc
-def malloc_resizable_buffer(TP, size):
- return malloc(TP, size)
+def shrink_array(p, smallersize):
+ return False
-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
def thread_prepare():
pass
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py Mon Jan 25 19:08:46 2010
@@ -58,33 +58,8 @@
gctypelayout.zero_gc_pointers(result)
return result
- def malloc_resizable_buffer(self, TYPE, n):
- typeid = self.get_type_id(TYPE)
- addr = self.gc.malloc(typeid, n)
- result = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
- if not self.gc.malloc_zero_filled:
- gctypelayout.zero_gc_pointers(result)
- return result
-
- def resize_buffer(self, obj, oldlength, newlength):
- T = lltype.typeOf(obj).TO
- ARRAY = getattr(T, T._arrayfld)
- addr = llmemory.cast_ptr_to_adr(obj)
- newaddr = self.gc.malloc(self.gc.get_type_id(addr), newlength, True)
- addr = llmemory.cast_ptr_to_adr(obj)
- itemsofs = (llmemory.FieldOffset(T, T._arrayfld) +
- llmemory.itemoffsetof(ARRAY, 0))
- itemsize = llmemory.sizeof(ARRAY.OF)
- tocopy = min(newlength, oldlength)
- llmemory.raw_memcopy(addr + itemsofs, newaddr + itemsofs,
- tocopy * itemsize)
- return llmemory.cast_adr_to_ptr(newaddr, lltype.Ptr(T))
-
- def finish_building_buffer(self, obj, oldlength, newlength):
- if hasattr(self.gc, 'realloc_shrink'):
- xxx
- else:
- return self.resize_buffer(obj, oldlength, newlength)
+ def shrink_array(self, p, smallersize):
+ return False
def free(self, TYPE, flavor='gc'):
assert flavor != 'gc'
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py Mon Jan 25 19:08:46 2010
@@ -468,18 +468,22 @@
assert self.interpret(func, []) == int(self.GC_CANNOT_MALLOC_NONMOVABLE)
- def test_resizable_buffer(self):
+ def test_shrink_array(self):
from pypy.rpython.lltypesystem.rstr import STR
- from pypy.rpython.annlowlevel import hlstr
def f():
- ptr = rgc.resizable_buffer_of_shape(STR, 1)
- ptr.chars[0] = 'a'
- ptr = rgc.resize_buffer(ptr, 1, 4)
- ptr.chars[1] = 'b'
- return len(hlstr(rgc.finish_building_buffer(ptr, 2)))
+ ptr = lltype.malloc(STR, 3)
+ ptr.hash = 0x62
+ ptr.chars[0] = 'A'
+ ptr.chars[1] = 'B'
+ ptr.chars[2] = 'C'
+ ptr = rgc.ll_shrink_array(ptr, 2)
+ return ( ord(ptr.chars[0]) +
+ (ord(ptr.chars[1]) << 8) +
+ (len(ptr.chars) << 16) +
+ (ptr.hash << 24))
- assert self.interpret(f, []) == 2
+ assert self.interpret(f, []) == 0x62024241
def test_tagged_simple(self):
from pypy.rlib.objectmodel import UnboxedValue
More information about the Pypy-commit
mailing list