[pypy-svn] r76255 - pypy/branch/unicode_filename-2/pypy/rpython/module

afa at codespeak.net afa at codespeak.net
Fri Jul 16 14:12:33 CEST 2010


Author: afa
Date: Fri Jul 16 14:12:31 2010
New Revision: 76255

Modified:
   pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
   pypy/branch/unicode_filename-2/pypy/rpython/module/ll_win32file.py
Log:
more progress


Modified: pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py	Fri Jul 16 14:12:31 2010
@@ -88,7 +88,8 @@
     str = str
     CHAR = rffi.CHAR
     CCHARP = rffi.CCHARP
-    str2charp = rffi.str2charp
+    charp2str = staticmethod(rffi.charp2str)
+    str2charp = staticmethod(rffi.str2charp)
 
     @staticmethod
     def posix_function_name(name):
@@ -102,7 +103,8 @@
     str = unicode
     CHAR = rffi.WCHAR_T
     CCHARP = rffi.CWCHARP
-    str2charp = rffi.wcharp2unicode
+    charp2str = staticmethod(rffi.wcharp2unicode)
+    str2charp = staticmethod(rffi.unicode2wcharp)
 
     @staticmethod
     def posix_function_name(name):
@@ -1100,73 +1102,17 @@
                       export_name=traits.ll_os_name("access"),
                       oofakeimpl=os_access_oofakeimpl)
 
-    @registering_if(posix, '_getfullpathname')
-    def register_posix__getfullpathname(self):
-        from pypy.rlib import rwin32
-        # this nt function is not exposed via os, but needed
-        # to get a correct implementation of os.abspath
-        # XXX why do we ignore WINAPI conventions everywhere?
-        LPSTRP = rffi.CArrayPtr(rwin32.LPSTR)
-        GetFullPathName = self.llexternal(
-            'GetFullPathNameA',
-            [rwin32.LPCSTR,
-             rwin32.DWORD,
-             rwin32.LPSTR,
-             rffi.CArrayPtr(rwin32.LPSTR)],
-            rwin32.DWORD)
-
-        def _getfullpathname_llimpl(lpFileName):
-            nBufferLength = rwin32.MAX_PATH + 1
-            lpBuffer = lltype.malloc(rwin32.LPSTR.TO, nBufferLength, flavor='raw')
-            try:
-                res = GetFullPathName(
-                    lpFileName, rffi.cast(rwin32.DWORD, nBufferLength),
-                    lpBuffer, lltype.nullptr(LPSTRP.TO))
-                if res == 0:
-                    raise rwin32.lastWindowsError("_getfullpathname failed")
-                result = rffi.charp2str(lpBuffer)
-                return result
-            finally:
-                lltype.free(lpBuffer, flavor='raw')
-
-        return extdef([str],  # a single argument which is a str
-                      str,    # returns a string
-                      "ll_os.posix__getfullpathname",
-                      llimpl=_getfullpathname_llimpl)
-
-    @registering_unicode_version(getattr(posix, '_getfullpathname', None),
-                                 [unicode], sys.platform=='win32')
-    def register_posix__getfullpathname_unicode(self):
-        from pypy.rlib import rwin32
+    @registering_str_unicode(getattr(posix, '_getfullpathname', None),
+                             condition=sys.platform=='win32')
+    def register_posix__getfullpathname(self, traits):
         # this nt function is not exposed via os, but needed
         # to get a correct implementation of os.abspath
-        # XXX why do we ignore WINAPI conventions everywhere?
-        LPWSTRP = rffi.CArrayPtr(rwin32.LPWSTR)
-        GetFullPathName = self.llexternal(
-            'GetFullPathNameW',
-            [rwin32.LPCWSTR,
-             rwin32.DWORD,
-             rwin32.LPWSTR,
-             rffi.CArrayPtr(rwin32.LPWSTR)],
-            rwin32.DWORD)
-
-        def _getfullpathname_llimpl(lpFileName):
-            nBufferLength = rwin32.MAX_PATH + 1
-            lpBuffer = lltype.malloc(rwin32.LPWSTR.TO, nBufferLength, flavor='raw')
-            try:
-                res = GetFullPathName(
-                    lpFileName, rffi.cast(rwin32.DWORD, nBufferLength),
-                    lpBuffer, lltype.nullptr(LPWSTRP.TO))
-                if res == 0:
-                    raise rwin32.lastWindowsError("_getfullpathname failed")
-                result = rffi.wcharp2unicode(lpBuffer)
-                return result
-            finally:
-                lltype.free(lpBuffer, flavor='raw')
+        from pypy.rpython.module.ll_win32file import make_getfullpathname_impl
+        _getfullpathname_llimpl = make_getfullpathname_impl(traits)
 
