Commits

Brian Kearns committed 55ade75

cleanup rmmap.py

Comments (0)

Files changed (1)

rpython/rlib/rmmap.py

-
 from rpython.rtyper.tool import rffi_platform
-from rpython.rtyper.lltypesystem import rffi, lltype, llmemory
+from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import rposix
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rlib.nonconst import NonConstant
 
 _POSIX = os.name == "posix"
 _MS_WINDOWS = os.name == "nt"
-_LINUX = "linux" in sys.platform
 _64BIT = "64bit" in platform.architecture()[0]
-_ARM = platform.machine().startswith('arm')
-_PPC = platform.machine().startswith('ppc')
 _CYGWIN = "cygwin" == sys.platform
 
 class RValueError(Exception):
 if _POSIX:
     includes += ['unistd.h', 'sys/mman.h']
 elif _MS_WINDOWS:
-    includes += ['winsock2.h','windows.h']
+    includes += ['winsock2.h', 'windows.h']
 
 class CConfig:
     _compilation_info_ = ExternalCompilationInfo(
     from rpython.rlib.rwin32 import NULL_HANDLE, INVALID_HANDLE_VALUE
     from rpython.rlib.rwin32 import DWORD, WORD, DWORD_PTR, LPDWORD
     from rpython.rlib.rwin32 import BOOL, LPVOID, LPCSTR, SIZE_T
-    from rpython.rlib.rwin32 import INT, LONG, PLONG
+    from rpython.rlib.rwin32 import LONG, PLONG
 
 # export the constants inside and outside. see __init__.py
 cConfig = rffi_platform.configure(CConfig)
 if _POSIX:
     has_mremap = cConfig['has_mremap']
     c_mmap, c_mmap_safe = external('mmap', [PTR, size_t, rffi.INT, rffi.INT,
-                               rffi.INT, off_t], PTR, macro=True)
+                                   rffi.INT, off_t], PTR, macro=True)
     # 'mmap' on linux32 is a macro that calls 'mmap64'
     _, c_munmap_safe = external('munmap', [PTR, size_t], rffi.INT)
     c_msync, _ = external('msync', [PTR, size_t, rffi.INT], rffi.INT)
 
     # this one is always safe
     _pagesize = rffi_platform.getintegerfunctionresult('getpagesize',
-                                                includes=includes)
+                                                       includes=includes)
     _get_allocation_granularity = _get_page_size = lambda: _pagesize
 
 elif _MS_WINDOWS:
             'SYSINFO_STRUCT',
                 ("wProcessorArchitecture", WORD),
                 ("wReserved", WORD),
-            )
+        )
 
         SYSINFO_UNION = rffi.CStruct(
             'union SYSINFO_UNION',
                 ("dwOemId", DWORD),
                 ("_struct_", SYSINFO_STRUCT),
-            )
+        )
         # sorry, I can't find a way to insert the above
         # because the union field has no name
         SYSTEM_INFO = rffi_platform.Struct(
     VirtualFree = winexternal('VirtualFree',
                               [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL)
 
-
     def _get_page_size():
         try:
             si = rffi.make(SYSTEM_INFO)
                 # this is not checked
                 return res
             elif _POSIX:
-##                XXX why is this code here?  There is no equivalent in CPython
-##                if _LINUX:
-##                    # alignment of the address
-##                    value = cast(self.data, c_void_p).value
-##                    aligned_value = value & ~(PAGESIZE - 1)
-##                    # the size should be increased too. otherwise the final
-##                    # part is not "msynced"
-##                    new_size = size + value & (PAGESIZE - 1)
                 res = c_msync(start, size, MS_SYNC)
                 if res == -1:
                     errno = rposix.get_errno()
 
         # check boundings
         if (src < 0 or dest < 0 or count < 0 or
-            src + count > self.size or dest + count > self.size):
+                src + count > self.size or dest + count > self.size):
             raise RValueError("source or destination out of range")
 
         datasrc = self.getptr(src)
             SetEndOfFile(self.file_handle)
             # create another mapping object and remap the file view
             res = CreateFileMapping(self.file_handle, NULL, PAGE_READWRITE,
-                                 newsize_high, newsize_low, self.tagname)
+                                    newsize_high, newsize_low, self.tagname)
             self.map_handle = res
 
-            dwErrCode = 0
             if self.map_handle:
                 data = MapViewOfFile(self.map_handle, FILE_MAP_WRITE,
                                      offset_high, offset_low, newsize)
 
         if len(value) != 1:
             raise RValueError("mmap assignment must be "
-                             "single-character string")
+                              "single-character string")
         if index < 0:
             index += self.size
         self.data[index] = value[0]
 
 if _POSIX:
     def mmap(fileno, length, flags=MAP_SHARED,
-        prot=PROT_WRITE | PROT_READ, access=_ACCESS_DEFAULT, offset=0):
+             prot=PROT_WRITE | PROT_READ, access=_ACCESS_DEFAULT, offset=0):
 
         fd = fileno
 
         # check access is not there when flags and prot are there
-        if access != _ACCESS_DEFAULT and ((flags != MAP_SHARED) or\
+        if access != _ACCESS_DEFAULT and ((flags != MAP_SHARED) or
                                           (prot != (PROT_WRITE | PROT_READ))):
             raise RValueError("mmap can't specify both access and flags, prot.")
 
                 pass     # ignore non-seeking files and errors and trust map_size
             else:
                 if not high and low <= sys.maxint:
-                   size = low
-                else:   
+                    size = low
+                else:
                     # not so sure if the signed/unsigned strictness is a good idea:
                     high = rffi.cast(lltype.Unsigned, high)
                     low = rffi.cast(lltype.Unsigned, low)
         case of a sandboxed process
         """
         null = lltype.nullptr(rffi.VOIDP.TO)
-        res = VirtualAlloc(null, map_size, MEM_COMMIT|MEM_RESERVE,
+        res = VirtualAlloc(null, map_size, MEM_COMMIT | MEM_RESERVE,
                            PAGE_EXECUTE_READWRITE)
         if not res:
             raise MemoryError