[pypy-svn] r54401 - in pypy/branch/io-improvements/pypy: rlib rlib/test rpython rpython/lltypesystem rpython/memory rpython/memory/test
fijal at codespeak.net
fijal at codespeak.net
Sun May 4 14:57:17 CEST 2008
Author: fijal
Date: Sun May 4 14:57:16 2008
New Revision: 54401
Modified:
pypy/branch/io-improvements/pypy/rlib/rgc.py
pypy/branch/io-improvements/pypy/rlib/test/test_rgc.py
pypy/branch/io-improvements/pypy/rpython/llinterp.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/io-improvements/pypy/rpython/memory/gcwrapper.py
pypy/branch/io-improvements/pypy/rpython/memory/test/test_gc.py
Log:
Enough support to pass test_gc with resizable buffer. It's still not doing
too much
Modified: pypy/branch/io-improvements/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/rgc.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/rgc.py Sun May 4 14:57:16 2008
@@ -245,16 +245,19 @@
def compute_result_annotation(self, s_T, s_init_size):
from pypy.annotation import model as annmodel
- from pypy.rpython.lltypesystem import rffi
+ from pypy.rpython.lltypesystem import rffi, lltype
assert s_T.is_constant()
assert isinstance(s_init_size, annmodel.SomeInteger)
T = s_T.const
- return annmodel.SomePtr(T)
+ return annmodel.SomePtr(lltype.Ptr(T))
def specialize_call(self, hop):
- xxx
- #T = hop.args_v[0].value
- #hop.genop('malloc_raw_array',
+ from pypy.rpython.lltypesystem import lltype
+ vlist = [hop.inputarg(lltype.Void, 0),
+ hop.inputarg(lltype.Signed, 1)]
+ hop.exception_is_here()
+ return hop.genop('malloc_resizable_buffer', vlist,
+ resulttype=hop.r_result.lowleveltype)
def resize_buffer(ptr, new_size):
""" Resize raw buffer returned by raw_buffer_of_shape to new size
@@ -274,16 +277,22 @@
class ResizeBufferEntry(ExtRegistryEntry):
_about_ = resize_buffer
- def compute_result_annotation(self, s_arr, s_old_size, s_new_size):
+ def compute_result_annotation(self, s_ptr, s_new_size):
from pypy.annotation import model as annmodel
from pypy.rpython.lltypesystem import rffi
- assert isinstance(s_arr, annmodel.SomePtr)
- assert isinstance(s_old_size, annmodel.SomeInteger)
+ assert isinstance(s_ptr, annmodel.SomePtr)
assert isinstance(s_new_size, annmodel.SomeInteger)
- assert s_arr.ll_ptrtype is rffi.VOIDP
- return s_arr
+ return s_ptr
-def finish_building_buffer(T, ptr):
+ def specialize_call(self, hop):
+ from pypy.rpython.lltypesystem import lltype
+ vlist = [hop.inputarg(hop.args_r[0], 0),
+ hop.inputarg(lltype.Signed, 1)]
+ hop.exception_is_here()
+ return hop.genop('resize_buffer', vlist,
+ resulttype=hop.r_result.lowleveltype)
+
+def finish_building_buffer(ptr):
""" Finish building raw_buffer returned by raw_buffer_of_shape
"""
return ptr
@@ -291,11 +300,14 @@
class FinishBuildingBufferEntry(ExtRegistryEntry):
_about_ = finish_building_buffer
- def compute_result_annotation(self, s_T, s_arr, s_size):
- from pypy.annotation.model import SomePtr, SomeInteger
- from pypy.rpython.lltypesystem import lltype
- assert s_T.is_constant()
- T = s_T.const
+ def compute_result_annotation(self, s_arr):
+ from pypy.annotation.model import SomePtr, s_ImpossibleValue
assert isinstance(s_arr, SomePtr)
- assert isinstance(s_size, SomeInteger)
- return SomePtr(lltype.Ptr(T))
+ return s_arr
+
+ def specialize_call(self, hop):
+ from pypy.rpython.lltypesystem import lltype
+ vlist = [hop.inputarg(hop.args_r[0], 0)]
+ hop.exception_cannot_occur()
+ return hop.genop('finish_building_buffer', vlist,
+ resulttype=hop.r_result.lowleveltype)
Modified: pypy/branch/io-improvements/pypy/rlib/test/test_rgc.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rlib/test/test_rgc.py (original)
+++ pypy/branch/io-improvements/pypy/rlib/test/test_rgc.py Sun May 4 14:57:16 2008
@@ -46,6 +46,6 @@
ptr.chars[0] = 'a'
ptr = rgc.resize_buffer(ptr, 2)
ptr.chars[1] = 'b'
- return hlstr(rgc.finish_building_buffer(STR, ptr))
+ return hlstr(rgc.finish_building_buffer(ptr))
assert f() == 'ab'
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 Sun May 4 14:57:16 2008
@@ -697,6 +697,15 @@
zero = flags.get('zero', False)
return self.heap.malloc_nonmovable(obj, size, zero=zero)
+ def op_malloc_resizable_buffer(self, obj, 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_finish_building_buffer(self, obj):
+ return self.heap.finish_building_buffer(obj)
+
def op_free(self, obj, flavor):
assert isinstance(flavor, str)
if flavor == 'raw' and self.llinterpreter.malloc_check:
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py Sun May 4 14:57:16 2008
@@ -325,6 +325,9 @@
'malloc_varsize': LLOp(canraise=(MemoryError,), canunwindgc=True),
'malloc_nonmovable': LLOp(canraise=(MemoryError,), canunwindgc=True),
'malloc_nonmovable_varsize':LLOp(canraise=(MemoryError,),canunwindgc=True),
+ 'malloc_resizable_buffer': LLOp(canraise=(MemoryError,),canunwindgc=True),
+ 'resize_buffer': LLOp(canraise=(MemoryError,),canunwindgc=True),
+ 'finish_building_buffer' : LLOp(),
'zero_gc_pointers_inside': LLOp(),
'free': LLOp(),
'getfield': LLOp(sideeffects=False, canrun=True),
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 Sun May 4 14:57:16 2008
@@ -52,6 +52,28 @@
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, 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)):
+ new_arr[i] = old_arr[i]
+ return buf
+
+ def finish_building_buffer(self, obj):
+ return obj
+
def free(self, TYPE, flavor='gc'):
assert flavor != 'gc'
return lltype.free(TYPE, flavor=flavor)
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 Sun May 4 14:57:16 2008
@@ -429,6 +429,20 @@
assert self.interpret(func, []) == int(self.GC_CAN_MOVE)
+ def test_raw_array(self):
+ from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.annlowlevel import hlstr
+ from pypy.rlib import rgc
+
+ def f():
+ ptr = rgc.raw_buffer_of_shape(STR, 1)
+ ptr.chars[0] = 'a'
+ ptr = rgc.resize_buffer(ptr, 2)
+ ptr.chars[1] = 'b'
+ return len(hlstr(rgc.finish_building_buffer(ptr)))
+
+ assert self.interpret(f, []) == 2
+
class TestMarkSweepGC(GCTest):
from pypy.rpython.memory.gc.marksweep import MarkSweepGC as GCClass
More information about the Pypy-commit
mailing list