Jump through some hoops to make the Windows SEH exception stuff happy
authorIan Lynagh <igloo@earth.li>
Fri, 24 Aug 2007 22:23:17 +0000 (22:23 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 24 Aug 2007 22:23:17 +0000 (22:23 +0000)
rts/Main.c
rts/Makefile
rts/win32/seh_excn.c [moved from rts/seh_excn.c with 100% similarity]
rts/win32/seh_excn.h [moved from rts/seh_excn.h with 97% similarity]

index 5f16fa3..434f791 100644 (file)
@@ -16,7 +16,9 @@
 #include "RtsUtils.h"
 #include "Prelude.h"
 #include "Task.h"
-#include "seh_excn.h"
+#if defined(mingw32_HOST_OS)
+#include "win32/seh_excn.h"
+#endif
 #include <stdlib.h>
 
 #ifdef DEBUG
 
 extern void __stginit_ZCMain(void);
 
+static int progargc;
+static char **progargv;
+
 /* Hack: we assume that we're building a batch-mode system unless 
  * INTERPRETER is set
  */
 #ifndef INTERPRETER /* Hack */
-int main(int argc, char *argv[])
+static void real_main(void)
 {
     int exit_status;
     SchedulerStatus status;
     /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */
 
-    BEGIN_CATCH
-    startupHaskell(argc,argv,__stginit_ZCMain);
+    startupHaskell(progargc,progargv,__stginit_ZCMain);
 
     /* kick off the computation by creating the main thread with a pointer
        to mainIO_closure representing the computation of the overall program;
@@ -135,8 +139,21 @@ int main(int argc, char *argv[])
       barf("main thread completed with invalid status");
     }
     shutdownHaskellAndExit(exit_status);
+}
+int main(int argc, char *argv[])
+{
+    /* We do this dance with argc and argv as otherwise the SEH exception
+       stuff (the BEGIN/END CATCH below) on Windows gets confused */
+    progargc = argc;
+    progargv = argv;
+
+#if defined(mingw32_HOST_OS)
+    BEGIN_CATCH
+#endif
+    real_main();
+#if defined(mingw32_HOST_OS)
     END_CATCH
-    return 0; /* not reached unless a Windows exception happens,
-                 also keeps gcc -Wall happy */
+#endif
+    return 0; /* not reached, but keeps gcc -Wall happy */
 }
 # endif /* BATCH_MODE */
index 9af9671..7fab5fa 100644 (file)
@@ -156,6 +156,12 @@ else
 DQ = \"
 endif
 
+# If Main.c is built with optimisation then the SEH exception stuff on
+# Windows gets confused.
+# This has to be in HC rather than CC opts, as otherwise there's a
+# -optc-O2 that comes after it.
+Main_HC_OPTS += -optc-O0
+
 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
 RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
similarity index 100%
rename from rts/seh_excn.c
rename to rts/win32/seh_excn.c
similarity index 97%
rename from rts/seh_excn.h
rename to rts/win32/seh_excn.h
index 311675d..410d430 100644 (file)
@@ -84,8 +84,7 @@ catchDivZero(struct _EXCEPTION_RECORD*,
    } \
   }
 #else
-#define BEGIN_CATCH /* nothing */
-#define END_CATCH   /* nothing */
+#error Don't know what sort of Windows system this is
 #endif
 
 #endif /* __SEH_EXCN_H__ */