comparison test/call_suite_aggrs/main.c @ 592:f29db2bf3c0e

- added exception handling to test/call{,back}_suite_aggrs - test/callback_suite_aggrs: added missing memory cleanup
author Tassilo Philipp
date Mon, 19 Sep 2022 18:11:08 +0200
parents ed8835abe05f
children 806e415df417
comparison
equal deleted inserted replaced
591:1d6e51b1d4c7 592:f29db2bf3c0e
23 */ 23 */
24 24
25 #include "dyncall.h" 25 #include "dyncall.h"
26 #include "globals.h" 26 #include "globals.h"
27 #include <string.h> 27 #include <string.h>
28 #include <signal.h>
29 #include <setjmp.h>
28 #include "../common/platformInit.h" 30 #include "../common/platformInit.h"
29 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ 31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
30 32
31 33
32 static void* G_callvm; 34 static void* G_callvm;
223 failure |= !( run_test(i) ); 225 failure |= !( run_test(i) );
224 226
225 return !failure; 227 return !failure;
226 } 228 }
227 229
230
231 jmp_buf jbuf;
232 void segv_handler(int sig)
233 {
234 longjmp(jbuf, 1);
235 }
236
237
228 int main(int argc, char* argv[]) 238 int main(int argc, char* argv[])
229 { 239 {
230 int total, i; 240 int r = 0, i;
241
242 signal(SIGSEGV, segv_handler);
243 #if !defined(DC_WINDOWS)
244 signal(SIGBUS, segv_handler);
245 #endif
231 246
232 dcTest_initPlatform(); 247 dcTest_initPlatform();
233 248
234 init_test_data(G_maxargs); 249 init_test_data(G_maxargs);
235 G_callvm = (DCCallVM*) dcNewCallVM(32768); 250 G_callvm = (DCCallVM*) dcNewCallVM(32768);
236 251
237 dcReset(G_callvm); 252 dcReset(G_callvm);
238 total = run_all(); 253 if(setjmp(jbuf) == 0)
239 254 r = run_all();
240 /* free all DCaggrs created on the fly */ 255
241 for(i=0; i<G_naggs; ++i) 256 /* free all DCaggrs created on the fly (backwards b/c they are interdependency-ordered */
257 for(i=G_naggs-1; i>=0; --i)
242 dcFreeAggr(((DCaggr*(*)())G_agg_touchAfuncs[i])()); 258 dcFreeAggr(((DCaggr*(*)())G_agg_touchAfuncs[i])());
243 259
244 dcFree(G_callvm); 260 dcFree(G_callvm);
245 deinit_test_data(G_maxargs); 261 deinit_test_data(G_maxargs);
246 262
247 printf("result: call_suite_aggrs: %d\n", total); 263 printf("result: call_suite_aggrs: %d\n", r);
248 264
249 dcTest_deInitPlatform(); 265 dcTest_deInitPlatform();
250 266
251 return !total; 267 return !r;
252 } 268 }
253 269