[pypy-commit] pypy py3k: Fix a Rpython crash in test_socket

amauryfa noreply at buildbot.pypy.org
Sun Feb 15 19:43:20 CET 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r75901:62c9e1cde45a
Date: 2015-02-15 17:49 +0100
http://bitbucket.org/pypy/pypy/changeset/62c9e1cde45a/

Log:	Fix a Rpython crash in test_socket

diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -10,7 +10,8 @@
 import sys
 import time
 
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
+pypy_path = os.path.join(os.path.dirname(__file__), '..', '..')
+sys.path.insert(0, os.path.abspath(pypy_path))
 
 from pypy.tool import option
 from pypy.interpreter import main, interactive, error, gateway
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -67,8 +67,11 @@
             return identifier
         u = self._value
         eh = unicodehelper.encode_error_handler(space)
-        identifier = unicode_encode_utf_8(u, len(u), None,
-                                          errorhandler=eh)
+        try:
+            identifier = unicode_encode_utf_8(u, len(u), None,
+                                              errorhandler=eh)
+        except unicodehelper.RUnicodeEncodeError, ue:
+            raise wrap_encode_error(space, ue)
         self._utf8 = identifier
         return identifier
 
@@ -499,13 +502,7 @@
                     return space.wrapbytes(unicode_encode_utf_8(
                             u, len(u), None, errorhandler=eh))
             except unicodehelper.RUnicodeEncodeError, ue:
-                raise OperationError(space.w_UnicodeEncodeError,
-                                     space.newtuple([
-                    space.wrap(ue.encoding),
-                    space.wrap(ue.object),
-                    space.wrap(ue.start),
-                    space.wrap(ue.end),
-                    space.wrap(ue.reason)]))
+                raise wrap_encode_error(space, ue)
         from pypy.module._codecs.interp_codecs import lookup_codec
         w_encoder = space.getitem(lookup_codec(space, encoding), space.wrap(0))
     if errors is None:
@@ -521,6 +518,16 @@
     return w_retval
 
 
+def wrap_encode_error(space, ue):
+    raise OperationError(space.w_UnicodeEncodeError,
+                         space.newtuple([
+        space.wrap(ue.encoding),
+        space.wrap(ue.object),
+        space.wrap(ue.start),
+        space.wrap(ue.end),
+        space.wrap(ue.reason)]))
+
+
 def decode_object(space, w_obj, encoding, errors):
     if encoding is None:
         encoding = getdefaultencoding(space)


More information about the pypy-commit mailing list