Skip to content

Commit 99a014f

Browse files
authored
Update _ctypes_test.c to version from CPython 3.6 (#1919)
* Update `_ctypes_test.c` to version from CPython 3.6 * Compile `_ctypes_test` on Darwin * Compile `_ctypes_test` on Linux/ARM64 * Compile `_ctypes_test` on Linux/Intel * Upgrade `_ctypes_test.vcxproj` ftom toolset v141 to v143 * Compile `_ctypes_test` on Windows * Add build instructions
1 parent b234b40 commit 99a014f

10 files changed

+260
-27
lines changed

tests/ctypes_test/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# By default, `make` produces a PYD for the current OS/processor.
2+
# To build a specific PYD, the full command is:
3+
# * _ctypes_test_darwin_arm64.pyd: make OS=darwin MACHINE=arm64
4+
# * _ctypes_test_darwin_x86_64.pyd: make OS=darwin MACHINE=x86_64
5+
# * _ctypes_test_linux_aarch64.pyd: make OS=linux MACHINE=aarch64
6+
# * _ctypes_test_linux_x86_64.pyd: make OS=linux MACHINE=x86_64 BITS=64
7+
# * _ctypes_test_linux_i686.pyd: make OS=linux MACHINE=i686 BITS=32
8+
# Parameter OS=... may be skipped if it is the same as the host OS.
9+
# For Windows builds, use `_ctypes_test.vcxproj` or `_ctypes_test.sln` with MSBuild:
10+
# * _ctypes_test_win64.pyd: msbuild -p:Configuration=Release -p:Platform=x64
11+
# * _ctypes_test_win32.pyd: msbuild -p:Configuration=Release -p:Platform=x86
12+
113
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
214
MACHINE ?= $(shell uname -m)
315
BITS ?= 64

tests/ctypes_test/_ctypes_test.c

Lines changed: 243 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <inttypes.h>
77
#include <wchar.h>
88

9-
#define HAVE_LONG_LONG
109
#define PY_LONG_LONG long long
1110

1211
#ifdef MS_WIN32
@@ -53,6 +52,37 @@ _testfunc_cbk_large_struct(Test in, void (*func)(Test))
5352
func(in);
5453
}
5554

55+
/*
56+
* See issue 29565. Update a structure passed by value;
57+
* the caller should not see any change.
58+
*/
59+
60+
EXPORT(void)
61+
_testfunc_large_struct_update_value(Test in)
62+
{
63+
((volatile Test *)&in)->first = 0x0badf00d;
64+
((volatile Test *)&in)->second = 0x0badf00d;
65+
((volatile Test *)&in)->third = 0x0badf00d;
66+
}
67+
68+
typedef struct {
69+
unsigned int first;
70+
unsigned int second;
71+
} TestReg;
72+
73+
74+
EXPORT(TestReg) last_tfrsuv_arg;
75+
76+
77+
EXPORT(void)
78+
_testfunc_reg_struct_update_value(TestReg in)
79+
{
80+
last_tfrsuv_arg = in;
81+
((volatile TestReg *)&in)->first = 0x0badf00d;
82+
((volatile TestReg *)&in)->second = 0x0badf00d;
83+
}
84+
85+
5686
EXPORT(void)testfunc_array(int values[4])
5787
{
5888
printf("testfunc_array %d %d %d %d\n",
@@ -242,16 +272,15 @@ EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
242272
return (*func)(table);
243273
}
244274

245-
#ifdef HAVE_LONG_LONG
246-
EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
247-
double d, PY_LONG_LONG q)
275+
EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
276+
double d, long long q)
248277
{
249-
return (PY_LONG_LONG)(b + h + i + l + f + d + q);
278+
return (long long)(b + h + i + l + f + d + q);
250279
}
251280

252-
EXPORT(PY_LONG_LONG) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
281+
EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
253282
{
254-
return (PY_LONG_LONG)(b + h + i + l + f + d);
283+
return (long long)(b + h + i + l + f + d);
255284
}
256285

257286
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))
264293
return sum;
265294
}
266295

267-
EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
268-
PY_LONG_LONG (*func)(PY_LONG_LONG))
296+
EXPORT(long long) _testfunc_callback_q_qf(long long value,
297+
long long (*func)(long long))
269298
{
270-
PY_LONG_LONG sum = 0;
299+
long long sum = 0;
271300

272301
while (value != 0) {
273302
sum += func(value);
@@ -276,8 +305,6 @@ EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
276305
return sum;
277306
}
278307

279-
#endif
280-
281308
typedef struct {
282309
char *name;
283310
char *value;
@@ -377,8 +404,8 @@ EXPORT(void) _py_func(void)
377404
{
378405
}
379406

380-
EXPORT(PY_LONG_LONG) last_tf_arg_s;
381-
EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u;
407+
EXPORT(long long) last_tf_arg_s;
408+
EXPORT(unsigned long long) last_tf_arg_u;
382409

383410
struct BITS {
384411
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; }
443470
EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; }
444471
EXPORT(long) tf_l(long c) { S; return c/3; }
445472
EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; }
446-
EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; }
447-
EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
473+
EXPORT(long long) tf_q(long long c) { S; return c/3; }
474+
EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; }
448475
EXPORT(float) tf_f(float c) { S; return c/3; }
449476
EXPORT(double) tf_d(double c) { S; return c/3; }
450477
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; }
458485
EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; }
459486
EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; }
460487
EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; }
461-
EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; }
462-
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
488+
EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; }
489+
EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; }
463490
EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; }
464491
EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; }
465492
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; }
474501
EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; }
475502
EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; }
476503
EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; }
477-
EXPORT(PY_LONG_LONG) tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
478-
EXPORT(unsigned PY_LONG_LONG) tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
504+
EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; }
505+
EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
479506
EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; }
480507
EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; }
481508
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; }
490517
EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; }
491518
EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; }
492519
EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; }
493-
EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
494-
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
520+
EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; }
521+
EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
495522
EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; }
496523
EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; }
497524
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)
618645
*pj += b;
619646
}
620647

