[pypy-commit] pypy more-rposix: Some fixes for windows

amauryfa noreply at buildbot.pypy.org
Mon Apr 6 21:05:08 CEST 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: more-rposix
Changeset: r76729:ae2d76775668
Date: 2015-04-06 21:02 +0200
http://bitbucket.org/pypy/pypy/changeset/ae2d76775668/

Log:	Some fixes for windows

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -18,6 +18,11 @@
 _WIN32 = sys.platform.startswith('win')
 _CYGWIN = sys.platform == 'cygwin'
 UNDERSCORE_ON_WIN32 = '_' if _WIN32 else ''
+_MACRO_ON_POSIX = True if not _WIN32 else None
+
+if _WIN32:
+    from rpython.rlib import rwin32 
+    from rpython.rlib.rwin32file import make_win32_traits
 
 class CConstantErrno(CConstant):
     # these accessors are used when calling get_errno() or set_errno()
@@ -268,7 +273,8 @@
 # For now we require off_t to be the same size as LONGLONG, which is the
 # interface required by callers of functions that thake an argument of type
 # off_t.
-assert OFF_T_SIZE == rffi.sizeof(rffi.LONGLONG)
+if not _WIN32:
+    assert OFF_T_SIZE == rffi.sizeof(rffi.LONGLONG)
 
 c_dup = external(UNDERSCORE_ON_WIN32 + 'dup', [rffi.INT], rffi.INT,
                  save_err=rffi.RFFI_SAVE_ERRNO)
@@ -369,8 +375,11 @@
 # with errno.
 
 def replace_os_function(name):
+    func = getattr(os, name, None)
+    if func is None:
+        return lambda f: f
     return register_replacement_for(
-        getattr(os, name, None),
+        func,
         sandboxed_name='ll_os.ll_os_%s' % name)
 
 @specialize.arg(0)
@@ -436,7 +445,7 @@
 
 c_lseek = external('_lseeki64' if _WIN32 else 'lseek',
                    [rffi.INT, rffi.LONGLONG, rffi.INT], rffi.LONGLONG,
-                   macro=True, save_err=rffi.RFFI_SAVE_ERRNO)
+                   macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
 
 @replace_os_function('lseek')
 def lseek(fd, pos, how):
@@ -451,7 +460,7 @@
     return handle_posix_error('lseek', c_lseek(fd, pos, how))
 
 c_ftruncate = external('ftruncate', [rffi.INT, rffi.LONGLONG], rffi.INT,
-                       macro=True, save_err=rffi.RFFI_SAVE_ERRNO)
+                       macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
 c_fsync = external('fsync' if not _WIN32 else '_commit', [rffi.INT], rffi.INT,
                    save_err=rffi.RFFI_SAVE_ERRNO)
 c_fdatasync = external('fdatasync', [rffi.INT], rffi.INT,
@@ -490,9 +499,8 @@
         handle_posix_error('chdir', c_chdir(_as_bytes0(path)))
     else:
         traits = _preferred_traits(path)
-        from rpython.rlib.rwin32file import make_win32_traits
         win32traits = make_win32_traits(traits)
-        path = traits._as_str0(path)
+        path = traits.as_str0(path)
 
         # This is a reimplementation of the C library's chdir
         # function, but one that produces Win32 errors instead of DOS
@@ -556,7 +564,6 @@
 def getfullpathname(path):
     length = rwin32.MAX_PATH + 1
     traits = _preferred_traits(path)
-    from rpython.rlib.rwin32file import make_win32_traits
     win32traits = make_win32_traits(traits)
     with traits.scoped_alloc_buffer(length) as buf:
         res = win32traits.GetFullPathName(
@@ -654,7 +661,6 @@
             raise OSError(error, "readdir failed")
         return result
     else:  # _WIN32 case
-        from rpython.rlib.rwin32file import make_win32_traits
         traits = _preferred_traits(path)
         win32traits = make_win32_traits(traits)
         path = traits.as_str0(path)
@@ -846,7 +852,7 @@
 
 def _make_waitmacro(name):
     c_func = external(name, [lltype.Signed], lltype.Signed,
-                      macro=True)
+                      macro=_MACRO_ON_POSIX)
     returning_int = name in ('WEXITSTATUS', 'WSTOPSIG', 'WTERMSIG')
 
     @replace_os_function(name)
@@ -1040,7 +1046,7 @@
                     save_err=rffi.RFFI_SAVE_ERRNO)
 c_mknod = external('mknod', [rffi.CCHARP, rffi.MODE_T, rffi.INT], rffi.INT,
 #                                           # xxx: actually ^^^ dev_t
-                   macro=True, save_err=rffi.RFFI_SAVE_ERRNO)
+                   macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO)
 
 @replace_os_function('mkfifo')
 @specialize.argtype(0)
@@ -1212,7 +1218,7 @@
                 lltype.free(l_utimbuf, flavor='raw')
         handle_posix_error('utime', error)
     else:  # _WIN32 case
-        from rpython.rlib.rwin32file import make_win32_traits, time_t_to_FILE_TIME
+        from rpython.rlib.rwin32file import time_t_to_FILE_TIME
         traits = _preferred_traits(path)
         win32traits = make_win32_traits(traits)
         path = traits.as_str0(path)
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
@@ -11,8 +11,7 @@
 from rpython.rtyper.tool import rffi_platform as platform
 from rpython.rtyper.llannotation import lltype_to_annotation
 
-from rpython.rlib.objectmodel import (
-    specialize)
+from rpython.rlib.objectmodel import specialize
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rlib.rposix import (
@@ -427,6 +426,7 @@
 #__________________________________________________
 # Helper functions for win32
 if _WIN32:
+    from rpython.rlib.rwin32file import FILE_TIME_to_time_t_float
 
     def make_longlong(high, low):
         return (rffi.r_longlong(high) << 32) + rffi.r_longlong(low)
@@ -434,16 +434,6 @@
     # Seconds between 1.1.1601 and 1.1.1970
     secs_between_epochs = rffi.r_longlong(11644473600)
 
-    def FILE_TIME_to_time_t_float(filetime):
-        ft = make_longlong(filetime.c_dwHighDateTime, filetime.c_dwLowDateTime)
-        # FILETIME is in units of 100 nsec
-        return float(ft) * (1.0 / 10000000.0) - secs_between_epochs
-
-    def time_t_to_FILE_TIME(time, filetime):
-        ft = rffi.r_longlong((time + secs_between_epochs) * 10000000)
-        filetime.c_dwHighDateTime = rffi.r_uint(ft >> 32)
-        filetime.c_dwLowDateTime = rffi.r_uint(ft)    # masking off high bits
-
     def win32_xstat(traits, path, traverse=False):
         win32traits = make_win32_traits(traits)
         with lltype.scoped_alloc(


More information about the pypy-commit mailing list