]> granicus.if.org Git - python/commitdiff
Fixes for 64-bit Windows: In ctypes.wintypes, correct the definitions
authorThomas Heller <theller@ctypes.org>
Thu, 11 Jan 2007 21:18:56 +0000 (21:18 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 11 Jan 2007 21:18:56 +0000 (21:18 +0000)
of HANDLE, WPARAM, LPARAM data types.  Make parameterless foreign
function calls work.

Lib/ctypes/test/test_win32.py
Lib/ctypes/wintypes.py
Misc/NEWS
Modules/_ctypes/libffi_msvc/ffi.c

index 10deacad530331cb88bda3f92985356e99949d2b..d6f018bd68af48b2f609e9146d52a1eeea04a76b 100644 (file)
@@ -3,6 +3,7 @@
 from ctypes import *
 from ctypes.test import is_resource_enabled
 import unittest, sys
+from ctypes import wintypes
 
 import _ctypes_test
 
@@ -32,12 +33,30 @@ if sys.platform == "win32" and sizeof(c_void_p) == sizeof(c_int):
             # or wrong calling convention
             self.assertRaises(ValueError, IsWindow, None)
 
+if sys.platform == "win32":
+    class FunctionCallTestCase(unittest.TestCase):
+
         if is_resource_enabled("SEH"):
             def test_SEH(self):
-                # Call functions with invalid arguments, and make sure that access violations
-                # are trapped and raise an exception.
+                # Call functions with invalid arguments, and make sure
+                # that access violations are trapped and raise an
+                # exception.
                 self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32)
 
+        def test_noargs(self):
+            # This is a special case on win32 x64
+            windll.user32.GetDesktopWindow()
+
+    class TestWintypes(unittest.TestCase):
+        def test_HWND(self):
+            self.failUnlessEqual(sizeof(wintypes.HWND), sizeof(c_void_p))
+
+        def test_PARAM(self):
+            self.failUnlessEqual(sizeof(wintypes.WPARAM),
+                                 sizeof(c_void_p))
+            self.failUnlessEqual(sizeof(wintypes.LPARAM),
+                                 sizeof(c_void_p))
+
 class Structures(unittest.TestCase):
 
     def test_struct_by_value(self):
index 97682331f6cefc832cfa371901058c308bd3227c..d2c1e38cb75f9037044060782e7090512ca41389 100644 (file)
@@ -34,8 +34,14 @@ LPCOLESTR = LPOLESTR = OLESTR = c_wchar_p
 LPCWSTR = LPWSTR = c_wchar_p
 LPCSTR = LPSTR = c_char_p
 
-WPARAM = c_uint
-LPARAM = c_long
+# WPARAM is defined as UINT_PTR (which is signed)
+# LPARAM is defined as LONG_PTR (which is unsigned)
+if sizeof(c_long) == sizeof(c_void_p):
+    WPARAM = c_ulong
+    LPARAM = c_long
+elif sizeof(c_longlong) == sizeof(c_void_p):
+    WPARAM = c_ulonglong
+    LPARAM = c_longlong
 
 ATOM = WORD
 LANGID = WORD
@@ -48,7 +54,7 @@ LCID = DWORD
 
 ################################################################
 # HANDLE types
-HANDLE = c_ulong # in the header files: void *
+HANDLE = c_void_p # in the header files: void *
 
 HACCEL = HANDLE
 HBITMAP = HANDLE
index e671c72ef61d245fc821ccf91b757926f548be25..9540f4bf545268e9fb06bbb312354b68828f5d3e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -109,6 +109,10 @@ Core and builtins
 Library
 -------
 
+- Fixes for 64-bit Windows: In ctypes.wintypes, correct the
+  definitions of HANDLE, WPARAM, LPARAM data types.  Make
+  parameterless foreign function calls work.
+
 - The version number of the ctypes package changed to "1.1.0".
 
 - Bug #1627575: logging: Added _open() method to FileHandler which can
index 3f23a052eddce94b72eec4803e11a27b7daf1a9a..e3e2344aa6e1dd103121531bbe903e39b06257cf 100644 (file)
@@ -224,7 +224,8 @@ ffi_call(/*@dependent@*/ ffi_cif *cif,
 #else
     case FFI_SYSV:
       /*@-usedef@*/
-      return ffi_call_AMD64(ffi_prep_args, &ecif, cif->bytes, 
+      /* Function call needs at least 40 bytes stack size, on win64 AMD64 */
+      return ffi_call_AMD64(ffi_prep_args, &ecif, cif->bytes ? cif->bytes : 40,
                           cif->flags, ecif.rvalue, fn);
       /*@=usedef@*/
       break;