diff -r f4adc2926bf5 Lib/ctypes/test/test_as_parameter.py --- a/Lib/ctypes/test/test_as_parameter.py Tue Apr 12 09:06:01 2011 -0700 +++ b/Lib/ctypes/test/test_as_parameter.py Tue Apr 12 11:41:42 2011 -0700 @@ -13,6 +13,11 @@ class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] +class SEVEN(Structure): + _fields_ = [] + for name in ('a', 'b', 'c', 'd', 'e', 'f', 'g'): + _fields_.append((name, c_uint)) + class BasicWrapTestCase(unittest.TestCase): def wrap(self, param): return param @@ -160,6 +165,23 @@ expected = 203, 101, 102 self.assertEqual(got, expected) + def test_byval_vii(self): + # without prototype + s1 = SEVEN(1, 2, 3, 4, 5, 6, 7) + s2 = SEVEN(0, 9, 8, 7, 6, 5, 4) + # EXPORT int _testfunc_byval_vii(seven s1, seven s2, unsigned int x) + result = dll._testfunc_byval_vii(s1, s2, 42) + expected = 42 + for name, typ in SEVEN._fields_: + expected += getattr(s1, name) * getattr(s2, name) + self.assertEqual(result, expected) + + # with prototype + dll._testfunc_byval_vii.argtypes = (SEVEN, SEVEN, c_uint) + dll._testfunc_byval_vii.restype = c_uint + result = dll._testfunc_byval_vii(s1, s2, 42) + self.assertEqual(result, expected) + def test_struct_return_2H(self): class S2H(Structure): _fields_ = [("x", c_short), diff -r f4adc2926bf5 Modules/_ctypes/_ctypes_test.c --- a/Modules/_ctypes/_ctypes_test.c Tue Apr 12 09:06:01 2011 -0700 +++ b/Modules/_ctypes/_ctypes_test.c Tue Apr 12 11:41:42 2011 -0700 @@ -304,6 +304,28 @@ return in.x + in.y; } +typedef struct tagseven { + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; + unsigned int e; + unsigned int f; + unsigned int g; +} seven; + +EXPORT(unsigned int) _testfunc_byval_vii(seven s1, seven s2, unsigned int x) +{ + return (s1.a * s2.a + + s1.b * s2.b + + s1.c * s2.c + + s1.d * s2.d + + s1.e * s2.e + + s1.f * s2.f + + s1.g * s2.g + + x); +} + EXPORT (int) an_integer = 42; EXPORT(int) get_an_integer(void)