]> granicus.if.org Git - python/commitdiff
Merged revisions 88284 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 31 Jan 2011 21:47:45 +0000 (21:47 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 31 Jan 2011 21:47:45 +0000 (21:47 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88284 | antoine.pitrou | 2011-01-31 22:08:57 +0100 (lun., 31 janv. 2011) | 4 lines

  Issue #8275: Fix passing of callback arguments with ctypes under Win64.
  Patch by Stan Mihai. Ok'ed by Georg.
........

Lib/ctypes/test/test_callbacks.py
Misc/ACKS
Misc/NEWS
Modules/_ctypes/_ctypes_test.c
Modules/_ctypes/libffi_msvc/ffi.c

index f97297bd1ea597559842e114179d8483c6a55409..621a0192b3156fed1a6995f546b95fc3a932f1e0 100644 (file)
@@ -206,6 +206,42 @@ class SampleCallbacksTestCase(unittest.TestCase):
 
             windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
 
+    def test_callback_register_int(self):
+        # Issue #8275: buggy handling of callback args under Win64
+        # NOTE: should be run on release builds as well
+        dll = CDLL(_ctypes_test.__file__)
+        CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int)
+        # All this function does is call the callback with its args squared
+        func = dll._testfunc_cbk_reg_int
+        func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK)
+        func.restype = c_int
+
+        def callback(a, b, c, d, e):
+            return a + b + c + d + e
+
+        result = func(2, 3, 4, 5, 6, CALLBACK(callback))
+        self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6))
+
+    def test_callback_register_double(self):
+        # Issue #8275: buggy handling of callback args under Win64
+        # NOTE: should be run on release builds as well
+        dll = CDLL(_ctypes_test.__file__)
+        CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double,
+                             c_double, c_double)
+        # All this function does is call the callback with its args squared
+        func = dll._testfunc_cbk_reg_double
+        func.argtypes = (c_double, c_double, c_double,
+                         c_double, c_double, CALLBACK)
+        func.restype = c_double
+
+        def callback(a, b, c, d, e):
+            return a + b + c + d + e
+
+        result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback))
+        self.assertEqual(result,
+                         callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5))
+
+
 ################################################################
 
 if __name__ == '__main__':
index 0c7debc3dc0d36adcee1da23fbe7291f30b5fc88..3cb7667a3b7436ed4228fa06b09316f5b82d0888 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -539,6 +539,7 @@ Luke Mewburn
 Mike Meyer
 Steven Miale
 Trent Mick
+Stan Mihai
 Aristotelis Mikropoulos
 Damien Miller
 Chad Miller
index 79c67c7f1d62d3e76a9032a087d6b51cb4da4b41..8c52b0947aaeaeee335e493396dec8c0241e7158 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8275: Fix passing of callback arguments with ctypes under Win64.
+  Patch by Stan Mihai.
+
 - Issue #10940: Workaround an IDLE hang on Mac OS X 10.6 when using the
   menu accelerators for Open Module, Go to Line, and New Indent Width.
   The accelerators still work but no longer appear in the menu items.
index 46406a6509b1263073908473e8b4ded3ce99e273..275618758691006e7ba181eaed4f592a53ca0d6f 100644 (file)
 
 /* some functions handy for testing */
 
+EXPORT(int)
+_testfunc_cbk_reg_int(int a, int b, int c, int d, int e,
+                      int (*func)(int, int, int, int, int))
+{
+    return func(a*a, b*b, c*c, d*d, e*e);
+}
+
+EXPORT(double)
+_testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
+                         double (*func)(double, double, double, double, double))
+{
+    return func(a*a, b*b, c*c, d*d, e*e);
+}
+
 EXPORT(void)testfunc_array(int values[4])
 {
     printf("testfunc_array %d %d %d %d\n",
index 65581a773fa5a466ba81c43b30c2114f7777d692..fb2e45efde12f2830f6385182139d2fe65184f28 100644 (file)
@@ -380,7 +380,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
   short bytes;
   char *tramp;
 #ifdef _WIN64
-  int mask;
+  int mask = 0;
 #endif
   FFI_ASSERT (cif->abi == FFI_SYSV);