[pypy-svn] r59407 - in pypy/trunk/pypy: objspace/std rpython/lltypesystem translator/c/test

fijal at codespeak.net fijal at codespeak.net
Sat Oct 25 20:21:26 CEST 2008


Author: fijal
Date: Sat Oct 25 20:21:25 2008
New Revision: 59407

Removed:
   pypy/trunk/pypy/translator/c/test/test_overflow.py
Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/unicodeobject.py
   pypy/trunk/pypy/rpython/lltypesystem/rstr.py
Log:
Revert moving of overflow checking into rpython level, seems to be a bit ill


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Sat Oct 25 20:21:25 2008
@@ -504,11 +504,15 @@
         substrings_w.append(input[start:])
 
     try:
-        return space.wrap(by.join(substrings_w))
+        # XXX conservative estimate. If your strings are that close
+        # to overflowing, bad luck.
+        ovfcheck(len(substrings_w) * len(by) + len(input))
     except OverflowError:
         raise OperationError(
             space.w_OverflowError, 
-            space.wrap("replace string is too long"))        
+            space.wrap("replace string is too long"))
+    
+    return space.wrap(by.join(substrings_w))
 
 def _strip(space, w_self, w_chars, left, right):
     "internal function called by str_xstrip methods"

Modified: pypy/trunk/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/unicodeobject.py	Sat Oct 25 20:21:25 2008
@@ -801,13 +801,14 @@
         parts = _split_into_chars(self, maxsplit)
 
     try:
-        # XXX for some obscure reasons CPython can raise here OverflowError
-        #     *or* MemoryError, depends
-        return W_UnicodeObject(w_new._value.join(parts))
-    except (MemoryError, OverflowError):
+        ovfcheck(len(parts) * len(w_new._value) + len(w_self._value))
+    except OverflowError:
         raise OperationError(
             space.w_OverflowError, 
-            space.wrap("replace string is too long"))    
+            space.wrap("replace string is too long"))
+
+    return W_UnicodeObject(w_new._value.join(parts))
+    
 
 def unicode_encode__Unicode_ANY_ANY(space, w_unistr,
                                     w_encoding=None,

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 20:21:25 2008
@@ -17,7 +17,6 @@
 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
 
 # ____________________________________________________________
 #
@@ -354,17 +353,10 @@
             return s.empty()
         itemslen = 0
         i = 0
-        try:
-            while i < num_items:
-                lgt = len(items[i].chars)
-                itemslen = ovfcheck(itemslen + lgt)
-                i += 1
-            num_items_1 = num_items - 1
-            totalmalloc = ovfcheck(s_len * num_items_1)
-            totalmalloc = ovfcheck(itemslen + totalmalloc)
-        except OverflowError:
-            raise
-        result = s.malloc(totalmalloc)
+        while i < num_items:
+            itemslen += len(items[i].chars)
+            i += 1
+        result = s.malloc(itemslen + s_len * (num_items - 1))
         res_index = len(items[0].chars)
         s.copy_contents(items[0], result, 0, 0, res_index)
         i = 1
@@ -603,11 +595,7 @@
         itemslen = 0
         i = 0
         while i < num_items:
-            lgt = len(items[i].chars)
-            try:
-                itemslen = ovfcheck(itemslen + lgt)
-            except OverflowError:
-                raise
+            itemslen += len(items[i].chars)
             i += 1
         if typeOf(items).TO.OF.TO == STR:
             malloc = mallocstr



More information about the Pypy-commit mailing list