mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #8275: Fix passing of callback arguments with ctypes under Win64.
Patch by Stan Mihai. Ok'ed by Georg.
This commit is contained in:
parent
bd0c897332
commit
0ea622a5c8
5 changed files with 55 additions and 1 deletions
|
@ -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__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue