[pypy-svn] r57944 - in pypy/branch/tuple-nonresizable-395/pypy/rlib: . test

fijal at codespeak.net fijal at codespeak.net
Sun Sep 7 14:08:02 CEST 2008


Author: fijal
Date: Sun Sep  7 14:07:59 2008
New Revision: 57944

Modified:
   pypy/branch/tuple-nonresizable-395/pypy/rlib/debug.py
   pypy/branch/tuple-nonresizable-395/pypy/rlib/test/test_debug.py
Log:
Add make_sure_not_resized


Modified: pypy/branch/tuple-nonresizable-395/pypy/rlib/debug.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/rlib/debug.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/rlib/debug.py	Sun Sep  7 14:07:59 2008
@@ -80,3 +80,21 @@
         hop.exception_cannot_occur()
         return hop.inputarg(hop.args_r[0], arg=0)
 
+def make_sure_not_resized(arg):
+    """ Function checking whether annotation of SomeList is never resized,
+    useful for debugging. Does nothing when run directly
+    """
+    pass
+
+class Entry(ExtRegistryEntry):
+    _about_ = make_sure_not_resized
+
+    def compute_result_annotation(self, s_arg):
+        from pypy.annotation.model import SomeList
+        assert isinstance(s_arg, SomeList)
+        s_arg.listdef.never_resize()
+        return s_arg
+    
+    def specialize_call(self, hop):
+        hop.exception_cannot_occur()
+        return hop.inputarg(hop.args_r[0], arg=0)

Modified: pypy/branch/tuple-nonresizable-395/pypy/rlib/test/test_debug.py
==============================================================================
--- pypy/branch/tuple-nonresizable-395/pypy/rlib/test/test_debug.py	(original)
+++ pypy/branch/tuple-nonresizable-395/pypy/rlib/test/test_debug.py	Sun Sep  7 14:07:59 2008
@@ -1,6 +1,6 @@
 
 import py
-from pypy.rlib.debug import check_annotation
+from pypy.rlib.debug import check_annotation, make_sure_not_resized
 from pypy.rpython.test.test_llinterp import interpret
 
 def test_check_annotation():
@@ -27,3 +27,12 @@
 
     py.test.raises(Error, "interpret(g, [3])")
 
+def test_make_sure_not_resized():
+    from pypy.annotation.listdef import TooLateForChange
+    def f():
+        result = [1,2,3]
+        make_sure_not_resized(result)
+        result.append(4)
+        return len(result)
+
+    py.test.raises(TooLateForChange, interpret, f, [])



More information about the Pypy-commit mailing list