]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 88284 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 31 Jan 2011 21:36:33 +0000 (21:36 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 31 Jan 2011 21:36:33 +0000 (21:36 +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 0fa2d9dba729b63f85a944f08213b2febb1ce23e..dabcde65c8d74a568c45d5ec1fe53d25952a5032 100644 (file)
@@ -166,6 +166,42 @@ class SampleCallbacksTestCase(unittest.TestCase):
 
         self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)
 
+    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 c38550d8a70da2ab073005de8774cd5e5a8e0910..2ef672e34431589505e662210464f543e98587c3 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -536,6 +536,7 @@ Luke Mewburn
 Mike Meyer
 Steven Miale
 Trent Mick
+Stan Mihai
 Aristotelis Mikropoulos
 Damien Miller
 Chad Miller
index 445536df66b61c4707098b5c6529ccba883866c1..362e52ce22313bdf167b6a3b3fe5ae1e1cecaf18 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 #11053: Fix IDLE "Syntax Error" windows to behave as in 2.x,
   preventing a confusing hung appearance on OS X with the windows
   obscured.
index 36bd0a1465be1fcddffe14a9fe2bc504024ae0d2..3a6845f39bb68c5f4445ec0ef5d13a67602be293 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 763d179c8b935f9342273161c63b3fac78f0959b..7a7348b3c47670d514651983344860a0446f41b9 100644 (file)
@@ -379,7 +379,7 @@ ffi_prep_closure (ffi_closure* closure,
   short bytes;
   char *tramp;
 #ifdef _WIN64
-  int mask;
+  int mask = 0;
 #endif
   FFI_ASSERT (cif->abi == FFI_SYSV);