annotate test/plain_c++/test_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 086362f4ae3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 #include "../../dyncall/dyncall.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
33 #include "../../dyncall/dyncall_aggregate.h"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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 this calls
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 * ------------------------------------------------------------------------- */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 union ValueUnion
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 DCbool B;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 DCint i;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 DClong j;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 DClonglong l;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 DCfloat f;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 DCdouble d;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 DCpointer p;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 };
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 /*
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
65 * the layout of the VTable is non-standard and it is not clear what is the
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
66 * initial real first method index.
557
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
67 * so far it turns out, *iff* dtor is defined, that:
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
68 * on msvc/x86 : 1
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
69 * on msvc/x64 : 1
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
70 * on gcc/x86 : 2
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
71 * on gcc/x64 : 2
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
72 * on clang/x86 : 2
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
73 * on clang/x64 : 2
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75
557
b36a738c8975 - dyncallback: fix for calling back win/x64 C++ methods returning non-trivial aggregates (thanks Raphael!)
Tassilo Philipp
parents: 539
diff changeset
76 // vtable offset to first func of class Value and class ValueMS, skipping dtor
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 #if defined DC__C_MSVC
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 #define VTBI_BASE 1
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 #else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 #define VTBI_BASE 2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 #endif
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 #define VTBI_SET_BOOL VTBI_BASE+0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 #define VTBI_GET_BOOL VTBI_BASE+1
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 #define VTBI_SET_INT VTBI_BASE+2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 #define VTBI_GET_INT VTBI_BASE+3
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 #define VTBI_SET_LONG VTBI_BASE+4
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 #define VTBI_GET_LONG VTBI_BASE+5
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 #define VTBI_SET_LONG_LONG VTBI_BASE+6
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 #define VTBI_GET_LONG_LONG VTBI_BASE+7
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 #define VTBI_SET_FLOAT VTBI_BASE+8
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 #define VTBI_GET_FLOAT VTBI_BASE+9
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 #define VTBI_SET_DOUBLE VTBI_BASE+10
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 #define VTBI_GET_DOUBLE VTBI_BASE+11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 #define VTBI_SET_POINTER VTBI_BASE+12
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 #define VTBI_GET_POINTER VTBI_BASE+13
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
97 #define VTBI_SUM_3_INTS VTBI_BASE+14
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
99 #define TEST_CLASS(NAME, CCONV) \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
100 class NAME \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
101 { \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
102 public: \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
103 virtual ~NAME() { } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
104 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
105 virtual void CCONV setBool(DCbool x) { mValue.B = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
106 virtual DCbool CCONV getBool() { return mValue.B; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
107 virtual void CCONV setInt(DCint x) { mValue.i = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
108 virtual DCint CCONV getInt() { return mValue.i; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
109 virtual void CCONV setLong(DClong x) { mValue.j = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
110 virtual DClong CCONV getLong() { return mValue.j; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
111 virtual void CCONV setLongLong(DClonglong x) { mValue.l = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
112 virtual DClonglong CCONV getLongLong() { return mValue.l; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
113 virtual void CCONV setFloat(DCfloat x) { mValue.f = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
114 virtual DCfloat CCONV getFloat() { return mValue.f; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
115 virtual void CCONV setDouble(DCdouble x) { mValue.d = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
116 virtual DCdouble CCONV getDouble() { return mValue.d; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
117 virtual void CCONV setPtr(DCpointer x) { mValue.p = x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
118 virtual DCpointer CCONV getPtr() { return mValue.p; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
119 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
120 /* ellipsis test w/ this ptr */ \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
121 virtual int CCONV sum3Ints(DCint x, ...) { va_list va; va_start(va,x); x += va_arg(va,int); x += va_arg(va,int); va_end(va); return x; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
122 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
123 private: \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
124 ValueUnion mValue; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
125 };
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126
612
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
127
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
128 #if defined(DC__Arch_Intel_x86) && !defined(DC__C_MSVC) && !defined(__cdecl)
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
129 # define __cdecl
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
130 #endif
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
131
086362f4ae3f - test/plain_c++: reintroduced an empty __cdecl define for portability
Tassilo Philipp
parents: 611
diff changeset
132
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
133 TEST_CLASS(ValueThisDef, /*empty/default*/) /* default */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
134 #if defined(DC__Arch_Intel_x86)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
135 TEST_CLASS(ValueThisCdecl, __cdecl) /* methods explicitly declared as cdecl */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
136 #if defined(DC__OS_Win32) && defined(DC__C_MSVC)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
137 TEST_CLASS(ValueThisMS, /*empty/default*/) /* microsoft this call */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
138 #endif
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
139 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
141
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
142
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 {
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
147 bool r = true, b;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 T o;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 T* pThis = &o;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 DCpointer* vtbl = *( (DCpointer**) pThis ); /* vtbl is located at beginning of class */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 /* set/get bool (TRUE) */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156 dcArgBool(pc,DC_TRUE);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157 dcCallVoid(pc, vtbl[VTBI_SET_BOOL] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
164 /* set/get bool (FALSE) */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
165
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
167 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168 dcArgBool(pc,DC_FALSE);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
169 dcCallVoid(pc, vtbl[VTBI_SET_BOOL] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
175
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176 /* set/get int */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
179 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
180 dcArgInt(pc,1234);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181 dcCallVoid(pc, vtbl[VTBI_SET_INT] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
182 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
187
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
188 /* set/get long */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
189
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
190 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192 dcArgLong(pc,0xCAFEBABEUL);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
193 dcCallVoid(pc, vtbl[VTBI_SET_LONG] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
194 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
199
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
200 /* set/get long long */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
201
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
202 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
203 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
204 dcArgLongLong(pc,0xCAFEBABEDEADC0DELL);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
205 dcCallVoid(pc, vtbl[VTBI_SET_LONG_LONG] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
206 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
211
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
212 /* set/get float */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
213
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
214 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
215 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
216 dcArgFloat(pc,1.2345f);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
217 dcCallVoid(pc, vtbl[VTBI_SET_FLOAT] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
218 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
223
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
224 /* set/get double */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
225
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
226 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
227 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
228 dcArgDouble(pc,1.23456789);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
229 dcCallVoid(pc, vtbl[VTBI_SET_DOUBLE] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
230 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
235
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
236 /* set/get pointer */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
237
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
238 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
239 dcArgPointer(pc, pThis);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
240 dcArgPointer(pc, (DCpointer) 0xCAFEBABE );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
241 dcCallVoid(pc, vtbl[VTBI_SET_POINTER] );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
242 dcReset(pc);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
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);
585
5a46d46b318b - fixed wrong mode setting in test (ellipse mode needs to be set after this ptr for thiscalls)
Tassilo Philipp
parents: 563
diff changeset
251 dcArgPointer(pc, pThis);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
252 dcMode(pc, DC_CALL_C_ELLIPSIS);
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
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
263 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
264
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
265
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
266 template<class T>
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
267 static bool testCallThis(DCint mode, const char* str)
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
268 {
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
269 bool r = false;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
270 DCCallVM* pc = dcNewCallVM(4096);
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
271 dcMode(pc, mode);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
272 dcReset(pc);
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
273 if(setjmp(jbuf) != 0)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
274 printf("sigsegv\n"), r=false;
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
275 else
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
276 r = testCallValue<T>(pc, str);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
277 dcFree(pc);
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
278 return r;
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
279 }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
280
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
281
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
282 #if defined(DC__Feature_AggrByVal)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
283
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
284 #define TEST_CLASS_AGGR(NAME, CCONV) \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
285 class NAME \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
286 { \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
287 public: \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
288 struct S { int i, j, k, l, m; }; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
289 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
290 virtual ~NAME() { } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
291 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
292 virtual void CCONV setAggr(S x) { mS.i = x.i; mS.j = x.j; mS.k = x.k; mS.l = x.l; mS.m = x.m; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
293 virtual S CCONV getAggr() { return mS; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
294 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
295 /* ellipsis test w/ this ptr and big (!) aggregate return */ \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
296 struct Big { int sum; long long dummy[50]; /*dummy to make it not fit in any regs*/ }; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
297 virtual struct Big CCONV 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; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
298 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
299 /* non-trivial aggregate */ \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
300 struct NonTriv { \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
301 int i, j; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
302 NonTriv(int a, int b) : i(a),j(b) { } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
303 NonTriv(const NonTriv& rhs) { static int a=13, b=37; i = a++; j = b++; } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
304 }; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
305 /* 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 */ \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
306 /* NOTE: copy of return value is subject to C++ "copy elision", so it is *not* calling the copy ctor for the return value */ \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
307 virtual struct NonTriv CCONV squareFields(NonTriv a, NonTriv b) { return NonTriv(a.i*b.i, a.j*b.j); } \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
308 \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
309 private: \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
310 struct S mS; \
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
311 };
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
312
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
313 TEST_CLASS_AGGR(ValueAggrThisDef, /*empty/default*/) /* default */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
314 #if defined(DC__Arch_Intel_x86)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
315 TEST_CLASS_AGGR(ValueAggrThisCdecl, __cdecl) /* methods explicitly declared as cdecl */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
316 #if defined(DC__OS_Win32) && defined(DC__C_MSVC)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
317 TEST_CLASS_AGGR(ValueAggrThisMS, /*empty/default*/) /* microsoft this call */
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
318 #endif
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
319 #endif
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
320
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
321
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
322 #if (__cplusplus >= 201103L)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
323 # include <type_traits>
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
324 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
325
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
326 /* special case w/ e.g. MS x64 C++ calling cconf: struct return ptr is passed as *2nd* arg */
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
327 template<class T>
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
328 static bool testCallThisAggr(DCint mode, const char* str)
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
329 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
330 bool r = false;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
331 DCCallVM* pc = dcNewCallVM(4096);
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
332 dcMode(pc, mode);
533
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 if(setjmp(jbuf) != 0)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
335 printf("sigsegv\n"), r=false;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
336 else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
337 {
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
338 T o;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
339
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
340 DCpointer* vtbl = *( (DCpointer**) &o ); /* vtbl is located at beginning of class */
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
341 typename T::S st = { 124, -12, 434, 20202, -99999 }, returned;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
342
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
343 #if (__cplusplus >= 201103L)
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
344 bool istriv = std::is_trivial<typename T::S>::value;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
345 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
346 bool istriv = true; /* own deduction as no type trait */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
347 #endif
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
348 DCaggr *s = dcNewAggr(5, sizeof(typename T::S));
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
349 dcAggrField(s, DC_SIGCHAR_INT, offsetof(typename T::S, i), 1);
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
350 dcAggrField(s, DC_SIGCHAR_INT, offsetof(typename T::S, j), 1);
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
351 dcAggrField(s, DC_SIGCHAR_INT, offsetof(typename T::S, k), 1);
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
352 dcAggrField(s, DC_SIGCHAR_INT, offsetof(typename T::S, l), 1);
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
353 dcAggrField(s, DC_SIGCHAR_INT, offsetof(typename T::S, m), 1);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
354 dcCloseAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
355
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
356 // set S::mS
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
357 dcReset(pc);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
358 dcArgPointer(pc, &o); // this ptr
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
359 dcArgAggr(pc, s, &st);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
360 dcCallVoid(pc, vtbl[VTBI_BASE+0]);
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 // get it back
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
363 dcReset(pc);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
364 dcBeginCallAggr(pc, s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
365 dcArgPointer(pc, &o); // this ptr
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
366 dcCallAggr(pc, vtbl[VTBI_BASE+1], s, &returned);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
367
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
368 dcFreeAggr(s);
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 r = returned.i == st.i && returned.j == st.j && returned.k == st.k && returned.l == st.l && returned.m == st.m && istriv;
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
371 printf("r:{iiiii} (%s/trivial): %d\n", str, r);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
372
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
373
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 /* 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
376 * 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
377 * 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
378 * 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
379 * 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
380 * passed *after* return aggregate's hidden ptr) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
381 #if (__cplusplus >= 201103L)
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
382 istriv = std::is_trivial<typename T::Big>::value;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
383 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
384 istriv = true; /* own deduction as no type trait */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
385 #endif
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
386 s = dcNewAggr(2, sizeof(struct T::Big));
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
387 dcAggrField(s, DC_SIGCHAR_INT, offsetof(struct T::Big, sum), 1);
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
388 dcAggrField(s, DC_SIGCHAR_LONGLONG, offsetof(struct T::Big, dummy), 50);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
389 dcCloseAggr(s);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
390 dcReset(pc);
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
391 dcMode(pc, mode);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
392
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
393 dcBeginCallAggr(pc, s);
539
0c3f5355769d - test code: dcmode setting order fix, test worked but was incorrect according to the definition/doc
Tassilo Philipp
parents: 533
diff changeset
394 dcArgPointer(pc, &o);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
395 dcMode(pc, DC_CALL_C_ELLIPSIS);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
396 dcArgInt(pc, 89);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
397 dcMode(pc, DC_CALL_C_ELLIPSIS_VARARGS);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
398 dcArgInt(pc, -157);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
399 dcArgInt(pc, 888);
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
400 struct T::Big big;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
401 dcCallAggr(pc, vtbl[VTBI_BASE+2], s, &big);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
402
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
403 dcFreeAggr(s);
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 bool b = (big.sum == 820) && istriv;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
406 r = r && b;
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
407 printf("r:{il[50]} (%s/trivial/ellipsis): %d\n", str, b);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
408
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
409
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
410
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
411 /* non-trivial test ----------------------------------------------------------- */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
412
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
413 #if (__cplusplus >= 201103L)
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
414 istriv = std::is_trivial<typename T::NonTriv>::value;
533
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 = false; /* 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 dcReset(pc);
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
419 dcMode(pc, mode);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
420
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
421 /* 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
422 dcBeginCallAggr(pc, NULL);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
423
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
424 typename T::NonTriv nt0(5, 6), nt1(7, 8), ntr(0, 0);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
425 dcArgAggr(pc, NULL, &o); // this ptr
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
426 /* make *own* copies, as dyncall cannot know how to call copy ctor */ //@@@ put into doc
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
427 typename T::NonTriv nt0_ = nt0, nt1_ = nt1;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
428 dcArgAggr(pc, NULL, &nt0_); /* use *own* copy */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
429 dcArgAggr(pc, NULL, &nt1_); /* use *own* copy */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
430
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
431 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
432
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
433
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
434 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
435 r = r && b;
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
436 printf("r:{ii} (%s/nontrivial/retval_copy_elision): %d\n", str, b);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
437 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
438
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
439 dcFree(pc);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
440 return r;
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 #endif
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
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
446 extern "C" {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
447
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
448 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
449 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
450 dcTest_initPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
451
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
452 signal(SIGSEGV, segv_handler);
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
453
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
454 bool r = true;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
455
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
456 r = testCallThis<ValueThisDef>(DC_CALL_C_DEFAULT_THIS, "thisDef") && r;
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
457 #if defined(DC__Arch_Intel_x86)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
458 r = testCallThis<ValueThisCdecl>(DC_CALL_C_X86_CDECL, "thisCdecl") && r;
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
459 #if defined(DC__OS_Win32) && defined(DC__C_MSVC)
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
460 r = testCallThis<ValueThisMS>(DC_CALL_C_X86_WIN32_THIS_MS, "thisMS") && r;
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
461 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
462 #endif
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
463
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
464 #if defined(DC__Feature_AggrByVal)
611
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
465 r = testCallThisAggr<ValueAggrThisDef>(DC_CALL_C_DEFAULT_THIS, "thisDef") && r;
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
466 #if defined(DC__Arch_Intel_x86)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
467 r = testCallThisAggr<ValueAggrThisCdecl>(DC_CALL_C_X86_CDECL, "thisCdecl") && r;
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
468 #if defined(DC__OS_Win32) && defined(DC__C_MSVC)
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
469 r = testCallThisAggr<ValueAggrThisMS>(DC_CALL_C_X86_WIN32_THIS_MS, "thisMS") && r;
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
470 #endif
d94b053311a7 test/plain_c++:
Tassilo Philipp
parents: 586
diff changeset
471 #endif
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 466
diff changeset
472 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
473
563
fcb9d00b5a00 - minor test case output change for consistency
Tassilo Philipp
parents: 557
diff changeset
474 printf("result: plain_c++: %d\n", r);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
475
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
476 dcTest_deInitPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
477
324
dd78bd0152af - removal of never-adopted mini-test framework stub
Tassilo Philipp
parents: 281
diff changeset
478 return !r;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
479 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
480
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
481 } // extern "C"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
482