648+
#ifdef MS_WIN32
649+
650+
typedef struct {
651+
char f1;
652+
} Size1;
653+
654+
typedef struct {
655+
char f1;
656+
char f2;
657+
} Size2;
658+
659+
typedef struct {
660+
char f1;
661+
char f2;
662+
char f3;
663+
} Size3;
664+
665+
typedef struct {
666+
char f1;
667+
char f2;
668+
char f3;
669+
char f4;
670+
} Size4;
671+
672+
typedef struct {
673+
char f1;
674+
char f2;
675+
char f3;
676+
char f4;
677+
char f5;
678+
} Size5;
679+
680+
typedef struct {
681+
char f1;
682+
char f2;
683+
char f3;
684+
char f4;
685+
char f5;
686+
char f6;
687+
} Size6;
688+
689+
typedef struct {
690+
char f1;
691+
char f2;
692+
char f3;
693+
char f4;
694+
char f5;
695+
char f6;
696+
char f7;
697+
} Size7;
698+
699+
typedef struct {
700+
char f1;
701+
char f2;
702+
char f3;
703+
char f4;
704+
char f5;
705+
char f6;
706+
char f7;
707+
char f8;
708+
} Size8;
709+
710+
typedef struct {
711+
char f1;
712+
char f2;
713+
char f3;
714+
char f4;
715+
char f5;
716+
char f6;
717+
char f7;
718+
char f8;
719+
char f9;
720+
} Size9;
721+
722+
typedef struct {
723+
char f1;
724+
char f2;
725+
char f3;
726+
char f4;
727+
char f5;
728+
char f6;
729+
char f7;
730+
char f8;
731+
char f9;
732+
char f10;
733+
} Size10;
734+
735+
EXPORT(Size1) TestSize1() {
736+
Size1 f;
737+
f.f1 = 'a';
738+
return f;
739+
}
740+
741+
EXPORT(Size2) TestSize2() {
742+
Size2 f;
743+
f.f1 = 'a';
744+
f.f2 = 'b';
745+
return f;
746+
}
747+
748+
EXPORT(Size3) TestSize3() {
749+
Size3 f;
750+
f.f1 = 'a';
751+
f.f2 = 'b';
752+
f.f3 = 'c';
753+
return f;
754+
}
755+
756+
EXPORT(Size4) TestSize4() {
757+
Size4 f;
758+
f.f1 = 'a';
759+
f.f2 = 'b';
760+
f.f3 = 'c';
761+
f.f4 = 'd';
762+
return f;
763+
}
764+
765+
EXPORT(Size5) TestSize5() {
766+
Size5 f;
767+
f.f1 = 'a';
768+
f.f2 = 'b';
769+
f.f3 = 'c';
770+
f.f4 = 'd';
771+
f.f5 = 'e';
772+
return f;
773+
}
774+
775+
EXPORT(Size6) TestSize6() {
776+
Size6 f;
777+
f.f1 = 'a';
778+
f.f2 = 'b';
779+
f.f3 = 'c';
780+
f.f4 = 'd';
781+
f.f5 = 'e';
782+
f.f6 = 'f';
783+
return f;
784+
}
785+
786+
EXPORT(Size7) TestSize7() {
787+
Size7 f;
788+
f.f1 = 'a';
789+
f.f2 = 'b';
790+
f.f3 = 'c';
791+
f.f4 = 'd';
792+
f.f5 = 'e';
793+
f.f6 = 'f';
794+
f.f7 = 'g';
795+
return f;
796+
}
797+
798+
EXPORT(Size8) TestSize8() {
799+
Size8 f;
800+
f.f1 = 'a';
801+
f.f2 = 'b';
802+
f.f3 = 'c';
803+
f.f4 = 'd';
804+
f.f5 = 'e';
805+
f.f6 = 'f';
806+
f.f7 = 'g';
807+
f.f8 = 'h';
808+
return f;
809+
}
810+
811+
EXPORT(Size9) TestSize9() {
812+
Size9 f;
813+
f.f1 = 'a';
814+
f.f2 = 'b';
815+
f.f3 = 'c';
816+
f.f4 = 'd';
817+
f.f5 = 'e';
818+
f.f6 = 'f';
819+
f.f7 = 'g';
820+
f.f8 = 'h';
821+
f.f9 = 'i';
822+
return f;
823+
}
824+
825+
EXPORT(Size10) TestSize10() {
826+
Size10 f;
827+
f.f1 = 'a';
828+
f.f2 = 'b';
829+
f.f3 = 'c';
830+
f.f4 = 'd';
831+
f.f5 = 'e';
832+
f.f6 = 'f';
833+
f.f7 = 'g';
834+
f.f8 = 'h';
835+
f.f9 = 'i';
836+
f.f10 = 'j';
837+
return f;
838+
}
839+
840+
#endif
841+
621842
#ifdef MS_WIN32
622843
EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); }
623844
EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); }

0 commit comments

Comments
 (0)