[pypy-svn] r64608 - in pypy/branch/unicode_filename/pypy: module/posix rlib rpython/module

afa at codespeak.net afa at codespeak.net
Thu Apr 23 20:18:15 CEST 2009


Author: afa
Date: Thu Apr 23 20:18:13 2009
New Revision: 64608

Modified:
   pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py
   pypy/branch/unicode_filename/pypy/rlib/streamio.py
   pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py
Log:
Attempt to support unicode filenames for open() and os.open().
Don't know if this is RPython enough.


Modified: pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py	(original)
+++ pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py	Thu Apr 23 20:18:13 2009
@@ -12,15 +12,15 @@
 _WIN = sys.platform == 'win32'
 WIDE_FILENAMES = _WIN
 
-def open(space, fname, flag, mode=0777):
+def open(space, w_path, flag, mode=0777):
     """Open a file (for low level IO).
 Return a file descriptor (a small integer)."""
     try: 
-        fd = os.open(fname, flag, mode)
+        fd = wrapper(os.open)(space, w_path, (flag, mode))
     except OSError, e: 
         raise wrap_oserror(space, e) 
     return space.wrap(fd)
-open.unwrap_spec = [ObjSpace, str, int, int]
+open.unwrap_spec = [ObjSpace, W_Root, int, int]
 
 def lseek(space, fd, pos, how):
     """Set the current position of a file descriptor.  Return the new position.

Modified: pypy/branch/unicode_filename/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/rlib/streamio.py	(original)
+++ pypy/branch/unicode_filename/pypy/rlib/streamio.py	Thu Apr 23 20:18:13 2009
@@ -40,6 +40,8 @@
 import os, sys
 from pypy.rlib.rarithmetic import r_longlong, intmask
 
+_WIN32 = sys.platform == 'win32'
+
 from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
 O_BINARY = getattr(os, "O_BINARY", 0)
 
@@ -92,7 +94,10 @@
 
 def open_path_helper(path, os_flags, append):
     # XXX for now always return DiskFile
-    fd = os.open(path, os_flags, 0666)
+    if _WIN32 and isinstance(path, unicode):
+        fd = ll_os.os_wopen(path, os_flags, 0666)
+    else:
+        fd = os.open(path, os_flags, 0666)
     if append:
         try:
             os.lseek(fd, 0, 2)
@@ -165,10 +170,11 @@
 StreamErrors = (OSError, StreamError)     # errors that can generally be raised
 
 
-if sys.platform == "win32":
+if _WIN32:
     from pypy.rlib import rwin32
     from pypy.translator.tool.cbuild import ExternalCompilationInfo
     from pypy.rpython.lltypesystem import rffi
+    from pypy.rpython.module import ll_os
     import errno
 
     _eci = ExternalCompilationInfo()

Modified: pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py	Thu Apr 23 20:18:13 2009
@@ -82,6 +82,8 @@
                                   [('actime', rffi.INT),
                                    ('modtime', rffi.INT)])
 
+def os_wopen(path, flags, mode):
+    return os.open(path, flags, mode)
 
 class RegisterOs(BaseLazyRegistering):
 
@@ -687,12 +689,19 @@
         os_open = self.llexternal(underscore_on_windows+'open',
                                   [rffi.CCHARP, rffi.INT, rffi.MODE_T],
                                   rffi.INT)
+        os_wopen = self.llexternal(underscore_on_windows+'wopen',
+                                   [rffi.CWCHARP, rffi.INT, rffi.MODE_T],
+                                   rffi.INT)
 
         def os_open_llimpl(path, flags, mode):
-            result = rffi.cast(rffi.LONG, os_open(path, flags, mode))
+            if isinstance(path, str):
+                result = rffi.cast(rffi.LONG, os_open(path, flags, mode))
+            else:
+                result = rffi.cast(rffi.LONG, os_wopen(path, flags, mode))
             if result == -1:
                 raise OSError(rposix.get_errno(), "os_open failed")
             return result
+        os_open_llimpl._annspecialcase_ = 'specialize:argtype(0)'
 
         def os_open_oofakeimpl(o_path, flags, mode):
             return os.open(o_path._str, flags, mode)
@@ -700,6 +709,24 @@
         return extdef([str, int, int], int, "ll_os.ll_os_open",
                       llimpl=os_open_llimpl, oofakeimpl=os_open_oofakeimpl)
 
+    @registering(os_wopen)
+    def register_os_wopen(self):
+        os_wopen = self.llexternal(underscore_on_windows+'wopen',
+                                   [rffi.CWCHARP, rffi.INT, rffi.MODE_T],
+                                   rffi.INT)
+
+        def os_wopen_llimpl(path, flags, mode):
+            result = rffi.cast(rffi.LONG, os_wopen(path, flags, mode))
+            if result == -1:
+                raise OSError(rposix.get_errno(), "os_wopen failed")
+            return result
+
+        def os_wopen_oofakeimpl(o_path, flags, mode):
+            return os.open(o_path._str, flags, mode)
+
+        return extdef([str, int, int], int, "ll_os.ll_os_wopen",
+                      llimpl=os_wopen_llimpl, oofakeimpl=os_wopen_oofakeimpl)
+
 # ------------------------------- os.read -------------------------------
 
     @registering(os.read)



More information about the Pypy-commit mailing list