[pypy-commit] pypy default: write an helper function to make sure that we do not mutate the oplist. Not used anywhere so far
antocuni
noreply at buildbot.pypy.org
Mon May 16 11:20:26 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r44194:a190d9915b69
Date: 2011-05-16 11:29 +0200
http://bitbucket.org/pypy/pypy/changeset/a190d9915b69/
Log: write an helper function to make sure that we do not mutate the
oplist. Not used anywhere so far
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