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

Simon Taylor stayl at cs.mu.OZ.AU
Wed Jan 23 04:28:43 AEDT 2002


On 21-Jan-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 12-Jan-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 
> > Allow Mercury runtime options to be set at compile time.
> ...
> > --- util/mkinit.c	18 Dec 2001 05:44:13 -0000	1.80
> ...
> > +	printf("	MR_runtime_flags = \"");
> > +	for (list_tmp = runtime_flags;
> > +			list_tmp != NULL; list_tmp = list_tmp->next) {
> > +		fputs(list_tmp->data, stdout);
> 
> Using fputs() here is wrong.  Any special characters --
> in particular '\"', '\\' and '\n' -- need to be quoted.
> 
> This may be particularly important in this case of run-time options
> which are file names when using DOS/Windows, since they are quite
> likely to include \\.

Estimated hours taken: 0.25

util/mkinit.c:
	Quote special characters occurring in the value of
	MR_runtime_flags written to the `_init.c' file.

tests/hard_coded/Mmakefile:
	Test case.

Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.81
diff -u -u -r1.81 mkinit.c
--- util/mkinit.c	13 Jan 2002 10:13:20 -0000	1.81
+++ util/mkinit.c	22 Jan 2002 17:04:20 -0000
@@ -789,6 +789,7 @@
 {
 	const char *aditi_load_func;
 	String_List *list_tmp;
+	char *options_str;
 
 	if (aditi) {
 		aditi_load_func = "MR_do_load_aditi_rl_code";
@@ -802,7 +803,22 @@
 	printf("	MR_runtime_flags = \"");
 	for (list_tmp = runtime_flags;
 			list_tmp != NULL; list_tmp = list_tmp->next) {
-		fputs(list_tmp->data, stdout);
+		for (options_str = list_tmp->data;
+				*options_str != '\0'; options_str++) {
+			if (*options_str == '\n') {
+				putchar('\\');
+				putchar('n');
+			} else if (*options_str == '\t') {
+				putchar('\\');
+				putchar('t');
+			} else if (*options_str == '"' ||
+					*options_str == '\\') {
+				putchar('\\');
+				putchar(*options_str);
+			} else {
+				putchar(*options_str);
+			}
+		}
 		putchar(' ');
 	}
 	printf("\";\n");
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.141
diff -u -u -r1.141 Mmakefile
--- tests/hard_coded/Mmakefile	13 Jan 2002 10:13:16 -0000	1.141
+++ tests/hard_coded/Mmakefile	22 Jan 2002 17:07:49 -0000
@@ -274,7 +274,11 @@
 # unless we increase the heap size from the default 4M.
 # The sizes specified here (70 Mb and 20 Mb respectively)
 # are sufficient for running these tests on 64-bit systems.
-MLFLAGS-integer_test = --runtime-flags "--heap-size 70000"
+# The setting of `--mdb-out' tests the quoting of runtime
+# options containing special characters.
+
+MLFLAGS-integer_test = \
+		--runtime-flags "--heap-size 70000 --mdb-out \"mdb\\mdb out\""
 MLFLAGS-rational_test = --runtime-flags "--heap-size 20000"
 
 # no_fully_strict is expected to fail (it calls error/1).
--------------------------------------------------------------------------
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