Mercurial > pub > dyncall > dyncall
changeset 439:252f32fa59d8
- suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
author | Tassilo Philipp |
---|---|
date | Wed, 26 Jan 2022 13:56:40 +0100 |
parents | b4ddad459690 |
children | e4ae6753a276 |
files | test/suite_aggrs/README.txt test/suite_aggrs/globals.c |
diffstat | 2 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/test/suite_aggrs/README.txt Wed Jan 26 13:37:19 2022 +0100 +++ b/test/suite_aggrs/README.txt Wed Jan 26 13:56:40 2022 +0100 @@ -1,6 +1,10 @@ suite_aggrs for dyncall written in C and Lua. -Tests aggregates (structs, unions and arrays) passed by value, along with other, non-aggregate args. +Tests aggregates (structs, unions and arrays) passed by value, along with +other, non-aggregate args. + +A macro AGGR_MISALIGN can be used in globals.c to intentionally misalign +aggregate instances. @@@ unions and arrays missing
--- a/test/suite_aggrs/globals.c Wed Jan 26 13:37:19 2022 +0100 +++ b/test/suite_aggrs/globals.c Wed Jan 26 13:56:40 2022 +0100 @@ -30,8 +30,10 @@ DEF_TYPES #undef X +#define AGGR_MISALIGN 0 + static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); } -static void rand_mem(void* p, size_t s) { for(int i=0; i<s; ++i) ((char*)p)[i] = (char)rand(); } +static void rand_mem(void* p, size_t s) { for(int i=0; i<s; ++i) ((char*)p)[i] = (char)rand(); } /* byte by byte is slow, but whatev */ static int calc_max_aggr_size() { @@ -59,7 +61,9 @@ K_p[i] = (void*) (long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1))); K_f[i] = (float) (rand_d() * FLT_MAX); K_d[i] = (double) (((rand_d()-0.5)*2) * 1.7976931348623157E+308/*__DBL_MAX__*/); /* Plan9 doesn't know the macro. */ - K_a[i] = malloc(maxaggrsize); rand_mem(K_a[i], maxaggrsize); + K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); + rand_mem(K_a[i], maxaggrsize+AGGR_MISALIGN); + K_a[i] = (char*)K_a[i]+AGGR_MISALIGN; } } @@ -71,11 +75,12 @@ int i; for(i=0;i<G_maxargs+1;++i) { if(aggr_init) - free(V_a[i]); + free((char*)V_a[i]-AGGR_MISALIGN); #define X(CH,T) V_##CH[i] = (T) 0; DEF_TYPES #undef X - V_a[i] = malloc(maxaggrsize); + V_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); + V_a[i] = (char*)V_a[i]+AGGR_MISALIGN; } aggr_init = 1; } @@ -84,8 +89,8 @@ { int i; for(i=0;i<G_maxargs+1;++i) { - free(V_a[i]); - free(K_a[i]); + free((char*)V_a[i]-AGGR_MISALIGN); + free((char*)K_a[i]-AGGR_MISALIGN); } #define X(CH,T) free(V_##CH); free(K_##CH);