summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-01-31 21:08:57 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-01-31 21:08:57 (GMT)
commit0ea622a5c88b75db15d818e91ec2f57651473a66 (patch)
tree34de987a85aa4329509b04109d9c0c4cfa6d6871
parentbd0c897332faddce4ebdd4698f976c99a70ec346 (diff)
downloadcpython-0ea622a5c88b75db15d818e91ec2f57651473a66.zip
cpython-0ea622a5c88b75db15d818e91ec2f57651473a66.tar.gz
cpython-0ea622a5c88b75db15d818e91ec2f57651473a66.tar.bz2
Issue #8275: Fix passing of callback arguments with ctypes under Win64.
Patch by Stan Mihai. Ok'ed by Georg.
-rw-r--r--Lib/ctypes/test/test_callbacks.py36
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_ctypes/_ctypes_test.c14
-rw-r--r--Modules/_ctypes/libffi_msvc/ffi.c2
5 files changed, 55 insertions, 1 deletions
diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py
index 4b468b9..8801ccd 100644
--- a/Lib/ctypes/test/test_callbacks.py
+++ b/Lib/ctypes/test/test_callbacks.py
@@ -200,6 +200,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__':
diff --git a/Misc/ACKS b/Misc/ACKS
index 02e5d91..8e12007 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -574,6 +574,7 @@ Luke Mewburn
Mike Meyer
Steven Miale
Trent Mick
+Stan Mihai
Aristotelis Mikropoulos
Damien Miller
Chad Miller
diff --git a/Misc/NEWS b/Misc/NEWS
index 6b6fae9..44a71d8 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
+- Issue #8275: Fix passing of callback arguments with ctypes under Win64.
+ Patch by Stan Mihai.
+
What's New in Python 3.2 Release Candidate 2?
=============================================
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
index 36bd0a1..3a6845f 100644
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -12,6 +12,20 @@
/* 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",
diff --git a/Modules/_ctypes/libffi_msvc/ffi.c b/Modules/_ctypes/libffi_msvc/ffi.c
index 5df4ba4..6e595e9 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.c
+++ b/Modules/_ctypes/libffi_msvc/ffi.c
@@ -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);