Mercurial > pub > dyncall > dyncall
annotate test/plain_c++/test_main.cc @ 533:71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
* integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv)
* windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.)
* see Changelog for details
- new calling convention modes for thiscalls (platform agnostic, was specific before)
* new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL)
- dcCallF(), dcVCallF(), dcArgF() and dcVArgF():
* added support for aggregates-by-value (wasn't part of patch)
* change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change)
- added macros to feature test implementation for aggregate-by-value and syscall support
- changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order
- doc:
* man page updates to describe aggregate interface
* manual overview changes to highlight platforms with aggregate-by-value support
- test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author | Tassilo Philipp |
---|---|
date | Thu, 21 Apr 2022 13:35:47 +0200 |
parents | ddfb9577a00e |
children | 0c3f5355769d |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/plain_c++/test_main.cc | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
6 Description: |
0 | 7 License: |
8 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
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 | |
29 #include "../../dyncall/dyncall.h" | |
30 #include "../common/platformInit.h" | |
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
32 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
33 #include "../../dyncall/dyncall_aggregate.h" |
0 | 34 |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
35 #include <signal.h> |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
36 #include <setjmp.h> |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
37 #include <stdarg.h> |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
38 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
39 jmp_buf jbuf; |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
40 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
41 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
42 void segv_handler(int sig) |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
43 { |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
44 longjmp(jbuf, 1); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
45 } |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
46 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
47 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
48 /* ------------------------------------------------------------------------- |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
49 * test: identity function calls |
0 | 50 * ------------------------------------------------------------------------- */ |
51 | |
52 #define DEF_FUNCS(API,NAME) \ | |
53 void API fun_##NAME##_v() { } \ | |
54 DCbool API fun_##NAME##_b(DCbool x) { return x; } \ | |
55 DCint API fun_##NAME##_i(DCint x) { return x; } \ | |
56 DClong API fun_##NAME##_j(DClong x) { return x; } \ | |
57 DClonglong API fun_##NAME##_l(DClonglong x) { return x; } \ | |
58 DCfloat API fun_##NAME##_f(DCfloat x) { return x; } \ | |
59 DCdouble API fun_##NAME##_d(DCdouble x) { return x; } \ | |
60 DCpointer API fun_##NAME##_p(DCpointer x) { return x; } | |
61 | |
62 /* __cdecl */ | |
63 | |
64 #if !defined(DC__OS_Win32) | |
65 # define __cdecl | |
66 #endif | |
67 | |
68 | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
69 /* ------------------------------------------------------------------------- |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
70 * test: identity this calls |
0 | 71 * ------------------------------------------------------------------------- */ |
72 | |
73 union ValueUnion | |
74 { | |
75 DCbool B; | |
76 DCint i; | |
77 DClong j; | |
78 DClonglong l; | |
79 DCfloat f; | |
80 DCdouble d; | |
81 DCpointer p; | |
82 }; | |
83 | |
84 /* C++ class using __cdecl this call */ | |
85 | |
86 // #define VTBI_DESTRUCTOR 0 | |
87 | |
88 /* | |
89 * the layout of the VTable is non-standard and it is not clear what is the initial real first method index. | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
90 * so far it turns out that: |
0 | 91 * on vc/x86 : 1 |
92 * on GCC/x86 : 2 | |
93 */ | |
94 | |
95 #if defined DC__C_MSVC | |
96 #define VTBI_BASE 1 | |
97 #else | |
98 #define VTBI_BASE 2 | |
99 #endif | |
100 | |
101 #define VTBI_SET_BOOL VTBI_BASE+0 | |
102 #define VTBI_GET_BOOL VTBI_BASE+1 | |
103 #define VTBI_SET_INT VTBI_BASE+2 | |
104 #define VTBI_GET_INT VTBI_BASE+3 | |
105 #define VTBI_SET_LONG VTBI_BASE+4 | |
106 #define VTBI_GET_LONG VTBI_BASE+5 | |
107 #define VTBI_SET_LONG_LONG VTBI_BASE+6 | |
108 #define VTBI_GET_LONG_LONG VTBI_BASE+7 | |
109 #define VTBI_SET_FLOAT VTBI_BASE+8 | |
110 #define VTBI_GET_FLOAT VTBI_BASE+9 | |
111 #define VTBI_SET_DOUBLE VTBI_BASE+10 | |
112 #define VTBI_GET_DOUBLE VTBI_BASE+11 | |
113 #define VTBI_SET_POINTER VTBI_BASE+12 | |
114 #define VTBI_GET_POINTER VTBI_BASE+13 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
115 #define VTBI_SUM_3_INTS VTBI_BASE+14 |
0 | 116 |
117 class Value | |
118 { | |
119 public: | |
120 virtual ~Value() {} | |
121 | |
122 virtual void __cdecl setBool(DCbool x) { mValue.B = x; } | |
123 virtual DCbool __cdecl getBool() { return mValue.B; } | |
124 virtual void __cdecl setInt(DCint x) { mValue.i = x; } | |
125 virtual DCint __cdecl getInt() { return mValue.i; } | |
126 virtual void __cdecl setLong(DClong x) { mValue.j = x; } | |
127 virtual DClong __cdecl getLong() { return mValue.j; } | |
128 virtual void __cdecl setLongLong(DClonglong x) { mValue.l = x; } | |
129 virtual DClonglong __cdecl getLongLong() { return mValue.l; } | |
130 virtual void __cdecl setFloat(DCfloat x) { mValue.f = x; } | |
131 virtual DCfloat __cdecl getFloat() { return mValue.f; } | |
132 virtual void __cdecl setDouble(DCdouble x) { mValue.d = x; } | |
133 virtual DCdouble __cdecl getDouble() { return mValue.d; } | |
134 virtual void __cdecl setPtr(DCpointer x) { mValue.p = x; } | |
135 virtual DCpointer __cdecl getPtr() { return mValue.p; } | |
136 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
137 /* ellipsis test w/ this ptr */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
138 virtual int __cdecl sum3Ints(DCint x, ...) { va_list va; va_start(va,x); x += va_arg(va,int) + va_arg(va,int); va_end(va); return x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
139 |
0 | 140 private: |
141 ValueUnion mValue; | |
142 }; | |
143 | |
144 template<typename T> | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
145 bool testCallValue(DCCallVM* pc, const char* name) |
0 | 146 { |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
147 bool r = true, b; |
0 | 148 T o; |
149 T* pThis = &o; | |
150 DCpointer* vtbl = *( (DCpointer**) pThis ); /* vtbl is located at beginning of class */ | |
151 | |
152 /* set/get bool (TRUE) */ | |
153 | |
154 dcReset(pc); | |
155 dcArgPointer(pc, pThis); | |
156 dcArgBool(pc,DC_TRUE); | |
157 dcCallVoid(pc, vtbl[VTBI_SET_BOOL] ); | |
158 dcReset(pc); | |
159 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
160 b = ( dcCallBool(pc, vtbl[VTBI_GET_BOOL] ) == DC_TRUE ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
161 printf("bt (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
162 r = r && b; |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
163 |
0 | 164 /* set/get bool (FALSE) */ |
165 | |
166 dcReset(pc); | |
167 dcArgPointer(pc, pThis); | |
168 dcArgBool(pc,DC_FALSE); | |
169 dcCallVoid(pc, vtbl[VTBI_SET_BOOL] ); | |
170 dcReset(pc); | |
171 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
172 b = ( dcCallBool(pc, vtbl[VTBI_GET_BOOL] ) == DC_FALSE ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
173 printf("bf (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
174 r = r && b; |
0 | 175 |
176 /* set/get int */ | |
177 | |
178 dcReset(pc); | |
179 dcArgPointer(pc, pThis); | |
180 dcArgInt(pc,1234); | |
181 dcCallVoid(pc, vtbl[VTBI_SET_INT] ); | |
182 dcReset(pc); | |
183 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
184 b = ( dcCallInt(pc, vtbl[VTBI_GET_INT] ) == 1234 ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
185 printf("i (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
186 r = r && b; |
0 | 187 |
188 /* set/get long */ | |
189 | |
190 dcReset(pc); | |
191 dcArgPointer(pc, pThis); | |
192 dcArgLong(pc,0xCAFEBABEUL); | |
193 dcCallVoid(pc, vtbl[VTBI_SET_LONG] ); | |
194 dcReset(pc); | |
195 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
196 b = ( dcCallLong(pc, vtbl[VTBI_GET_LONG] ) == (DClong)0xCAFEBABEUL ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
197 printf("l (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
198 r = r && b; |
0 | 199 |
200 /* set/get long long */ | |
201 | |
202 dcReset(pc); | |
203 dcArgPointer(pc, pThis); | |
204 dcArgLongLong(pc,0xCAFEBABEDEADC0DELL); | |
205 dcCallVoid(pc, vtbl[VTBI_SET_LONG_LONG] ); | |
206 dcReset(pc); | |
207 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
208 b = ( dcCallLongLong(pc, vtbl[VTBI_GET_LONG_LONG] ) == (DClonglong)0xCAFEBABEDEADC0DELL ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
209 printf("ll (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
210 r = r && b; |
0 | 211 |
212 /* set/get float */ | |
213 | |
214 dcReset(pc); | |
215 dcArgPointer(pc, pThis); | |
216 dcArgFloat(pc,1.2345f); | |
217 dcCallVoid(pc, vtbl[VTBI_SET_FLOAT] ); | |
218 dcReset(pc); | |
219 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
220 b = ( dcCallFloat(pc, vtbl[VTBI_GET_FLOAT] ) == 1.2345f ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
221 printf("f (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
222 r = r && b; |
0 | 223 |
224 /* set/get double */ | |
225 | |
226 dcReset(pc); | |
227 dcArgPointer(pc, pThis); | |
228 dcArgDouble(pc,1.23456789); | |
229 dcCallVoid(pc, vtbl[VTBI_SET_DOUBLE] ); | |
230 dcReset(pc); | |
231 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
232 b = ( dcCallDouble(pc, vtbl[VTBI_GET_DOUBLE] ) == 1.23456789 ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
233 printf("d (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
234 r = r && b; |
0 | 235 |
236 /* set/get pointer */ | |
237 | |
238 dcReset(pc); | |
239 dcArgPointer(pc, pThis); | |
240 dcArgPointer(pc, (DCpointer) 0xCAFEBABE ); | |
241 dcCallVoid(pc, vtbl[VTBI_SET_POINTER] ); | |
242 dcReset(pc); | |
243 dcArgPointer(pc, pThis); | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
244 b = ( dcCallPointer(pc, vtbl[VTBI_GET_POINTER] ) == ( (DCpointer) 0xCAFEBABE ) ); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
245 printf("p (%s): %d\n", name, b); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
246 r = r && b; |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
247 |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
248 /* ellipsis test w/ this pointer */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
249 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
250 dcReset(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
251 dcMode(pc, DC_CALL_C_ELLIPSIS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
252 dcArgPointer(pc, pThis); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
253 dcArgInt(pc, 23); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
254 dcMode(pc, DC_CALL_C_ELLIPSIS_VARARGS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
255 dcArgInt(pc, -223); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
256 dcArgInt(pc, 888); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
257 int r_ = dcCallInt(pc, vtbl[VTBI_SUM_3_INTS]); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
258 b = (r_ == 688); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
259 printf("... (%s): %d\n", name, b); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
260 r = r && b; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
261 |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
262 return r; |
0 | 263 } |
264 | |
265 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
266 #if defined(DC__OS_Win32) && defined(DC__C_MSVC) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
267 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
268 /* C++ class using (on win32: microsoft) this call */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
269 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
270 class ValueMS |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
271 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
272 public: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
273 virtual ~ValueMS() {} |
0 | 274 |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
275 virtual void setBool(DCbool x) { mValue.B = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
276 virtual DCbool getBool() { return mValue.B; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
277 virtual void setInt(DCint x) { mValue.i = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
278 virtual DCint getInt() { return mValue.i; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
279 virtual void setLong(DClong x) { mValue.j = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
280 virtual DClong getLong() { return mValue.j; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
281 virtual void setLongLong(DClonglong x) { mValue.l = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
282 virtual DClonglong getLongLong() { return mValue.l; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
283 virtual void setFloat(DCfloat x) { mValue.f = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
284 virtual DCfloat getFloat() { return mValue.f; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
285 virtual void setDouble(DCdouble x) { mValue.d = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
286 virtual DCdouble getDouble() { return mValue.d; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
287 virtual void setPtr(DCpointer x) { mValue.p = x; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
288 virtual DCpointer getPtr() { return mValue.p; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
289 private: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
290 ValueUnion mValue; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
291 }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
292 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
293 static bool testCallThisMS() |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
294 { |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
295 bool r = false; |
0 | 296 DCCallVM* pc = dcNewCallVM(4096); |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
297 dcMode(pc, DC_CALL_C_X86_WIN32_THIS_MS); |
0 | 298 dcReset(pc); |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
299 if(setjmp(jbuf) != 0) |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
300 printf("sigsegv\n"), r=false; |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
301 else |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
302 r = testCallValue<ValueMS>(pc, "MS"); |
0 | 303 dcFree(pc); |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
304 return r; |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
305 } |
0 | 306 |
307 #endif | |
308 | |
309 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
310 static bool testCallThisC() |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
311 { |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
312 bool r = false; |
0 | 313 DCCallVM* pc = dcNewCallVM(4096); |
466
ddfb9577a00e
introduced platform-native thiscall mode (DC_CALL_C_DEFAULT_THIS), as needed
Tassilo Philipp
parents:
348
diff
changeset
|
314 dcMode(pc, DC_CALL_C_DEFAULT_THIS); |
0 | 315 dcReset(pc); |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
316 if(setjmp(jbuf) != 0) |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
317 printf("sigsegv\n"), r=false; |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
318 else |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
319 r = testCallValue<Value>(pc, "c"); |
0 | 320 dcFree(pc); |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
321 return r; |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
322 } |
0 | 323 |
324 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
325 #if defined(DC__Feature_AggrByVal) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
326 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
327 class ValueAggr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
328 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
329 public: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
330 struct S { int i, j, k, l, m; }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
331 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
332 virtual ~ValueAggr() {} |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
333 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
334 virtual void __cdecl setAggr(S x) { mS.i = x.i; mS.j = x.j; mS.k = x.k; mS.l = x.l; mS.m = x.m; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
335 virtual S __cdecl getAggr() { return mS; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
336 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
337 /* ellipsis test w/ this ptr and big (!) aggregate return */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
338 struct Big { int sum; long long dummy[50]; /*dummy to make it not fit in any regs*/ }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
339 virtual struct Big __cdecl sum3RetAggr(DCint x, ...) { va_list va; va_start(va,x); struct Big r = { x + va_arg(va,int) + va_arg(va,int) }; va_end(va); return r; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
340 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
341 /* non-trivial aggregate */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
342 struct NonTriv { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
343 int i, j; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
344 NonTriv(int a, int b) : i(a),j(b) { } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
345 NonTriv(const NonTriv& rhs) { static int a=13, b=37; i = a++; j = b++; } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
346 }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
347 /* by value, so on first invocation a = 13,37, b = 14,38 and retval = 13*14,37*38, no matter the contents of the instances as copy ctor is called */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
348 /* NOTE: copy of return value is subject to C++ "copy elision", so it is *not* calling the copy ctor for the return value */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
349 virtual struct NonTriv __cdecl squareFields(NonTriv a, NonTriv b) { return NonTriv(a.i*b.i, a.j*b.j); } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
350 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
351 private: |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
352 struct S mS; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
353 }; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
354 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
355 #if (__cplusplus >= 201103L) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
356 # include <type_traits> |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
357 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
358 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
359 /* special case w/ e.g. MS x64 C++ calling cconf: struct return ptr is passed as *2nd* arg */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
360 static bool testCallThisAggr() |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
361 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
362 bool r = false; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
363 DCCallVM* pc = dcNewCallVM(4096); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
364 dcMode(pc, DC_CALL_C_DEFAULT_THIS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
365 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
366 if(setjmp(jbuf) != 0) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
367 printf("sigsegv\n"), r=false; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
368 else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
369 { |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
370 ValueAggr o; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
371 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
372 DCpointer* vtbl = *( (DCpointer**) &o ); /* vtbl is located at beginning of class */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
373 ValueAggr::S st = { 124, -12, 434, 20202, -99999 }, returned; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
374 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
375 #if (__cplusplus >= 201103L) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
376 bool istriv = std::is_trivial<ValueAggr::S>::value; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
377 #else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
378 bool istriv = true; /* own deduction as no type trait */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
379 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
380 DCaggr *s = dcNewAggr(5, sizeof(ValueAggr::S)); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
381 dcAggrField(s, DC_SIGCHAR_INT, offsetof(ValueAggr::S, i), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
382 dcAggrField(s, DC_SIGCHAR_INT, offsetof(ValueAggr::S, j), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
383 dcAggrField(s, DC_SIGCHAR_INT, offsetof(ValueAggr::S, k), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
384 dcAggrField(s, DC_SIGCHAR_INT, offsetof(ValueAggr::S, l), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
385 dcAggrField(s, DC_SIGCHAR_INT, offsetof(ValueAggr::S, m), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
386 dcCloseAggr(s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
387 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
388 // set S::mS |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
389 dcReset(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
390 dcArgPointer(pc, &o); // this ptr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
391 dcArgAggr(pc, s, &st); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
392 dcCallVoid(pc, vtbl[VTBI_BASE+0]); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
393 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
394 // get it back |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
395 dcReset(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
396 dcBeginCallAggr(pc, s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
397 dcArgPointer(pc, &o); // this ptr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
398 dcCallAggr(pc, vtbl[VTBI_BASE+1], s, &returned); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
399 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
400 dcFreeAggr(s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
401 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
402 r = returned.i == st.i && returned.j == st.j && returned.k == st.k && returned.l == st.l && returned.m == st.m && istriv; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
403 printf("r:{iiiii} (this/trivial): %d\n", r); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
404 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
405 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
406 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
407 /* ellipsis test w/ this pointer returning big aggregate (quite an edge |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
408 * case) by value (won't fit in regs, so hidden pointer is is used to write |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
409 * return values to), showing the need to use the DC_CALL_C_DEFAULT_THIS |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
410 * mode first, for the this ptr alone, then DC_CALL_C_ELLIPSIS, then |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
411 * DC_CALL_C_ELLIPSIS_VARARGS (test is useful on win64 where thisptr is |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
412 * passed *after* return aggregate's hidden ptr) */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
413 #if (__cplusplus >= 201103L) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
414 istriv = std::is_trivial<ValueAggr::Big>::value; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
415 #else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
416 istriv = true; /* own deduction as no type trait */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
417 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
418 s = dcNewAggr(2, sizeof(struct ValueAggr::Big)); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
419 dcAggrField(s, DC_SIGCHAR_INT, offsetof(struct ValueAggr::Big, sum), 1); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
420 dcAggrField(s, DC_SIGCHAR_LONGLONG, offsetof(struct ValueAggr::Big, dummy), 50); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
421 dcCloseAggr(s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
422 dcReset(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
423 dcMode(pc, DC_CALL_C_DEFAULT_THIS); /* <-- needed on x64/win64 */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
424 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
425 dcBeginCallAggr(pc, s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
426 dcMode(pc, DC_CALL_C_ELLIPSIS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
427 dcArgPointer(pc, &o); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
428 dcArgInt(pc, 89); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
429 dcMode(pc, DC_CALL_C_ELLIPSIS_VARARGS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
430 dcArgInt(pc, -157); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
431 dcArgInt(pc, 888); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
432 struct ValueAggr::Big big; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
433 dcCallAggr(pc, vtbl[VTBI_BASE+2], s, &big); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
434 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
435 dcFreeAggr(s); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
436 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
437 bool b = (big.sum == 820) && istriv; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
438 r = r && b; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
439 printf("r:{il[50]} (this/trivial/ellipsis): %d\n", b); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
440 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
441 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
442 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
443 /* non-trivial test ----------------------------------------------------------- */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
444 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
445 #if (__cplusplus >= 201103L) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
446 istriv = std::is_trivial<ValueAggr::NonTriv>::value; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
447 #else |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
448 istriv = false; /* own deduction as no type trait */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
449 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
450 dcReset(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
451 dcMode(pc, DC_CALL_C_DEFAULT_THIS); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
452 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
453 /* non trivial aggregates: pass NULL for DCaggr* and do copy on our own (see doc) */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
454 dcBeginCallAggr(pc, NULL); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
455 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
456 ValueAggr::NonTriv nt0(5, 6), nt1(7, 8), ntr(0, 0); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
457 dcArgAggr(pc, NULL, &o); // this ptr |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
458 /* make *own* copies, as dyncall cannot know how to call copy ctor */ //@@@ put into doc |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
459 ValueAggr::NonTriv nt0_ = nt0, nt1_ = nt1; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
460 dcArgAggr(pc, NULL, &nt0_); /* use *own* copy */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
461 dcArgAggr(pc, NULL, &nt1_); /* use *own* copy */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
462 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
463 dcCallAggr(pc, vtbl[VTBI_BASE+3], NULL, &ntr); /* note: "copy elision", so retval might *not* call copy ctor */ |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
464 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
465 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
466 b = ntr.i == 13*14 && ntr.j == 37*38 && !istriv; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
467 r = r && b; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
468 printf("r:{ii} (this/nontrivial/retval_copy_elision): %d\n", b); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
469 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
470 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
471 dcFree(pc); |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
472 return r; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
473 } |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
474 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
475 #endif |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
476 |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
477 |
0 | 478 extern "C" { |
479 | |
480 int main(int argc, char* argv[]) | |
481 { | |
482 dcTest_initPlatform(); | |
483 | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
484 signal(SIGSEGV, segv_handler); |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
485 |
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
486 bool r = true; |
0 | 487 |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
488 r = testCallThisC() && r; |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
489 #if defined(DC__OS_Win32) && defined(DC__C_MSVC) |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
490 r = testCallThisMS() && r; |
0 | 491 #endif |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
492 #if defined(DC__Feature_AggrByVal) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
493 r = testCallThisAggr() && r; |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
466
diff
changeset
|
494 #endif |
0 | 495 |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
496 printf("result: plain_cpp: %d\n", r); |
0 | 497 |
498 dcTest_deInitPlatform(); | |
499 | |
324
dd78bd0152af
- removal of never-adopted mini-test framework stub
Tassilo Philipp
parents:
281
diff
changeset
|
500 return !r; |
0 | 501 } |
502 | |
503 } // extern "C" | |
504 |