diff --git a/Lib/ctypes/test/test_functions.py b/Lib/ctypes/test/test_functions.py index 7562892420..e3c042eb7e 100644 --- a/Lib/ctypes/test/test_functions.py +++ b/Lib/ctypes/test/test_functions.py @@ -138,6 +138,18 @@ class FunctionTestCase(unittest.TestCase): self.assertEqual(result, -21) self.assertEqual(type(result), float) + def test_doubleresult_var(self): + f = dll._testfunc_d_bhilfd_var + f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] + f.restype = c_double + result = f(1, 2, 3, 4, 5.0, 6.0) + self.assertEqual(result, 21) + self.assertEqual(type(result), float) + + result = f(-1, -2, -3, -4, -5.0, -6.0) + self.assertEqual(result, -21) + self.assertEqual(type(result), float) + def test_longdoubleresult(self): f = dll._testfunc_D_bhilfD f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble] diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index 8fbc22ff29..18f499159c 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -341,6 +341,28 @@ EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f return (double)(b + h + i + l + f + d); } +EXPORT(double) _testfunc_d_bhilfd_var(int dummy, ...) +{ + signed char b; + short h; + int i; + long l; + float f; + double d; + va_list argptr; + va_start(argptr, dummy); + b = (signed char)va_arg(argptr, int); + h = (short)va_arg(argptr, int); + i = va_arg(argptr, int); + l = va_arg(argptr, long); + f = (float)va_arg(argptr, double); + d = va_arg(argptr, double); + va_end(argptr); + printf("_testfunc_d_bhilfd_var got %d %d %d %ld %f %f\n", + b, h, i, l, f, d); + return (double)(b + h + i + l + f + d); +} + EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d) { /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",