[pypy-svn] r76974 - in pypy/trunk/pypy: module/_winreg rlib rpython/lltypesystem rpython/module translator/c

afa at codespeak.net afa at codespeak.net
Thu Sep 9 16:52:19 CEST 2010


Author: afa
Date: Thu Sep  9 16:52:18 2010
New Revision: 76974

Modified:
   pypy/trunk/pypy/module/_winreg/interp_winreg.py
   pypy/trunk/pypy/rlib/rmmap.py
   pypy/trunk/pypy/rlib/rwin32.py
   pypy/trunk/pypy/rpython/lltypesystem/rffi.py
   pypy/trunk/pypy/rpython/module/ll_os.py
   pypy/trunk/pypy/rpython/module/ll_win32file.py
   pypy/trunk/pypy/translator/c/database.py
Log:
Turn rwin32.HANDLE into an Opaque type that emits "HANDLE" in C.
this removes a lot of compilation warnings on Windows.


Modified: pypy/trunk/pypy/module/_winreg/interp_winreg.py
==============================================================================
--- pypy/trunk/pypy/module/_winreg/interp_winreg.py	(original)
+++ pypy/trunk/pypy/module/_winreg/interp_winreg.py	Thu Sep  9 16:52:18 2010
@@ -20,16 +20,19 @@
         self.Close(space)
     descr_del.unwrap_spec = ['self', ObjSpace]
 
+    def as_int(self):
+        return rffi.cast(rffi.SIZE_T, self.hkey)
+
     def descr_nonzero(self, space):
-        return space.wrap(self.hkey != 0)
+        return space.wrap(self.as_int() != 0)
     descr_nonzero.unwrap_spec = ['self', ObjSpace]
 
     def descr_repr(self, space):
-        return space.wrap("<PyHKEY:0x%x>" % (self.hkey,))
+        return space.wrap("<PyHKEY:0x%x>" % (self.as_int(),))
     descr_repr.unwrap_spec = ['self', ObjSpace]
 
     def descr_int(self, space):
-        return space.wrap(self.hkey)
+        return space.wrap(self.as_int())
     descr_int.unwrap_spec = ['self', ObjSpace]
 
     def Close(self, space):
