Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e811c9

Browse files
committed
Merged revisions 88284 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 070f050 commit 2e811c9

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

Lib/ctypes/test/test_callbacks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,42 @@ def func(x):
166166

167167
self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)
168168

169+
def test_callback_register_int(self):
170+
# Issue #8275: buggy handling of callback args under Win64
171+
# NOTE: should be run on release builds as well
172+
dll = CDLL(_ctypes_test.__file__)
173+
CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int)
174+
# All this function does is call the callback with its args squared
175+
func = dll._testfunc_cbk_reg_int
176+
func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK)
177+
func.restype = c_int
178+
179+
def callback(a, b, c, d, e):
180+
return a + b + c + d + e
181+
182+
result = func(2, 3, 4, 5, 6, CALLBACK(callback))
183+
self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6))
184+
185+
def test_callback_register_double(self):
186+
# Issue #8275: buggy handling of callback args under Win64
187+
# NOTE: should be run on release builds as well
188+
dll = CDLL(_ctypes_test.__file__)
189+
CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double,
190+
c_double, c_double)
191+
# All this function does is call the callback with its args squared
192+
func = dll._testfunc_cbk_reg_double
193+
func.argtypes = (c_double, c_double, c_double,
194+
c_double, c_double, CALLBACK)
195+
func.restype = c_double
196+
197+
def callback(a, b, c, d, e):
198+
return a + b + c + d + e
199+
200+
result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback))
201+
self.assertEqual(result,
202+
callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5))
203+
204+
169205
################################################################
170206

171207
if __name__ == '__main__':

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ Luke Mewburn
536536
Mike Meyer
537537
Steven Miale
538538
Trent Mick
539+
Stan Mihai
539540
Aristotelis Mikropoulos
540541
Damien Miller
541542
Chad Miller

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Core and Builtins
3737
Library
3838
-------
3939

40+
- Issue #8275: Fix passing of callback arguments with ctypes under Win64.
41+
Patch by Stan Mihai.
42+
4043
- Issue #11053: Fix IDLE "Syntax Error" windows to behave as in 2.x,
4144
preventing a confusing hung appearance on OS X with the windows
4245
obscured.

Modules/_ctypes/_ctypes_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@
1212

1313
/* some functions handy for testing */
1414

15+
EXPORT(int)
16+
_testfunc_cbk_reg_int(int a, int b, int c, int d, int e,
17+
int (*func)(int, int, int, int, int))
18+
{
19+
return func(a*a, b*b, c*c, d*d, e*e);
20+
}
21+
22+
EXPORT(double)
23+
_testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
24+
double (*func)(double, double, double, double, double))
25+
{
26+
return func(a*a, b*b, c*c, d*d, e*e);
27+
}
28+
1529
EXPORT(void)testfunc_array(int values[4])
1630
{
1731
printf("testfunc_array %d %d %d %d\n",

Modules/_ctypes/libffi_msvc/ffi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ ffi_prep_closure (ffi_closure* closure,
379379
short bytes;
380380
char *tramp;
381381
#ifdef _WIN64
382-
int mask;
382+
int mask = 0;
383383
#endif
384384
FFI_ASSERT (cif->abi == FFI_SYSV);
385385

0 commit comments

Comments
 (0)