Commits

Amaury Forgeot d'Arc committed 7b763e6

Fix translation, and use the new "registering" decorator

Comments (0)

Files changed (2)

pypy/rpython/module/ll_os.py

     str = str
     CHAR = rffi.CHAR
     CCHARP = rffi.CCHARP
+    str2charp = rffi.str2charp
 
     @staticmethod
     def posix_function_name(name):
     str = unicode
     CHAR = rffi.WCHAR_T
     CCHARP = rffi.CWCHARP
+    str2charp = rffi.wcharp2unicode
 
     @staticmethod
     def posix_function_name(name):
         return extdef([], unicode,
                       "ll_os.ll_os_wgetcwd", llimpl=os_getcwd_llimpl)
 
-    @registering(os.listdir)
-    def register_os_listdir(self):
+    @registering_str_unicode(os.listdir)
+    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
-            os_listdir_llimpl = make_listdir_impl(StringTraits())
+            os_listdir_llimpl = make_listdir_impl(traits)
         else:
+            assert traits.str is str
             compilation_info = ExternalCompilationInfo(
                 includes = ['sys/types.h', 'dirent.h']
             )
                     raise OSError(error, "os_readdir failed")
                 return result
 
-        return extdef([str],  # a single argument which is a str
-                      [str],  # returns a list of strings
-                      "ll_os.ll_os_listdir",
+        return extdef([traits.str],  # a single argument which is a str
+                      [traits.str],  # returns a list of strings
+                      traits.ll_os_name('listdir'),
                       llimpl=os_listdir_llimpl)
 
-    @registering_unicode_version(os.listdir, [unicode], sys.platform=='win32')
-    def register_os_listdir_unicode(self):
-        from pypy.rpython.module.win32file import make_listdir_impl
-
-        return extdef([unicode],  # a single argument which is a unicode
-                      [unicode],  # returns a list of unicodes
-                      "ll_os.ll_os_wlistdir",
-                      llimpl=make_listdir_impl(UnicodeTraits()))
-
     @registering(os.pipe)
     def register_os_pipe(self):
         # we need a different approach on Windows and on Posix

pypy/rpython/module/ll_win32file.py

         def skip_listdir(path):
             return name == "." or name == "..":
 
-    def listdir_llimpl(path):
+    @func_renamer('listdir_llimpl_%s' % traits.str.__name__)
+    def os_listdir_llimpl(path):
         mask = make_listdir_mask(path)
         filedata = lltype.malloc(win32traits.WIN32_FIND_DATA, flavor='raw')
         try:
                 else:
                     raise WindowsError(error,  "FindFirstFile failed")
             while True:
-                name = rffi.wcharp2unicode(rffi.cast(rffi.CWCHARP,
-                                                     filedata.c_cFileName))
+                name = traits.str2charp(rffi.cast(traits.CCHARP,
+                                                  filedata.c_cFileName))
                 if not skip_listdir(name):
                     result.append(name)
                 if not win32traits.FindNextFile(hFindFile, filedata):