[pypy-svn] r33062 - in pypy/dist/pypy: rpython rpython/lltypesystem rpython/memory/gctransform translator/c translator/c/test

mwh at codespeak.net mwh at codespeak.net
Mon Oct 9 16:54:37 CEST 2006


Author: mwh
Date: Mon Oct  9 16:54:35 2006
New Revision: 33062

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/memory/gctransform/transform.py
   pypy/dist/pypy/translator/c/exceptiontransform.py
   pypy/dist/pypy/translator/c/test/test_exceptiontransform.py
Log:
have the exception transformer insert a 'zero_gc_pointers_inside' operation for
the gc transformer to use, though it doesn't actually use it yet.


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Mon Oct  9 16:54:35 2006
@@ -629,6 +629,9 @@
         assert isinstance(flavor, str)
         self.heap.free(obj, flavor=flavor)
 
+    def op_zero_gc_pointers_inside(self, obj):
+        pass
+
     def op_getfield(self, obj, field):
         checkptr(obj)
         # check the difference between op_getfield and op_getsubstruct:

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Mon Oct  9 16:54:35 2006
@@ -294,6 +294,7 @@
     'zero_malloc':          LLOp(canraise=(MemoryError,), canunwindgc=True),
     'malloc_varsize':       LLOp(canraise=(MemoryError,), canunwindgc=True),
     'zero_malloc_varsize':  LLOp(canraise=(MemoryError,), canunwindgc=True),
+    'zero_gc_pointers_inside': LLOp(),
     'flavored_malloc':      LLOp(canraise=(MemoryError,)),
     'flavored_free':        LLOp(),
     'getfield':             LLOp(sideeffects=False, canrun=True),

Modified: pypy/dist/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/transform.py	Mon Oct  9 16:54:35 2006
@@ -316,6 +316,9 @@
     def gct_safe_call(self, hop):
         hop.rename("direct_call")
 
+    def gct_zero_gc_pointers_inside(self, hop):
+        pass
+
 class MinimalGCTransformer(GCTransformer):
     def __init__(self, parenttransformer):
         GCTransformer.__init__(self, parenttransformer.translator)

Modified: pypy/dist/pypy/translator/c/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/c/exceptiontransform.py	(original)
+++ pypy/dist/pypy/translator/c/exceptiontransform.py	Mon Oct  9 16:54:35 2006
@@ -338,6 +338,30 @@
 
         block.recloseblock(l0, l)
 
+        insert_zeroing_op = False
+        if spaceop.opname == 'malloc':
+            insert_zeroing_op = True
+        elif spaceop.opname == 'flavored_malloc':
+            flavor = op.args[0].value
+            if flavor.startswith('gc'):
+                insert_zeroing_op = True
+
+        if insert_zeroing_op:
+            if normalafterblock is None:
+                normalafterblock = insert_empty_block(None, l0)
+            v_result = spaceop.result
+            if v_result in l0.args:
+                result_i = l0.args.index(v_result)
+                v_result_after = normalafterblock.inputargs[result_i]
+            else:
+                v_result_after = copyvar(None, v_result)
+                l0.args.append(v_result)
+                normalafterblock.inputargs.append(v_result_after)
+            normalafterblock.operations.insert(
+                0, SpaceOperation('zero_gc_pointers_inside',
+                                  [v_result_after],
+                                  varoftype(lltype.Void)))
+
         if self.always_exc_clear:
             # insert code that clears the exception even in the non-exceptional
             # case...  this is a hint for the JIT, but pointless otherwise

Modified: pypy/dist/pypy/translator/c/test/test_exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_exceptiontransform.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_exceptiontransform.py	Mon Oct  9 16:54:35 2006
@@ -187,3 +187,19 @@
     etrafo.create_exception_handling(g)
     etrafo2 = exceptiontransform.ExceptionTransformer(t)
     py.test.raises(AssertionError, etrafo2.create_exception_handling, g)
+
+def test_inserting_zeroing_op():
+    from pypy.rpython.lltypesystem import lltype
+    S = lltype.GcStruct("S", ('x', lltype.Signed))
+    def f(x):
+        s = lltype.malloc(S)
+        s.x = 0
+        return s.x
+    t = TranslationContext()
+    t.buildannotator().build_types(f, [int])
+    t.buildrtyper().specialize()
+    g = graphof(t, f)
+    etrafo = exceptiontransform.ExceptionTransformer(t)
+    etrafo.create_exception_handling(g)
+    ops = dict.fromkeys([o.opname for b, o in g.iterblockops()])
+    assert 'zero_gc_pointers_inside' in ops



More information about the Pypy-commit mailing list