-        return extdef([unicode],  # a single argument which is a str
-                      unicode,    # returns a string
-                      "ll_os.posix__wgetfullpathname",
+        return extdef([traits.str],  # a single argument which is a str
+                      traits.str,    # returns a string
+                      traits.ll_os_function('_getfullpathname'),
                       llimpl=_getfullpathname_llimpl)
 
     @registering(os.getcwd)
@@ -1233,7 +1179,7 @@
     def register_os_listdir(self, traits):
         # we need a different approach on Windows and on Posix
         if sys.platform.startswith('win'):
-            from pypy.rpython.module.win32file import make_listdir_impl
+            from pypy.rpython.module.ll_win32file import make_listdir_impl
             os_listdir_llimpl = make_listdir_impl(traits)
         else:
             assert traits.str is str

Modified: pypy/branch/unicode_filename-2/pypy/rpython/module/ll_win32file.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rpython/module/ll_win32file.py	(original)
+++ pypy/branch/unicode_filename-2/pypy/rpython/module/ll_win32file.py	Fri Jul 16 14:12:31 2010
@@ -6,6 +6,7 @@
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rpython.tool import rffi_platform as platform
+from pypy.tool.sourcetools import func_renamer
 
 def make_win32_traits(traits):
     from pypy.rlib import rwin32
@@ -68,19 +69,19 @@
                 path += u'/'
             return path + u'*.*'
 
-        def skip_listdir(path):
-            return name == u"." or name == u"..":
+        def skip_listdir(name):
+            return name == u"." or name == u".."
     else:
         def make_listdir_mask(path):
             if path and path[-1] not in ('/', '\\', ':'):
                 path += '/'
             return path + '*.*'
 
-        def skip_listdir(path):
-            return name == "." or name == "..":
+        def skip_listdir(name):
+            return name == "." or name == ".."
 
     @func_renamer('listdir_llimpl_%s' % traits.str.__name__)
-    def os_listdir_llimpl(path):
+    def listdir_llimpl(path):
         mask = make_listdir_mask(path)
         filedata = lltype.malloc(win32traits.WIN32_FIND_DATA, flavor='raw')
         try:
@@ -93,7 +94,7 @@
                 else:
                     raise WindowsError(error,  "FindFirstFile failed")
             while True:
-                name = traits.str2charp(rffi.cast(traits.CCHARP,
+                name = traits.charp2str(rffi.cast(traits.CCHARP,
                                                   filedata.c_cFileName))
                 if not skip_listdir(name):
                     result.append(name)
@@ -111,3 +112,26 @@
             lltype.free(filedata, flavor='raw')
 
     return listdir_llimpl
+
+def make_getfullpathname_impl(traits):
+    win32traits = make_win32_traits(traits)
+
+    LPSTRP = rffi.CArrayPtr(traits.CCHARP)
+
+    @func_renamer('getfullpathname_llimpl_%s' % traits.str.__name__)
+    def getfullpathname_llimpl(path):
+        # XXX why do we ignore WINAPI conventions everywhere?
+        nBufferLength = rwin32.MAX_PATH + 1
+        lpBuffer = lltype.malloc(traits.CCHARP.TO, nBufferLength, flavor='raw')
+        try:
+            res = win32traits.GetFullPathName(
+                lpFileName, rffi.cast(rwin32.DWORD, nBufferLength),
+                lpBuffer, lltype.nullptr(LPSTRP.TO))
+            if res == 0:
+                raise rwin32.lastWindowsError("_getfullpathname failed")
+            result = traits.charp2str(lpBuffer)
+            return result
+        finally:
+            lltype.free(lpBuffer, flavor='raw')
+
+    return getfullpathname_llimpl



More information about the Pypy-commit mailing list