Author: Matti Picus <[email protected]>
Branch: unicode-utf8-py3
Changeset: r95263:78258e983d74
Date: 2018-10-31 23:14 +0200
http://bitbucket.org/pypy/pypy/changeset/78258e983d74/

Log:    convert File{En,De}codingObject to unicode via traits.as_str0, fix
        translation

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -80,13 +80,15 @@
     errorhandler=state.decode_error_handler
     if _WIN32:
         bytes = space.bytes_w(w_string)
-        uni = str_decode_mbcs(bytes, 'strict', True, errorhandler,
-                              force_ignore=False)[0]
+        slen = len(bytes)
+        uni, size = runicode.str_decode_mbcs(bytes, slen, 'strict', final=True,
+                           errorhandler=errorhandler, force_ignore=False)
     elif _MACOSX:
         bytes = space.bytes_w(w_string)
-        uni = str_decode_utf8(
+        utf8 = str_decode_utf8(
             bytes, 'surrogateescape', final=True,
             allow_surrogates=False)[0]
+        uni = space.realunicode_w(utf8)
     elif space.sys.filesystemencoding is None or state.codec_need_encodings:
         # bootstrap check: if the filesystemencoding isn't initialized
         # or the filesystem codec is implemented in Python we cannot
@@ -101,6 +103,7 @@
         return space.call_method(w_string, 'decode',
                                  getfilesystemencoding(space),
                                  space.newtext('surrogateescape'))
+    assert isinstance(uni, unicode)
     return space.newtext(runicode.unicode_encode_utf_8(uni,
                                  len(uni), 'strict', allow_surrogates=True), 
len(uni))
 
diff --git a/pypy/module/_cffi_backend/errorbox.py 
b/pypy/module/_cffi_backend/errorbox.py
--- a/pypy/module/_cffi_backend/errorbox.py
+++ b/pypy/module/_cffi_backend/errorbox.py
@@ -89,7 +89,7 @@
                 return
 
             w_text = self.space.call_function(w_done)
-            p = rffi.unicode2wcharp(self.space.utf8_w(w_text),
+            p = rffi.unicode2wcharp(self.space.realunicode_w(w_text),
                                     track_allocation=False)
             if self.text_p:
                 rffi.free_wcharp(self.text_p, track_allocation=False)
diff --git a/pypy/module/posix/interp_nt.py b/pypy/module/posix/interp_nt.py
--- a/pypy/module/posix/interp_nt.py
+++ b/pypy/module/posix/interp_nt.py
@@ -96,7 +96,7 @@
             raise LLNotImplemented("GetFinalPathNameByHandle not available on "
                                    "this platform")
 
-        hFile = win32traits.CreateFile(path, 0, 0, None,
+        hFile = win32traits.CreateFile(traits.as_str0(path), 0, 0, None,
                                        win32traits.OPEN_EXISTING,
                                        win32traits.FILE_FLAG_BACKUP_SEMANTICS,
                                        rwin32.NULL_HANDLE)
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -56,7 +56,10 @@
         return self.space.fsencode_w(self.w_obj)
 
     def as_unicode(self):
-        return self.space.utf8_w(self.w_obj).decode('utf8')
+        ret = self.space.realunicode_w(self.w_obj)
+        if u'\x00' in ret:
+            raise oefmt(self.space.w_ValueError, "embedded null character")
+        return ret
 
 class FileDecoder(object):
     is_unicode = False
@@ -69,7 +72,10 @@
         return self.space.bytesbuf0_w(self.w_obj)
 
     def as_unicode(self):
-        return self.space.fsdecode_w(self.w_obj)
+        ret = self.space.fsdecode_w(self.w_obj)
+        if u'\x00' in ret:
+            raise oefmt(self.space.w_ValueError, "embedded null character")
+        return ret
 
 @specialize.memo()
 def make_dispatch_function(func, tag, allow_fd_fn=None):
@@ -889,7 +895,7 @@
         # started through main() instead of wmain()
         rwin32._wgetenv(u"")
         for key, value in rwin32._wenviron_items():
-            space.setitem(w_env, space.newtext(key), space.newunicode(value))
+            space.setitem(w_env, space.newtext(key), space.newtext(value))
 
     @unwrap_spec(name=unicode, value=unicode)
     def putenv(space, name, value):
diff --git a/rpython/rlib/_os_support.py b/rpython/rlib/_os_support.py
--- a/rpython/rlib/_os_support.py
+++ b/rpython/rlib/_os_support.py
@@ -64,6 +64,8 @@
         assert path is not None
         if isinstance(path, unicode):
             return path
+        elif isinstance(path, str):
+            raise RuntimeError('str given where unicode expected')
         else:
             return path.as_unicode()
 
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -137,10 +137,7 @@
         RPY_EXTERN void exit_suppress_iph(void* handle) {};
         #endif
     ''',]
-    post_include_bits=['RPY_EXTERN int _PyVerify_fd(int);',
-                       'RPY_EXTERN void* enter_suppress_iph();',
-                       'RPY_EXTERN void exit_suppress_iph(void* handle);',
-                      ]
+    post_include_bits=['RPY_EXTERN int _PyVerify_fd(int);']
 else:
     separate_module_sources = []
     post_include_bits = []
@@ -238,8 +235,7 @@
             rthread.tlfield_rpy_errno.setraw(_get_errno())
             # ^^^ keep fork() up-to-date too, below
 if _WIN32:
-    includes = ['io.h', 'sys/utime.h', 'sys/types.h', 'process.h', 'time.h',
-                'direct.h']
+    includes = ['io.h', 'sys/utime.h', 'sys/types.h', 'process.h', 'time.h']
     libraries = []
 else:
     if sys.platform.startswith(('darwin', 'netbsd', 'openbsd')):
diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py
--- a/rpython/rlib/rposix_stat.py
+++ b/rpython/rlib/rposix_stat.py
@@ -685,8 +685,7 @@
         # XXX 'traverse' is ignored, and everything related to
         # the "reparse points" is missing
         win32traits = make_win32_traits(traits)
-
-        hFile = win32traits.CreateFile(path,
+        hFile = win32traits.CreateFile(traits.as_str0(path),
             win32traits.FILE_READ_ATTRIBUTES,
             0,
             lltype.nullptr(rwin32.LPSECURITY_ATTRIBUTES.TO),
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to