[pypy-svn] r59400 - in pypy/trunk/pypy: rpython/lltypesystem translator/c/test

fijal at codespeak.net fijal at codespeak.net
Sat Oct 25 15:19:52 CEST 2008


Author: fijal
Date: Sat Oct 25 15:19:50 2008
New Revision: 59400

Added:
   pypy/trunk/pypy/translator/c/test/test_overflow.py   (contents, props changed)
Modified:
   pypy/trunk/pypy/rpython/lltypesystem/rstr.py
Log:
A test and a check for single overflow point, more to come


Modified: pypy/trunk/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rstr.py	Sat Oct 25 15:19:50 2008
@@ -17,6 +17,7 @@
 from pypy.rpython.rmodel import Repr
 from pypy.rpython.lltypesystem import llmemory
 from pypy.tool.sourcetools import func_with_new_name
+from pypy.rlib.rarithmetic import ovfcheck
 
 # ____________________________________________________________
 #
@@ -595,7 +596,11 @@
         itemslen = 0
         i = 0
         while i < num_items:
-            itemslen += len(items[i].chars)
+            lgt = len(items[i].chars)
+            try:
+                itemslen = ovfcheck(itemslen + lgt)
+            except OverflowError:
+                raise
             i += 1
         if typeOf(items).TO.OF.TO == STR:
             malloc = mallocstr

Added: pypy/trunk/pypy/translator/c/test/test_overflow.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/translator/c/test/test_overflow.py	Sat Oct 25 15:19:50 2008
@@ -0,0 +1,19 @@
+
+""" This is a test that should be in rpython directory. The thing is that
+on top of llinterp these tests take forever, so they're here. They usually
+segfault when run on top of C, hence inheritance from AbstractGCTestClass
+"""
+
+import py
+from pypy.translator.c.test.test_boehm import AbstractGCTestClass
+
+class TestOverflow(AbstractGCTestClass):
+    def test_overflow(self):
+        def f(i):
+            x = "A" * (2 << i)
+            ''.join([x] * (2 << i))
+
+        fn = self.getcompiled(f, [int])
+        py.test.raises(OverflowError, fn, 16)
+        # XXX - we cannot grab overflow check inside test, for obscure
+        #       graph related reasons it gets propagated anyway



More information about the Pypy-commit mailing list