[pypy-svn] r57939 - in pypy/branch/tuple-nonresizable-395/pypy/annotation: . test
fijal at codespeak.net
fijal at codespeak.net
Sun Sep 7 12:56:09 CEST 2008
Author: fijal
Date: Sun Sep 7 12:56:07 2008
New Revision: 57939
Modified:
pypy/branch/tuple-nonresizable-395/pypy/annotation/listdef.py
pypy/branch/tuple-nonresizable-395/pypy/annotation/test/test_annrpython.py
Log:
add dont_resize hint to listitem, useful for debugging
Modified: pypy/branch/tuple-nonresizable-395/pypy/annotation/listdef.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/annotation/listdef.py (original)
+++ pypy/branch/tuple-nonresizable-395/pypy/annotation/listdef.py Sun Sep 7 12:56:07 2008
@@ -26,6 +26,7 @@
self.bookkeeper = bookkeeper
self.itemof = {} # set of all ListDefs using this ListItem
self.read_locations = {}
+ self.dont_resize = False
if bookkeeper is None:
self.dont_change_any_more = True
@@ -37,7 +38,7 @@
def resize(self):
if not self.resized:
- if self.dont_change_any_more:
+ if self.dont_change_any_more or self.dont_resize:
raise TooLateForChange
self.resized = True
@@ -181,6 +182,9 @@
self.listitem.mutate()
self.listitem.resize()
+ def dont_resize_any_more(self):
+ self.listitem.dont_resize = True
+
MOST_GENERAL_LISTDEF = ListDef(None, SomeObject())
Modified: pypy/branch/tuple-nonresizable-395/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/branch/tuple-nonresizable-395/pypy/annotation/test/test_annrpython.py Sun Sep 7 12:56:07 2008
@@ -10,7 +10,7 @@
from pypy.translator.translator import graphof as tgraphof
from pypy.annotation import policy
from pypy.annotation import specialize
-from pypy.annotation.listdef import ListDef
+from pypy.annotation.listdef import ListDef, TooLateForChange
from pypy.annotation.dictdef import DictDef
from pypy.objspace.flow.model import *
from pypy.rlib.rarithmetic import r_uint, base_int, r_longlong, r_ulonglong
@@ -3040,6 +3040,28 @@
a.build_types(f, [str])
+ def test_listitem_no_mutating(self):
+ from pypy.rlib.debug import check_annotation
+ called = []
+
+ def checker(ann, bk):
+ called.append(True)
+ assert not ann.listdef.listitem.mutated
+ ann.listdef.dont_resize_any_more()
+
+ def f():
+ l = [1,2,3]
+ check_annotation(l, checker)
+ return l
+
+ def g():
+ l = f()
+ l.append(4)
+
+ a = self.RPythonAnnotator()
+ py.test.raises(TooLateForChange, a.build_types, g, [])
+ assert called
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list