[pypy-svn] r17054 - in pypy/dist/pypy/rpython/memory: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Aug 29 19:56:23 CEST 2005


Author: cfbolz
Date: Mon Aug 29 19:56:21 2005
New Revision: 17054

Modified:
   pypy/dist/pypy/rpython/memory/gclltype.py
   pypy/dist/pypy/rpython/memory/lltypesimulation.py
   pypy/dist/pypy/rpython/memory/test/test_support.py
Log:
support + test for flavored_free in the llinterpreter
TODO: add free to the 'real' lltype


Modified: pypy/dist/pypy/rpython/memory/gclltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gclltype.py	(original)
+++ pypy/dist/pypy/rpython/memory/gclltype.py	Mon Aug 29 19:56:21 2005
@@ -5,7 +5,7 @@
 from pypy.rpython.lltype import Signed, Unsigned, Float, Char, Bool, Void
 from pypy.rpython.lltype import UniChar, Ptr, typeOf, InvalidCast
 
-from pypy.rpython.memory.lltypesimulation import cast_pointer
+from pypy.rpython.memory.lltypesimulation import cast_pointer, free
 from pypy.rpython.memory.lltypesimulation import simulatorptr as _ptr
 from pypy.rpython.memory.lltypesimulation import malloc, functionptr, nullptr
 from pypy.rpython.memory.lltypesimulation import pyobjectptr, cast_ptr_to_int

Modified: pypy/dist/pypy/rpython/memory/lltypesimulation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lltypesimulation.py	(original)
+++ pypy/dist/pypy/rpython/memory/lltypesimulation.py	Mon Aug 29 19:56:21 2005
@@ -197,7 +197,13 @@
         size = fixedsize + n * varsize
     address = lladdress.raw_malloc(size)
     return init_object_on_address(address, T, n)
-        
+
+def free(obj, flavor="gc"):
+    assert not flavor.startswith("gc")
+    assert isinstance(obj, simulatorptr)
+    lladdress.raw_free(obj._address)
+    obj.__dict__["_address"] = lladdress.NULL
+
 def init_object_on_address(address, T, n=None):
     result = simulatorptr(lltype.Ptr(T), address)
     result._zero_initialize(n)

Modified: pypy/dist/pypy/rpython/memory/test/test_support.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_support.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_support.py	Mon Aug 29 19:56:21 2005
@@ -1,6 +1,7 @@
 from pypy.rpython.objectmodel import free_non_gc_object
 from pypy.rpython.memory.support import AddressLinkedList
 from pypy.rpython.memory.lladdress import raw_malloc, raw_free, NULL
+from pypy.rpython.memory.test.test_llinterpsim import interpret
 
 class TestAddressLinkedList(object):
     def test_simple_access(self):
@@ -28,3 +29,35 @@
         free_non_gc_object(ll)
         raw_free(addr)
         
+def test_linked_list_annotate():
+    def f():
+        addr = raw_malloc(100)
+        ll = AddressLinkedList()
+        ll.append(addr)
+        ll.append(addr + 1)
+        ll.append(addr + 2)
+        a = ll.pop()
+        res = a == addr
+        a = ll.pop()
+        res = res and (a - addr == 1)
+        a = ll.pop()
+        res = res and (a - addr == 2)
+        res = res and (ll.pop() == NULL)
+        res = res and (ll.pop() == NULL)
+        ll.append(addr)
+        ll.free()
+        free_non_gc_object(ll)
+        ll = AddressLinkedList()
+        ll.append(addr)
+        ll.append(addr + 1)
+        ll.append(addr + 2)
+        ll.free()
+        free_non_gc_object(ll)
+        raw_free(addr)
+        return res
+##     a = RPythonAnnotator()
+##     res = a.build_types(f, [])
+##     a.translator.specialize()
+##     a.translator.view()
+    res = interpret(f, [])
+    assert res



More information about the Pypy-commit mailing list