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

tismer at codespeak.net tismer at codespeak.net
Thu Mar 16 04:39:32 CET 2006


Author: tismer
Date: Thu Mar 16 04:39:21 2006
New Revision: 24422

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
   pypy/dist/pypy/rpython/memory/test/test_gctransform.py
Log:
added new operations to gctransform which control extra liveness of objects

Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Thu Mar 16 04:39:21 2006
@@ -109,6 +109,8 @@
                 ops, cleanup_before_exception = res
             except ValueError:
                 ops, cleanup_before_exception, num_ops_after_exc_raising = res
+            if not ops:
+                continue # may happen when we eat gc_increase_aliveness etc.
             newops.extend(ops)
             op = ops[-1-num_ops_after_exc_raising]
             # XXX for now we assume that everything can raise
@@ -212,6 +214,14 @@
         result = varoftype(lltype.Void)
         return [SpaceOperation("gc_pop_alive_pyobj", [var], result)]
 
+    def replace_gc_protect(self, op, livevars):
+        """ protect this object from gc (make it immortal) """
+        return [], []
+
+    def replace_gc_unprotect(self, op, livevars):
+        """ get this object back into gc control """
+        return [], []
+
     def annotate_helper(self, ll_helper, ll_args, ll_result):
         assert not self.finished
         args_s = map(annmodel.lltype_to_annotation, ll_args)
@@ -354,6 +364,14 @@
                                      varoftype(lltype.Void), cleanup=None))
         return result
 
+    def replace_gc_protect(self, op, livevars):
+        """ protect this object from gc (make it immortal) """
+        return self.push_alive(op.args[0]), []
+
+    def replace_gc_unprotect(self, op, livevars):
+        """ get this object back into gc control """
+        return self.pop_alive(op.args[0]), []
+
     def replace_setfield(self, op, livevars):
         if not var_needsgc(op.args[2]):
             return [op], []

Modified: pypy/dist/pypy/rpython/memory/test/test_gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_gctransform.py	Thu Mar 16 04:39:21 2006
@@ -4,6 +4,8 @@
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.rpython.lltypesystem import lltype
 from pypy.objspace.flow.model import Variable
+from pypy.annotation import model as annmodel
+from pypy.rpython import extregistry
 from pypy import conftest
 
 import py
@@ -214,6 +216,33 @@
         elif op.opname == 'gc_pop_alive_pyobj':
             pop_count += 1
     assert push_count == 0 and pop_count == 1
+
+def test_protect_unprotect():
+    def protect(obj): RaiseNameError
+    def unprotect(obj): RaiseNameError
+    def rtype_protect(hop):
+        v_any, = hop.inputargs(hop.args_r[0])
+        return hop.genop('gc_protect', [v_any], resulttype=lltype.Void)
+    def rtype_unprotect(hop):
+        v_any, = hop.inputargs(hop.args_r[0])
+        return hop.genop('gc_unprotect', [v_any], resulttype=lltype.Void)
+    extregistry.register_value(protect,
+        compute_result_annotation=annmodel.s_None, specialize_call=rtype_protect)
+    extregistry.register_value(unprotect,
+        compute_result_annotation=annmodel.s_None, specialize_call=rtype_unprotect)
+
+    def p():    protect('this is an object')
+    def u():    unprotect('this is an object')
+
+    rgc = gctransform.RefcountingGCTransformer
+    bgc = gctransform.BoehmGCTransformer
+    expected = [1, 1, 0, 0]
+    gcs = [rgc, rgc, bgc, bgc]
+    fs = [p, u, p, u]
+    for ex, f, gc in zip(expected, fs, gcs):
+        t, transformer = rtype_and_transform(f, [], gc, check=False)
+        ops = getops(graphof(t, f))
+        assert len(ops.get('direct_call', [])) == ex
     
 def test_except_block():
     S = lltype.GcStruct("S", ('x', lltype.Signed))



More information about the Pypy-commit mailing list