[pypy-commit] pypy default: merge

cfbolz noreply at buildbot.pypy.org
Mon May 16 11:22:52 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r44198:d19a4c4aa69a
Date: 2011-05-16 11:31 +0200
http://bitbucket.org/pypy/pypy/changeset/d19a4c4aa69a/

Log:	merge

diff --git a/pypy/jit/metainterp/resoperation.py b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -626,3 +626,23 @@
     rop.PTR_EQ: rop.PTR_EQ,
     rop.PTR_NE: rop.PTR_NE,
     }
+
+def get_deep_immutable_oplist(operations):
+    """
+    When not we_are_translated(), turns ``operations`` into a tuple and
+    monkey-patch its items to make sure they are not mutated.
+
+    When we_are_translated(), do nothing and just return the old list.
+    """
+    if we_are_translated():
+        return operations
+    #
+    def setarg(*args):
+        assert False, "operations cannot change at this point"
+    def setdescr(*args):
+        assert False, "operations cannot change at this point"
+    newops = tuple(operations)
+    for op in newops:
+        op.setarg = setarg
+        op.setdescr = setdescr
+    return newops
diff --git a/pypy/jit/metainterp/test/test_resoperation.py b/pypy/jit/metainterp/test/test_resoperation.py
--- a/pypy/jit/metainterp/test/test_resoperation.py
+++ b/pypy/jit/metainterp/test/test_resoperation.py
@@ -68,3 +68,11 @@
     call = rop.ResOperation(rop.rop.CALL, ['a', 'b'], 'c', descr=mydescr)
     assert call.can_malloc()
     assert not rop.ResOperation(rop.rop.INT_ADD, ['a', 'b'], 'c').can_malloc()
+
+def test_get_deep_immutable_oplist():
+    ops = [rop.ResOperation(rop.rop.INT_ADD, ['a', 'b'], 'c')]
+    newops = rop.get_deep_immutable_oplist(ops)
+    py.test.raises(AttributeError, "newops.append('foobar')")
+    py.test.raises(TypeError, "newops[0] = 'foobar'")
+    py.test.raises(AssertionError, "newops[0].setarg(0, 'd')")
+    py.test.raises(AssertionError, "newops[0].setdescr('foobar')")


More information about the pypy-commit mailing list