[m-rev.] for review: set runtime flags at compile time

Simon Taylor stayl at cs.mu.OZ.AU
Sun Jan 13 20:46:04 AEDT 2002


On 12-Jan-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> On 12-Jan-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> >  		strcpy(dummy_command_line, cmd);
> > -		strcat(dummy_command_line, options);
> > +		/*
> > +		** mkinit always puts a trailing space on MR_runtime_flags
> > +		** if it is non-empty.
> > +		*/
> > +		strcat(dummy_command_line, MR_runtime_flags);
> > +		strcat(dummy_command_line, env_options);
> 
> However, mkinit won't put a space at the *start* of MR_runtime_flags.
> You should document that cmd also has a space at its end.

On reflection, that code is a bug waiting to happen.
I'll commit with the following change to mercury_wrapper.c.

Simon.

Index: mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.94
diff -u -u -r1.94 mercury_wrapper.c
--- mercury_wrapper.c	31 Dec 2001 04:26:54 -0000	1.94
+++ mercury_wrapper.c	13 Jan 2002 08:03:21 -0000
@@ -209,6 +209,8 @@
 		/* normally mercury__main_2_0 (main/2) */
 #endif
 
+const char *MR_runtime_flags = "";
+
 void	(*MR_library_initializer)(void);
 		/* normally ML_io_init_state (io__init_state/2)*/
 void	(*MR_library_finalizer)(void);
@@ -665,15 +667,21 @@
 static void
 process_environment_options(void)
 {
-	char*	options;
+	char*	env_options;
+
+	env_options = getenv("MERCURY_OPTIONS");
+	if (env_options == NULL) {
+		env_options = (char *) "";
+	}
 
-	options = getenv("MERCURY_OPTIONS");
-	if (options != NULL) {
+	if (env_options[0] != '\0' || MR_runtime_flags[0] != '\0') {
 		const char	*cmd;
 		char		*arg_str, **argv;
 		char		*dummy_command_line;
 		const char	*error_msg;
 		int		argc;
+		int		cmd_len;
+		int		runtime_flags_len;
 
 		/*
 		** getopt() expects the options to start in argv[1],
@@ -683,10 +691,16 @@
 		** to getopt().
 		*/
 		cmd = "mercury_runtime ";
+		cmd_len = strlen(cmd);
+		runtime_flags_len = strlen(MR_runtime_flags);
 		dummy_command_line = MR_GC_NEW_ARRAY(char,
-					strlen(options) + strlen(cmd) + 1);
+					cmd_len + runtime_flags_len + 1 +
+					strlen(env_options) + 1);
 		strcpy(dummy_command_line, cmd);
-		strcat(dummy_command_line, options);
+		strcpy(dummy_command_line + cmd_len, MR_runtime_flags);
+		dummy_command_line[cmd_len + runtime_flags_len] = ' ';
+		strcpy(dummy_command_line + cmd_len + runtime_flags_len + 1,
+				env_options);
 		
 		error_msg = MR_make_argv(dummy_command_line,
 			&arg_str, &argv, &argc);

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list