@@ -49,12 +52,13 @@
 need the underlying win32 handle to exist beyond the lifetime of the
 handle object.
 On 64 bit windows, the result of this function is a long integer"""
-        hkey = self.hkey
-        self.hkey = 0
-        return space.wrap(hkey)
+        key = self.as_int()
+        self.hkey = rwin32.NULL_HANDLE
+        return space.wrap(key)
     Detach.unwrap_spec = ['self', ObjSpace]
 
-def new_HKEY(space, w_subtype, hkey):
+def new_HKEY(space, w_subtype, key):
+    hkey = rffi.cast(rwinreg.HKEY, key)
     return space.wrap(W_HKEY(hkey))
 descr_HKEY_new = interp2app(new_HKEY,
                             unwrap_spec=[ObjSpace, W_Root, int])
@@ -98,9 +102,9 @@
     elif isinstance(w_hkey, W_HKEY):
         return w_hkey.hkey
     elif space.is_true(space.isinstance(w_hkey, space.w_int)):
-        return space.int_w(w_hkey)
+        return rffi.cast(rwinreg.HKEY, space.int_w(w_hkey))
     elif space.is_true(space.isinstance(w_hkey, space.w_long)):
-        return space.uint_w(w_hkey)
+        return rffi.cast(rwinreg.HKEY, space.uint_w(w_hkey))
     else:
         errstring = space.wrap("The object is not a PyHKEY object")
         raise OperationError(space.w_TypeError, errstring)
@@ -631,8 +635,8 @@
                     null_dword, ft)
                 if ret != 0:
                     raiseWindowsError(space, ret, 'RegQueryInfoKey')
-                l = (ft[0].c_dwLowDateTime +
-                     (ft[0].c_dwHighDateTime << 32))
+                l = ((lltype.r_longlong(ft[0].c_dwHighDateTime) << 32) +
+                     lltype.r_longlong(ft[0].c_dwLowDateTime))
                 return space.newtuple([space.wrap(nSubKeys[0]),
                                        space.wrap(nValues[0]),
                                        space.wrap(l)])

Modified: pypy/trunk/pypy/rlib/rmmap.py
==============================================================================
--- pypy/trunk/pypy/rlib/rmmap.py	(original)
+++ pypy/trunk/pypy/rlib/rmmap.py	Thu Sep  9 16:52:18 2010
@@ -72,6 +72,7 @@
         setattr(CConfig, name, rffi_platform.ConstantInteger(name))
 
     from pypy.rlib.rwin32 import HANDLE, LPHANDLE
+    from pypy.rlib.rwin32 import NULL_HANDLE, INVALID_HANDLE_VALUE
     from pypy.rlib.rwin32 import DWORD, WORD, DWORD_PTR, LPDWORD
     from pypy.rlib.rwin32 import BOOL, LPVOID, LPCVOID, LPCSTR, SIZE_T
     from pypy.rlib.rwin32 import INT, LONG, PLONG
@@ -183,7 +184,7 @@
     ##_get_osfhandle = winexternal('_get_osfhandle', [INT], LONG)
     # casting from int to handle did not work, so I changed this
     # but it should not be so!
-    _get_osfhandle = winexternal('_get_osfhandle', [INT], HANDLE)
+    _get_osfhandle = winexternal('_get_osfhandle', [INT], rffi.INTPTR_T)
     GetLastError = winexternal('GetLastError', [], DWORD)
     VirtualAlloc = winexternal('VirtualAlloc',
                                [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD],
@@ -228,8 +229,7 @@
     def _get_error_no():
         return rffi.cast(lltype.Signed, GetLastError())
 
-    NULL_HANDLE = rffi.cast(HANDLE, 0)
-    INVALID_HANDLE = rffi.cast(HANDLE, -1)
+    INVALID_HANDLE = INVALID_HANDLE_VALUE
 
 PAGESIZE = _get_page_size()
 NULL = lltype.nullptr(PTR.TO)
@@ -684,12 +684,11 @@
         # assume -1 and 0 both mean invalid file descriptor
         # to 'anonymously' map memory.
         if fileno != -1 and fileno != 0:
-            fh = _get_osfhandle(fileno)
-            # parts of the C library use HANDLE, others just ints
-            # XXX hack - made _get_osfhandle compatible
-            if fh == INVALID_HANDLE:
+            res = _get_osfhandle(fileno)
+            if res == rffi.cast(rffi.SSIZE_T, INVALID_HANDLE):
                 errno = _get_error_no()
                 raise OSError(errno, os.strerror(errno))
+            fh = rffi.cast(HANDLE, res)
             # Win9x appears to need us seeked to zero
             # SEEK_SET = 0
             # libc._lseek(fileno, 0, SEEK_SET)

Modified: pypy/trunk/pypy/rlib/rwin32.py
==============================================================================
--- pypy/trunk/pypy/rlib/rwin32.py	(original)
+++ pypy/trunk/pypy/rlib/rwin32.py	Thu Sep  9 16:52:18 2010
@@ -81,9 +81,10 @@
     return rffi.llexternal(name, args, result, compilation_info=eci, calling_conv='win')
 
 if WIN32:
-    HANDLE = rffi.ULONG
+    HANDLE = rffi.COpaquePtr(typedef='HANDLE')
     LPHANDLE = rffi.CArrayPtr(HANDLE)
     HMODULE = HANDLE
+    NULL_HANDLE = rffi.cast(HANDLE, 0)
     INVALID_HANDLE_VALUE = rffi.cast(HANDLE, -1)
     PFILETIME = rffi.CArrayPtr(FILETIME)
 

Modified: pypy/trunk/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rffi.py	Thu Sep  9 16:52:18 2010
@@ -358,9 +358,11 @@
 if os.name != 'nt':
     TYPES.append('mode_t')
     TYPES.append('pid_t')
+    TYPES.append('ssize_t')
 else:
     MODE_T = lltype.Signed
     PID_T = lltype.Signed
+    SSIZE_T = lltype.Signed
 
 def populate_inttypes():
     names = []
@@ -415,6 +417,7 @@
 #        ULONGLONG      r_ulonglong
 #        WCHAR_T        r_wchar_t
 #        SIZE_T         r_size_t
+#        SSIZE_T        r_ssize_t
 #        TIME_T         r_time_t
 # --------------------------------------------------------------------
 # Note that rffi.r_int is not necessarily the same as
@@ -535,6 +538,8 @@
 # (use SIGNEDCHAR or UCHAR for the small integer types)
 CHAR = lltype.Char
 
+INTPTR_T = SSIZE_T
+
 # double
 DOUBLE = lltype.Float
 

Modified: pypy/trunk/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/trunk/pypy/rpython/module/ll_os.py	(original)
+++ pypy/trunk/pypy/rpython/module/ll_os.py	Thu Sep  9 16:52:18 2010
@@ -1046,7 +1046,7 @@
                                                         rffi.VOIDP,
                                                         rwin32.DWORD],
                                          rwin32.BOOL)
-            _open_osfhandle = self.llexternal('_open_osfhandle', [rffi.ULONG,
+            _open_osfhandle = self.llexternal('_open_osfhandle', [rffi.INTPTR_T,
                                                                   rffi.INT],
                                               rffi.INT)
             null = lltype.nullptr(rffi.VOIDP.TO)
@@ -1059,8 +1059,8 @@
                     error = 0
                 else:
                     error = rwin32.GetLastError()
-                hread = pread[0]
-                hwrite = pwrite[0]
+                hread = rffi.cast(rffi.INTPTR_T, pread[0])
+                hwrite = rffi.cast(rffi.INTPTR_T, pwrite[0])
                 lltype.free(pwrite, flavor='raw')
                 lltype.free(pread, flavor='raw')
                 if error:

Modified: pypy/trunk/pypy/rpython/module/ll_win32file.py
==============================================================================
--- pypy/trunk/pypy/rpython/module/ll_win32file.py	(original)
+++ pypy/trunk/pypy/rpython/module/ll_win32file.py	Thu Sep  9 16:52:18 2010
@@ -265,7 +265,8 @@
         hFile = CreateFile(path,
                            FILE_WRITE_ATTRIBUTES, 0,
                            None, OPEN_EXISTING,
-                           FILE_FLAG_BACKUP_SEMANTICS, 0)
+                           FILE_FLAG_BACKUP_SEMANTICS,
+                           rwin32.NULL_HANDLE)
         if hFile == rwin32.INVALID_HANDLE_VALUE:
             raise rwin32.lastWindowsError()
         ctime = lltype.nullptr(rwin32.FILETIME)

Modified: pypy/trunk/pypy/translator/c/database.py
==============================================================================
--- pypy/trunk/pypy/translator/c/database.py	(original)
+++ pypy/trunk/pypy/translator/c/database.py	Thu Sep  9 16:52:18 2010
@@ -2,7 +2,7 @@
      Primitive, Ptr, typeOf, RuntimeTypeInfo, \
      Struct, Array, FuncType, PyObject, Void, \
      ContainerType, OpaqueType, FixedSizeArray, _uninitialized
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rpython.lltypesystem.llmemory import WeakRef, _WeakRefType, GCREF
 from pypy.rpython.lltypesystem.rffi import CConstant
 from pypy.rpython.lltypesystem import llgroup
@@ -183,6 +183,12 @@
         if isinstance(T, Primitive) or T == GCREF:
             return PrimitiveName[T](obj, self)
         elif isinstance(T, Ptr):
+            if (isinstance(T.TO, OpaqueType) and
+                T.TO.hints.get('c_pointer_typedef') is not None):
+                if obj._obj is not None:
+                    value = rffi.cast(rffi.SSIZE_T, obj)
+                    return '((%s) %s)' % (cdecl(self.gettype(T), ''),
+                                          self.get(value))
             if obj:   # test if the ptr is non-NULL
                 try:
                     container = obj._obj



More information about the Pypy-commit mailing list