[project @ 2001-10-01 11:36:28 by simonmar]
authorsimonmar <unknown>
Mon, 1 Oct 2001 11:36:29 +0000 (11:36 +0000)
committersimonmar <unknown>
Mon, 1 Oct 2001 11:36:29 +0000 (11:36 +0000)
Allow default RTS options to be specified by linking in an object file
which defines the symbol `ghc_rts_opts' to point to a string of RTS
options.

This is preferred to using defaultsHook(), if possible.  Perhaps we
could remove defaultsHook().

(won't work with DLL's; if we ever ressurrect them we'll
have to deal with this somehow).

ghc/includes/Hooks.h
ghc/rts/RtsFlags.c
ghc/rts/hooks/RtsOpts.c [new file with mode: 0644]

index 8db74f7..d172bc7 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Hooks.h,v 1.5 2001/04/01 05:56:29 chak Exp $
+ * $Id: Hooks.h,v 1.6 2001/10/01 11:36:28 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -7,6 +7,8 @@
  *
  * ---------------------------------------------------------------------------*/
 
+extern char *ghc_rts_opts;
+
 extern void OnExitHook (void);
 extern void ErrorHdrHook (long fd);
 extern int  NoRunnableThreadsHook (void);
index a95d443..d070c13 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.50 2001/08/31 11:42:44 sewardj Exp $
+ * $Id: RtsFlags.c,v 1.51 2001/10/01 11:36:28 simonmar Exp $
  *
  * (c) The AQUA Project, Glasgow University, 1994-1997
  * (c) The GHC Team, 1998-1999
@@ -485,6 +485,32 @@ strequal(const char *a, const char * b)
     return(strcmp(a, b) == 0);
 }
 
+static void
+splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
+{
+    char *c1, *c2;
+
+    c1 = s;
+    do {
+       while (isspace(*c1)) { c1++; };
+       c2 = c1;
+       while (!isspace(*c2) && *c2 != '\0') { c2++; };
+       
+       if (c1 == c2) { break; }
+       
+       if (*rts_argc < MAX_RTS_ARGS-1) {
+           s = malloc(c2-c1+1);
+           strncpy(s, c1, c2-c1);
+           s[c2-c1] = '\0';
+           rts_argv[(*rts_argc)++] = s;
+       } else {
+           barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
+       }
+       
+       c1 = c2;
+    } while (*c1 != '\0');
+}
+    
 void
 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
 {
@@ -504,32 +530,22 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
     *argc = 1;
     *rts_argc = 0;
 
+    // process arguments from the ghc_rts_opts global variable first.
+    // (arguments from the GHCRTS environment variable and the command
+    // line override these).
+    {
+       if (ghc_rts_opts != NULL) {
+           splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
+       }
+    }
+
     // process arguments from the GHCRTS environment variable first
     // (arguments from the command line override these).
     {
        char *ghc_rts = getenv("GHCRTS");
-       char *c1, *c2, *s;
 
        if (ghc_rts != NULL) {
-           c1 = ghc_rts;
-           do {
-               while (isspace(*c1)) { c1++; };
-               c2 = c1;
-               while (!isspace(*c2) && *c2 != '\0') { c2++; };
-
-               if (c1 == c2) { break; }
-
-               if (*rts_argc < MAX_RTS_ARGS-1) {
-                   s = malloc(c2-c1+1);
-                   strncpy(s, c1, c2-c1);
-                   s[c2-c1] = '\0';
-                   rts_argv[(*rts_argc)++] = s;
-               } else {
-                   barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
-               }
-
-               c1 = c2;
-           } while (*c1 != '\0');
+           splitRtsFlags(ghc_rts, rts_argc, rts_argv);
        }
     }
 
diff --git a/ghc/rts/hooks/RtsOpts.c b/ghc/rts/hooks/RtsOpts.c
new file mode 100644 (file)
index 0000000..dec0075
--- /dev/null
@@ -0,0 +1,12 @@
+/* -----------------------------------------------------------------------------
+ * $Id: RtsOpts.c,v 1.1 2001/10/01 11:36:29 simonmar Exp $
+ *
+ * Default RTS options.
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "Rts.h"
+
+// Default RTS options can be given by providing an alternate
+// definition for this variable, pointing to a string of RTS options.
+char *ghc_rts_opts = NULL;