Mercurial > pub > dyncall > dyncall
annotate test/call_suite_aggrs/globals.c @ 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 | f29db2bf3c0e |
children |
rev | line source |
---|---|
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
1 /* |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
2 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
3 Package: dyncall |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
4 Library: test |
485
0c68b3f91367
- renamed suite_aggrs to call_suite_aggrs for consistency (callback version will be called callback_suite_aggrs)
Tassilo Philipp
parents:
482
diff
changeset
|
5 File: test/call_suite_aggrs/globals.c |
592
f29db2bf3c0e
- added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents:
561
diff
changeset
|
6 Description: |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
7 License: |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
8 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
9 Copyright (c) 2022 Tassilo Philipp <tphilipp@potion-studios.com> |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
10 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
11 Permission to use, copy, modify, and distribute this software for any |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
12 purpose with or without fee is hereby granted, provided that the above |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
13 copyright notice and this permission notice appear in all copies. |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
14 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
22 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
23 */ |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
24 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
25 #include <stdlib.h> |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
26 #include "globals.h" |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
27 #include <float.h> |
459 | 28 #include <string.h> |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
29 |
592
f29db2bf3c0e
- added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents:
561
diff
changeset
|
30 #define X(CH,T) T *V_##CH; T *K_##CH; |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
31 DEF_TYPES |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
32 #undef X |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
33 |
561 | 34 /* intentional misalignment of test aggregates (use only positive numbers); |
35 * crashes/exceptions (e.g. sigbus on some platforms) when using values > 0 | |
36 * might reveal missing aggr-by-val copies in the implementation */ | |
37 #define AGGR_MISALIGN 1 /* @@@AGGR make configurable */ | |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
38 |
457
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
39 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); } |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
40 |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
41 /* fill mem with random values, make sure no float aligned memory location |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
42 * results in a NaN, as they always compare to false; so avaid all ones in |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
43 * exporent (for simplicity we just look at first 7 exponent bits and make sure |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
44 * they aren't all set, which would work for all IEEE754 precision formats) */ |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
45 static void rand_mem__fp_friendly(void* p, size_t s) |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
46 { |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
47 int i; |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
48 for(i = 0; i<s; ++i) { |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
49 char* c = (char*)p; |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
50 c[i] = (char)rand(); /* slowish, byte by byte, but whatev */ |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
51 if((c[i]&0x7f) == 0x7f) |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
52 c[i] ^= 1; |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
53 } |
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
54 } |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
55 |
458 | 56 int get_max_aggr_size() |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
57 { |
458 | 58 static int s = 0; |
59 int i; | |
60 if(s == 0) { | |
61 for(i=0; i<G_naggs; ++i) | |
62 if(G_agg_sizes[i] > s) | |
63 s = G_agg_sizes[i]; | |
64 } | |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
65 return s; |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
66 } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
67 |
438 | 68 void init_test_data() |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
69 { |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
70 int i; |
458 | 71 int maxaggrsize = get_max_aggr_size(); |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
72 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
73 DEF_TYPES |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
74 #undef X |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
75 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
76 for(i=0;i<G_maxargs+1;++i) { |
515 | 77 K_B[i] = (DCbool) ((int)rand_d() & 1); |
492 | 78 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7)); |
79 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1))); | |
80 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2))); | |
81 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2))); | |
82 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); | |
83 K_C[i] = (unsigned char) (((rand_d()-0.5)*2) * (1<<7)); | |
84 K_S[i] = (unsigned short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1))); | |
85 K_I[i] = (unsigned int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2))); | |
86 K_J[i] = (unsigned long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2))); | |
87 K_L[i] = (unsigned long long)(((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); | |
88 K_p[i] = (void*)(long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1))); | |
89 K_f[i] = (float) (rand_d() * FLT_MAX); | |
90 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX); | |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
91 K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); |
457
90b1d927912a
- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents:
450
diff
changeset
|
92 rand_mem__fp_friendly(K_a[i], maxaggrsize+AGGR_MISALIGN); |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
93 K_a[i] = (char*)K_a[i]+AGGR_MISALIGN; |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
94 } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
95 } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
96 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
97 void clear_V() |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
98 { |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
99 static int aggr_init = 0; |
458 | 100 int maxaggrsize = get_max_aggr_size(); |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
101 |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
102 int i; |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
103 for(i=0;i<G_maxargs+1;++i) { |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
104 if(aggr_init) |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
105 free((char*)V_a[i]-AGGR_MISALIGN); |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
106 #define X(CH,T) V_##CH[i] = (T) 0; |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
107 DEF_TYPES |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
108 #undef X |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
109 V_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); |
458 | 110 memset(V_a[i], 0, maxaggrsize+AGGR_MISALIGN); |
439
252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents:
438
diff
changeset
|
111 V_a[i] = (char*)V_a[i]+AGGR_MISALIGN; |
432
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
112 } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
113 aggr_init = 1; |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
114 } |
167faab0c0be
first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff
changeset
|
115 |
438 | 116 void deinit_test_data() |
117 { | |
118 int i; | |
119 for(i=0;i<G_maxargs+1;++i) { | |
592
f29db2bf3c0e
- added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents:
561
diff
changeset
|
120 if(V_a[i]) free((char*)V_a[i]-AGGR_MISALIGN); |
f29db2bf3c0e
- added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents:
561
diff
changeset
|
121 if(K_a[i]) free((char*)K_a[i]-AGGR_MISALIGN); |
438 | 122 } |
123 | |
124 #define X(CH,T) free(V_##CH); free(K_##CH); | |
125 DEF_TYPES | |
126 #undef X | |
127 } | |
128 |