Author: Antonio Cuni <[email protected]>
Branch: 
Changeset: r44204:d05a7437ee20
Date: 2011-05-16 14:31 +0200
http://bitbucket.org/pypy/pypy/changeset/d05a7437ee20/

Log:    make get_deep_immutable_oplist returning an actual frozen list
        instead of a tuple, because a lot of places rely on it to be a list
        (e.g. to do operations + some_other_list)

diff --git a/pypy/jit/backend/x86/test/test_gc_integration.py 
b/pypy/jit/backend/x86/test/test_gc_integration.py
--- a/pypy/jit/backend/x86/test/test_gc_integration.py
+++ b/pypy/jit/backend/x86/test/test_gc_integration.py
@@ -54,7 +54,8 @@
         self.gcrefs = GcRefList()
         self.gcrefs.initialize()
         self.single_gcref_descr = GcPtrFieldDescr('', 0)
-        
+
+    replace_constptrs_with_getfield_raw = 
GcLLDescr_framework.replace_constptrs_with_getfield_raw.im_func
     rewrite_assembler = GcLLDescr_framework.rewrite_assembler.im_func
 
 class TestRegallocDirectGcIntegration(object):
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
@@ -627,13 +627,15 @@
     rop.PTR_NE: rop.PTR_NE,
     }
 
+
 def get_deep_immutable_oplist(operations):
     """
-    When not we_are_translated(), turns ``operations`` into a tuple and
+    When not we_are_translated(), turns ``operations`` into a frozenlist and
     monkey-patch its items to make sure they are not mutated.
 
     When we_are_translated(), do nothing and just return the old list.
     """
+    from pypy.tool.frozenlist import frozenlist
     if we_are_translated():
         return operations
     #
@@ -641,7 +643,7 @@
         assert False, "operations cannot change at this point"
     def setdescr(*args):
         assert False, "operations cannot change at this point"
-    newops = tuple(operations)
+    newops = frozenlist(operations)
     for op in newops:
         op.setarg = setarg
         op.setdescr = setdescr
diff --git a/pypy/tool/frozenlist.py b/pypy/tool/frozenlist.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/frozenlist.py
@@ -0,0 +1,19 @@
+from pypy.tool.sourcetools import func_with_new_name
+
+def forbid(*args):
+    raise TypeError, "cannot mutate a frozenlist"
+
+class frozenlist(list):
+    __setitem__  = func_with_new_name(forbid, '__setitem__')
+    __delitem__  = func_with_new_name(forbid, '__delitem__')
+    __setslice__ = func_with_new_name(forbid, '__setslice__')
+    __delslice__ = func_with_new_name(forbid, '__delslice__')
+    __iadd__     = func_with_new_name(forbid, '__iadd__')
+    __imul__     = func_with_new_name(forbid, '__imul__')
+    append       = func_with_new_name(forbid, 'append')
+    insert       = func_with_new_name(forbid, 'insert')
+    pop          = func_with_new_name(forbid, 'pop')
+    remove       = func_with_new_name(forbid, 'remove')
+    reverse      = func_with_new_name(forbid, 'reverse')
+    sort         = func_with_new_name(forbid, 'sort')
+    extend       = func_with_new_name(forbid, 'extend')
diff --git a/pypy/tool/test/test_frozenlist.py 
b/pypy/tool/test/test_frozenlist.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/test/test_frozenlist.py
@@ -0,0 +1,21 @@
+import py
+from pypy.tool.frozenlist import frozenlist
+
+def test_frozenlist():
+    l = frozenlist([1, 2, 3])
+    assert l[0] == 1
+    assert l[:2] == [1, 2]
+    assert l.index(2) == 1
+    py.test.raises(TypeError, "l[0] = 1")
+    py.test.raises(TypeError, "del l[0]")
+    py.test.raises(TypeError, "l[:] = []")
+    py.test.raises(TypeError, "del l[:]")
+    py.test.raises(TypeError, "l += []")
+    py.test.raises(TypeError, "l *= 2")
+    py.test.raises(TypeError, "l.append(1)")
+    py.test.raises(TypeError, "l.insert(0, 0)")
+    py.test.raises(TypeError, "l.pop()")
+    py.test.raises(TypeError, "l.remove(1)")
+    py.test.raises(TypeError, "l.reverse()")
+    py.test.raises(TypeError, "l.sort()")
+    py.test.raises(TypeError, "l.extend([])")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to