diff --git a/tests/ctypes_test/Makefile b/tests/ctypes_test/Makefile index 5724155c3..fe7bc3871 100644 --- a/tests/ctypes_test/Makefile +++ b/tests/ctypes_test/Makefile @@ -1,3 +1,15 @@ +# By default, `make` produces a PYD for the current OS/processor. +# To build a specific PYD, the full command is: +# * _ctypes_test_darwin_arm64.pyd: make OS=darwin MACHINE=arm64 +# * _ctypes_test_darwin_x86_64.pyd: make OS=darwin MACHINE=x86_64 +# * _ctypes_test_linux_aarch64.pyd: make OS=linux MACHINE=aarch64 +# * _ctypes_test_linux_x86_64.pyd: make OS=linux MACHINE=x86_64 BITS=64 +# * _ctypes_test_linux_i686.pyd: make OS=linux MACHINE=i686 BITS=32 +# Parameter OS=... may be skipped if it is the same as the host OS. +# For Windows builds, use `_ctypes_test.vcxproj` or `_ctypes_test.sln` with MSBuild: +# * _ctypes_test_win64.pyd: msbuild -p:Configuration=Release -p:Platform=x64 +# * _ctypes_test_win32.pyd: msbuild -p:Configuration=Release -p:Platform=x86 + OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') MACHINE ?= $(shell uname -m) BITS ?= 64 diff --git a/tests/ctypes_test/_ctypes_test.c b/tests/ctypes_test/_ctypes_test.c index b68b0d2b9..a09bc4838 100644 --- a/tests/ctypes_test/_ctypes_test.c +++ b/tests/ctypes_test/_ctypes_test.c @@ -6,7 +6,6 @@ #include #include -#define HAVE_LONG_LONG #define PY_LONG_LONG long long #ifdef MS_WIN32 @@ -53,6 +52,37 @@ _testfunc_cbk_large_struct(Test in, void (*func)(Test)) func(in); } +/* + * See issue 29565. Update a structure passed by value; + * the caller should not see any change. + */ + +EXPORT(void) +_testfunc_large_struct_update_value(Test in) +{ + ((volatile Test *)&in)->first = 0x0badf00d; + ((volatile Test *)&in)->second = 0x0badf00d; + ((volatile Test *)&in)->third = 0x0badf00d; +} + +typedef struct { + unsigned int first; + unsigned int second; +} TestReg; + + +EXPORT(TestReg) last_tfrsuv_arg; + + +EXPORT(void) +_testfunc_reg_struct_update_value(TestReg in) +{ + last_tfrsuv_arg = in; + ((volatile TestReg *)&in)->first = 0x0badf00d; + ((volatile TestReg *)&in)->second = 0x0badf00d; +} + + EXPORT(void)testfunc_array(int values[4]) { printf("testfunc_array %d %d %d %d\n", @@ -242,16 +272,15 @@ EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *)) return (*func)(table); } -#ifdef HAVE_LONG_LONG -EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f, - double d, PY_LONG_LONG q) +EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f, + double d, long long q) { - return (PY_LONG_LONG)(b + h + i + l + f + d + q); + return (long long)(b + h + i + l + f + d + q); } -EXPORT(PY_LONG_LONG) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d) +EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d) { - return (PY_LONG_LONG)(b + h + i + l + f + d); + return (long long)(b + h + i + l + f + d); } EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int)) @@ -264,10 +293,10 @@ EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int)) return sum; } -EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value, - PY_LONG_LONG (*func)(PY_LONG_LONG)) +EXPORT(long long) _testfunc_callback_q_qf(long long value, + long long (*func)(long long)) { - PY_LONG_LONG sum = 0; + long long sum = 0; while (value != 0) { sum += func(value); @@ -276,8 +305,6 @@ EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value, return sum; } -#endif - typedef struct { char *name; char *value; @@ -377,8 +404,8 @@ EXPORT(void) _py_func(void) { } -EXPORT(PY_LONG_LONG) last_tf_arg_s; -EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u; +EXPORT(long long) last_tf_arg_s; +EXPORT(unsigned long long) last_tf_arg_u; struct BITS { int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9; @@ -443,8 +470,8 @@ EXPORT(int) tf_i(int c) { S; return c/3; } EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; } EXPORT(long) tf_l(long c) { S; return c/3; } EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; } -EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; } -EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; } +EXPORT(long long) tf_q(long long c) { S; return c/3; } +EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; } EXPORT(float) tf_f(float c) { S; return c/3; } EXPORT(double) tf_d(double c) { S; return c/3; } EXPORT(long double) tf_D(long double c) { S; return c/3; } @@ -458,8 +485,8 @@ EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; } EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; } EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; } EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; } -EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; } -EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; } +EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; } +EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; } EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; } EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; } EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; } @@ -474,8 +501,8 @@ EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; } EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; } EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; } EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; } -EXPORT(PY_LONG_LONG) tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; } -EXPORT(unsigned PY_LONG_LONG) tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; } +EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; } +EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; } EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; } EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; } EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; } @@ -490,8 +517,8 @@ EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; } EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; } EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; } EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; } -EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; } -EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; } +EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; } +EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; } EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; } EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; } EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; } @@ -618,6 +645,200 @@ EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj) *pj += b; } +#ifdef MS_WIN32 + +typedef struct { + char f1; +} Size1; + +typedef struct { + char f1; + char f2; +} Size2; + +typedef struct { + char f1; + char f2; + char f3; +} Size3; + +typedef struct { + char f1; + char f2; + char f3; + char f4; +} Size4; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; +} Size5; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; +} Size6; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; +} Size7; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; +} Size8; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; + char f9; +} Size9; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; + char f9; + char f10; +} Size10; + +EXPORT(Size1) TestSize1() { + Size1 f; + f.f1 = 'a'; + return f; +} + +EXPORT(Size2) TestSize2() { + Size2 f; + f.f1 = 'a'; + f.f2 = 'b'; + return f; +} + +EXPORT(Size3) TestSize3() { + Size3 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + return f; +} + +EXPORT(Size4) TestSize4() { + Size4 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + return f; +} + +EXPORT(Size5) TestSize5() { + Size5 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + return f; +} + +EXPORT(Size6) TestSize6() { + Size6 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + return f; +} + +EXPORT(Size7) TestSize7() { + Size7 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + return f; +} + +EXPORT(Size8) TestSize8() { + Size8 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + return f; +} + +EXPORT(Size9) TestSize9() { + Size9 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + f.f9 = 'i'; + return f; +} + +EXPORT(Size10) TestSize10() { + Size10 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + f.f9 = 'i'; + f.f10 = 'j'; + return f; +} + +#endif + #ifdef MS_WIN32 EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } diff --git a/tests/ctypes_test/_ctypes_test.vcxproj b/tests/ctypes_test/_ctypes_test.vcxproj index d7fd2b3e3..2a902f5d8 100644 --- a/tests/ctypes_test/_ctypes_test.vcxproj +++ b/tests/ctypes_test/_ctypes_test.vcxproj @@ -23,32 +23,32 @@ {0BDA76B0-44BF-47B7-AA21-C247F83FAF73} Win32Proj ctypestest - 10.0.17134.0 + 10.0 DynamicLibrary true - v141 + v143 Unicode DynamicLibrary false - v141 + v143 true Unicode DynamicLibrary true - v141 + v143 Unicode DynamicLibrary false - v141 + v143 true Unicode diff --git a/tests/suite/_ctypes_test_darwin_arm64.pyd b/tests/suite/_ctypes_test_darwin_arm64.pyd index ae5b989b5..f21ee70bc 100755 Binary files a/tests/suite/_ctypes_test_darwin_arm64.pyd and b/tests/suite/_ctypes_test_darwin_arm64.pyd differ diff --git a/tests/suite/_ctypes_test_darwin_x86_64.pyd b/tests/suite/_ctypes_test_darwin_x86_64.pyd index f924090ab..ccb8c0d39 100755 Binary files a/tests/suite/_ctypes_test_darwin_x86_64.pyd and b/tests/suite/_ctypes_test_darwin_x86_64.pyd differ diff --git a/tests/suite/_ctypes_test_linux_aarch64.pyd b/tests/suite/_ctypes_test_linux_aarch64.pyd index 4899a64f6..7dd82e4e0 100755 Binary files a/tests/suite/_ctypes_test_linux_aarch64.pyd and b/tests/suite/_ctypes_test_linux_aarch64.pyd differ diff --git a/tests/suite/_ctypes_test_linux_i686.pyd b/tests/suite/_ctypes_test_linux_i686.pyd index 3e8f5a186..71b3a5ed9 100755 Binary files a/tests/suite/_ctypes_test_linux_i686.pyd and b/tests/suite/_ctypes_test_linux_i686.pyd differ diff --git a/tests/suite/_ctypes_test_linux_x86_64.pyd b/tests/suite/_ctypes_test_linux_x86_64.pyd index b7fe4fb93..7b191bede 100755 Binary files a/tests/suite/_ctypes_test_linux_x86_64.pyd and b/tests/suite/_ctypes_test_linux_x86_64.pyd differ diff --git a/tests/suite/_ctypes_test_win32.pyd b/tests/suite/_ctypes_test_win32.pyd index 3f0af47cc..fb98ded27 100644 Binary files a/tests/suite/_ctypes_test_win32.pyd and b/tests/suite/_ctypes_test_win32.pyd differ diff --git a/tests/suite/_ctypes_test_win64.pyd b/tests/suite/_ctypes_test_win64.pyd index b42b11650..aad324640 100644 Binary files a/tests/suite/_ctypes_test_win64.pyd and b/tests/suite/_ctypes_test_win64.pyd differ