[pypy-svn] r58268 - in pypy/branch/gc-experiments/pypy/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Sat Sep 20 15:20:03 CEST 2008


Author: fijal
Date: Sat Sep 20 15:20:00 2008
New Revision: 58268

Modified:
   pypy/branch/gc-experiments/pypy/rpython/lltypesystem/llarena.py
   pypy/branch/gc-experiments/pypy/rpython/lltypesystem/test/test_llarena.py
Log:
Add a hack to llarena for having arena "views"


Modified: pypy/branch/gc-experiments/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/lltypesystem/llarena.py	Sat Sep 20 15:20:00 2008
@@ -264,6 +264,9 @@
 # work with fakearenaaddresses on which arbitrary arithmetic is
 # possible even on top of the llinterpreter.
 
+# arena_new_view(ptr) is a no-op when translated, returns fresh view
+# on previous arena when run on top of llinterp
+
 def arena_malloc(nbytes, zero):
     """Allocate and return a new arena, optionally zero-initialized."""
     return Arena(nbytes, zero).getaddr(0)
@@ -299,6 +302,11 @@
     following an object.  For arenas containing heterogenous objects."""
     return RoundedUpForAllocation(size)
 
+def arena_new_view(ptr):
+    """Return a fresh memory view on an arena
+    """
+    return Arena(ptr.arena.nbytes, False).getaddr(0)
+
 # ____________________________________________________________
 #
 # Translation support: the functions above turn into the code below.
@@ -399,3 +407,9 @@
                   llimpl=llimpl_round_up_for_allocation,
                   llfakeimpl=round_up_for_allocation,
                   sandboxsafe=True)
+
+def llimpl_arena_new_view(addr):
+    return addr
+register_external(arena_new_view, [llmemory.Address], llmemory.Address,
+                  'll_arena.arena_new_view', llimpl=llimpl_arena_new_view,
+                  llfakeimpl=arena_new_view, sandboxsafe=True)

Modified: pypy/branch/gc-experiments/pypy/rpython/lltypesystem/test/test_llarena.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/lltypesystem/test/test_llarena.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/lltypesystem/test/test_llarena.py	Sat Sep 20 15:20:00 2008
@@ -4,7 +4,7 @@
 from pypy.rpython.lltypesystem.llarena import arena_malloc, arena_reset
 from pypy.rpython.lltypesystem.llarena import arena_reserve, arena_free
 from pypy.rpython.lltypesystem.llarena import round_up_for_allocation
-from pypy.rpython.lltypesystem.llarena import ArenaError
+from pypy.rpython.lltypesystem.llarena import ArenaError, arena_new_view
 
 def test_arena():
     S = lltype.Struct('S', ('x',lltype.Signed))
@@ -150,6 +150,13 @@
     arena_free(a)
     return 42
 
+def test_arena_new_view():
+    a = arena_malloc(50, False)
+    arena_reserve(a, precomputed_size)
+    # we can now allocate the same space in new view
+    b = arena_new_view(a)
+    arena_reserve(b, precomputed_size)
+
 def test_partial_arena_reset():
     a = arena_malloc(50, False)
     def reserve(i):



More information about the Pypy-commit mailing list