Author: Matti Picus <matti.pi...@gmail.com>
Branch: codec_errorhandler
Changeset: r97397:2935e5510fa8
Date: 2019-09-07 12:01 +0200
http://bitbucket.org/pypy/pypy/changeset/2935e5510fa8/

Log:    disallow changing the exc.object since we cannot modify the input
        bytes in-place

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -1180,7 +1180,7 @@
             result.append(r)
     r = result.build()
     lgt = rutf8.check_utf8(r, True)
-    return result.build(), lgt, pos, bo
+    return r, lgt, pos, bo
 
 def _STORECHAR(result, CH, byteorder):
     hi = chr(((CH) >> 8) & 0xff)
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -83,6 +83,15 @@
                     msg = ("encoding error handler must return "
                            "(str/bytes, int) tuple")
                 raise OperationError(space.w_TypeError, space.newtext(msg))
+            # PyPy does not support modifying the input string (the exc.object)
+            # CPython copies back the un-decoded part, since it can modify the
+            # input in-place
+            inputobj = space.bytes_w(space.getattr(w_exc,
+                                                   space.newtext('object')))
+            if input != inputobj 
+                raise oefmt(space.w_RuntimeError,
+                            "PyPy does not support modifying the exc.object "
+                            "in an error handler")
             try:
                 newpos = space.int_w(w_newpos)
             except OperationError as e:
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -1006,7 +1006,7 @@
                                    1, 1 + n, "ouch")
             ) == (s[:1], 1 + n)
 
-    def test_replace_with_long(self):
+    def test_replace_with_longer(self):
         #bpo-32583
         import codecs
         def replace_with_long(exc):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to