[pypy-commit] pypy unicode-utf8-py3: win32 fixes, still uses runicode for str_decode_mbcs

mattip pypy.commits at gmail.com
Mon Feb 11 04:11:53 EST 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95934:18628545b899
Date: 2019-02-11 11:10 +0200
http://bitbucket.org/pypy/pypy/changeset/18628545b899/

Log:	win32 fixes, still uses runicode for str_decode_mbcs

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -637,8 +637,7 @@
             lgt = len(msg)
         w_errno = space.w_None
         w_winerror = space.newint(winerror)
-        msg_utf8 = rutf8.str_encode_utf_8(msg, lgt, 'strict')
-        w_msg = space.newtext(msg_utf8, lgt)
+        w_msg = space.newtext(msg, lgt)
     else:
         errno = e.errno
         if errno == EINTR:
diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -321,8 +321,8 @@
         from rpython.rlib import runicode
         res, size = runicode.str_decode_mbcs(s, slen, errors, final=final,
                            errorhandler=errorhandler, force_ignore=force_ignore)
-        res_utf8 = unicode_encode_utf_8(res, len(res), 'strict')
-        return res_utf8, len(res), len(res)
+        res_utf8 = runicode.unicode_encode_utf_8(res, size, 'strict')
+        return res_utf8, len(res), size
 
 def str_decode_utf8(s, errors, final, errorhandler, allow_surrogates=False):
     """ Same as checking for the valid utf8, but we know the utf8 is not
diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -306,7 +306,7 @@
         return result
 
     def llimpl_FormatErrorW(code):
-        "Return a unicode message corresponding to the given Windows error code."
+        "Return a utf8-encoded msg and its length"
         buf = lltype.malloc(rffi.CWCHARPP.TO, 1, flavor='raw')
         buf[0] = lltype.nullptr(rffi.CWCHARP.TO)
         try:
@@ -327,7 +327,8 @@
                 buflen -= 1
 
             if buflen <= 0:
-                result = u'Windows Error %d' % (code,)
+                msg = 'Windows Error %d' % (code,)
+                result = msg, len(msg)
             else:
                 result = rffi.wcharpsize2utf8(s_buf, buflen), buflen
         finally:


More information about the pypy-commit mailing list