diff 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
line wrap: on
line diff
--- a/test/call_suite_aggrs/main.c	Mon Sep 19 16:59:52 2022 +0200
+++ b/test/call_suite_aggrs/main.c	Mon Sep 19 18:11:08 2022 +0200
@@ -25,6 +25,8 @@
 #include "dyncall.h"
 #include "globals.h"
 #include <string.h>
+#include <signal.h>
+#include <setjmp.h>
 #include "../common/platformInit.h"
 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
 
@@ -225,9 +227,22 @@
   return !failure;
 }
 
+
+jmp_buf jbuf;
+void segv_handler(int sig)
+{
+  longjmp(jbuf, 1);
+}
+
+
 int main(int argc, char* argv[])
 {
-  int total, i;
+  int r = 0, i;
+
+  signal(SIGSEGV, segv_handler);
+#if !defined(DC_WINDOWS)
+  signal(SIGBUS,  segv_handler);
+#endif
 
   dcTest_initPlatform();
 
@@ -235,19 +250,20 @@
   G_callvm = (DCCallVM*) dcNewCallVM(32768);
 
   dcReset(G_callvm);
-  total = run_all();
+  if(setjmp(jbuf) == 0)
+    r = run_all();
 
-  /* free all DCaggrs created on the fly */
-  for(i=0; i<G_naggs; ++i)
+  /* free all DCaggrs created on the fly (backwards b/c they are interdependency-ordered */
+  for(i=G_naggs-1; i>=0; --i)
     dcFreeAggr(((DCaggr*(*)())G_agg_touchAfuncs[i])());
 
   dcFree(G_callvm);
   deinit_test_data(G_maxargs);
 
-  printf("result: call_suite_aggrs: %d\n", total);
+  printf("result: call_suite_aggrs: %d\n", r);
 
   dcTest_deInitPlatform();
 
-  return !total;
+  return !r;
 }