Mercurial > pub > dyncall > dyncall
annotate test/suite2_x86win32std/main.cc @ 663:127b569978cc default tip
- another tweak handling clang trying to be too smart (see last commit)
author | Tassilo Philipp |
---|---|
date | Sun, 24 Mar 2024 13:52:44 +0100 |
parents | 85b7a117b807 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/suite2_x86win32std/main.cc | |
6 Description: | |
7 License: | |
8 | |
606
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 #include "../../dyncall/dyncall.h" | |
29 #include "config.h" | |
30 #include "../../dyncall/dyncall_value.h" | |
31 #include "funcinfo.h" | |
32 #include <stdlib.h> | |
33 #include "../common/platformInit.h" | |
34 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
35 | |
36 | |
37 int getId(); | |
38 DCpointer getFunc(int x); | |
39 DCValue* getArg(int pos); | |
40 | |
41 | |
606
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
42 static DCbool valueBool [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
43 static DCchar valueChar [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
44 static DCshort valueShort [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
45 static DCint valueInt [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
46 static DClong valueLong [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
47 static DClonglong valueLongLong[MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
48 static DCdouble valueDouble [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
49 static DCpointer valuePointer [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
605
diff
changeset
|
50 static DCfloat valueFloat [MAXARGS]; |
0 | 51 |
52 | |
53 void clearValues(); | |
54 | |
55 void init() | |
56 { | |
57 for (int i = 0 ; i < MAXARGS ; ++i ) { | |
58 | |
59 valueBool[i] = DCbool( (i % 1) ? DC_TRUE : DC_FALSE ); | |
60 valueChar[i] = DCchar(i); | |
61 valueShort[i] = DCshort(i); | |
62 valueInt[i] = DCint(i); | |
63 valueLong[i] = DClong(i); | |
64 valueLongLong[i] = DClonglong(i); | |
65 valueDouble[i] = DCdouble(i); | |
66 valuePointer[i] = DCpointer(i); | |
67 valueFloat[i] = DCfloat(i); | |
68 } | |
69 } | |
70 | |
71 | |
72 bool test(int x) | |
73 { | |
74 bool r = true; | |
75 clearValues(); | |
76 | |
77 DCCallVM* pCall; | |
78 | |
79 funcinfo* fi = &gFuncInfos[x]; | |
80 | |
81 const DCsigchar* sig = &fi->sig[2]; | |
82 const DCsigchar* ptr = sig; | |
83 DCsigchar ch; | |
84 int pos; | |
85 | |
86 pos = 0; | |
87 | |
88 pCall = dcNewCallVM(4096); | |
89 dcMode(pCall, DC_CALL_C_X86_WIN32_STD); | |
90 dcReset(pCall); | |
91 | |
92 while ( (ch=*ptr++) != '\0' ) { | |
93 switch(ch) { | |
94 case DC_SIGCHAR_BOOL: dcArgBool( pCall, valueBool[pos] ); break; | |
95 case DC_SIGCHAR_CHAR: dcArgChar( pCall, valueChar[pos] ); break; | |
96 case DC_SIGCHAR_SHORT: dcArgShort( pCall, valueShort[pos] ); break; | |
97 case DC_SIGCHAR_INT: dcArgInt( pCall, valueInt[pos] ); break; | |
98 case DC_SIGCHAR_LONG: dcArgLong( pCall, valueLong[pos] ); break; | |
99 case DC_SIGCHAR_LONGLONG: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
100 case DC_SIGCHAR_FLOAT: dcArgFloat( pCall, valueFloat[pos] ); break; | |
101 case DC_SIGCHAR_DOUBLE: dcArgDouble( pCall, valueDouble[pos] ); break; | |
102 case DC_SIGCHAR_POINTER: dcArgPointer( pCall, valuePointer[pos] ); break; | |
103 } | |
104 ++pos; | |
105 } | |
106 | |
107 dcCallVoid( pCall, fi->funcptr ); | |
108 | |
109 | |
110 if ( getId() == x ) { | |
111 | |
112 ptr = sig; | |
113 pos = 0; | |
114 while( ( ch=*ptr++ ) != '\0' ) { | |
115 | |
116 switch(ch) { | |
117 case DC_SIGCHAR_BOOL: if ( getArg(pos)->B != valueBool [pos] ) r = false; break; | |
118 case DC_SIGCHAR_CHAR: if ( getArg(pos)->c != valueChar [pos] ) r = false; break; | |
119 case DC_SIGCHAR_SHORT: if ( getArg(pos)->s != valueShort [pos] ) r = false; break; | |
120 case DC_SIGCHAR_INT: if ( getArg(pos)->i != valueInt [pos] ) r = false; break; | |
121 case DC_SIGCHAR_LONG: if ( getArg(pos)->l != valueLong [pos] ) r = false; break; | |
122 case DC_SIGCHAR_LONGLONG: if ( getArg(pos)->L != valueLongLong [pos] ) r = false; break; | |
123 case DC_SIGCHAR_FLOAT: if ( getArg(pos)->f != valueFloat [pos] ) r = false; break; | |
124 case DC_SIGCHAR_DOUBLE: if ( getArg(pos)->d != valueDouble[pos] ) r = false; break; | |
125 case DC_SIGCHAR_POINTER: if ( getArg(pos)->p != valuePointer [pos] ) r = false; break; | |
126 } | |
127 ++pos; | |
128 } | |
129 | |
130 } else { | |
131 r = false; | |
132 } | |
133 | |
134 printf("%d-%s:%d\n", x, sig, r); | |
135 | |
136 dcFree(pCall); | |
137 | |
138 return r; | |
139 } | |
140 | |
141 | |
142 bool run_range(int from, int to) | |
143 { | |
144 bool r = true; | |
145 for (int i = from ; i < to ; ++i ) | |
146 r &= test(i); | |
147 return r; | |
148 } | |
149 | |
150 extern "C" { | |
151 | |
152 int main(int argc, char* argv[]) | |
153 { | |
154 dcTest_initPlatform(); | |
155 | |
156 bool success = false; | |
157 init(); | |
158 if (argc == 2) { | |
159 int index = atoi(argv[1]); | |
160 success = run_range( index, index+1 ); | |
161 } else if (argc == 3) { | |
162 int from = atoi(argv[1]); | |
163 int to = atoi(argv[2])+1; | |
164 success = run_range(from,to); | |
165 } else { | |
166 success = run_range(0,NCASES); | |
167 } | |
168 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
169 printf("result: suite2_x86win32std: %d\n", success); |
0 | 170 |
171 dcTest_deInitPlatform(); | |
172 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
173 return !success; |
0 | 174 } |
175 | |
176 } // extern "C" | |
177 |