[pypy-svn] r59402 - pypy/trunk/pypy/objspace/std

fijal at codespeak.net fijal at codespeak.net
Sat Oct 25 15:38:05 CEST 2008


Author: fijal
Date: Sat Oct 25 15:38:03 2008
New Revision: 59402

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/unicodeobject.py
Log:
Hum. I'm not sure if this is correct level, but handle unicode object
overflows this way


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 15:38:03 2008
@@ -504,15 +504,11 @@
         substrings_w.append(input[start:])
 
     try:
-        # XXX conservative estimate. If your strings are that close
-        # to overflowing, bad luck.
-        ovfcheck(len(substrings_w) * len(by) + len(input))
+        return space.wrap(by.join(substrings_w))
     except OverflowError:
         raise OperationError(
             space.w_OverflowError, 
-            space.wrap("replace string is too long"))
-    
-    return space.wrap(by.join(substrings_w))
+            space.wrap("replace string is too long"))        
 
 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 15:38:03 2008
@@ -801,14 +801,13 @@
         parts = _split_into_chars(self, maxsplit)
 
     try:
-        ovfcheck(len(parts) * len(w_new._value) + len(w_self._value))
-    except OverflowError:
+        # XXX for some obscure reasons CPython can raise here OverflowError
+        #     *or* MemoryError, depends
+        return W_UnicodeObject(w_new._value.join(parts))
+    except (MemoryError, OverflowError):
         raise OperationError(
             space.w_OverflowError, 
-            space.wrap("replace string is too long"))
-
-    return W_UnicodeObject(w_new._value.join(parts))
-    
+            space.wrap("replace string is too long"))    
 
 def unicode_encode__Unicode_ANY_ANY(space, w_unistr,
                                     w_encoding=None,



More information about the Pypy-commit mailing list