for review: fixing bart's complaints about MERCURY_OPTIONS
Zoltan Somogyi
zs at cs.mu.OZ.AU
Sun Aug 9 17:21:52 AEST 1998
I am referring to this mail.
> Received: from beddoe.cs.monash.edu.au (beddoe.cs.monash.edu.au [130.194.67.171]) by mulga.cs.mu.OZ.AU with ESMTP
> id MAA22933 for <mercury-bugs at cs.mu.oz.au>; Wed, 5 Aug 1998 12:09:58 +1000 (EST)
> Received: (from bartd at localhost)
> by beddoe.cs.monash.edu.au (8.8.8/8.8.8) id MAA12484;
> Wed, 5 Aug 1998 12:09:57 +1000 (EST)
> Date: Wed, 5 Aug 1998 12:09:57 +1000 (EST)
> Message-Id: <199808050209.MAA12484 at beddoe.cs.monash.edu.au>
> From: Bart Demoen <bartd at cs.monash.edu.au>
> To: mercury-bugs at cs.mu.OZ.AU
> Subject: a complaint about MERCURY_OPTIONS
>
>
> the Mercury doc gives the impression that changing the size of the
> heap can be done by
>
> setenv MERCURY_OPTIONS '-s h 1000'
>
> but this doesn't work because there shouldn't be a space between
> h and 100
>
> giving the about setenv command results in an error message when an
> already compiled program is run:
>
> The MERCURY_OPTIONS environment variable contains an invalid option.
> Please refer to the Environment Variables section of the Mercury
> user's guide for details.
>
> and that is fair enough, except that I tried to correct my setenv as follows:
>
> setenv MERCURY_OPTIONS 's h 1000'
>
> (I left out the -)
>
> then my application ran without complaining, so I thought everything
> was ok, until after some runs I realised that the heap size was not
> changed at all !
>
> I later found out that there is no error message for other random setenvs
> like setenv MERCURY_OPTIONS 'asd'
>
> anyway, the Mercury doc is misleading a bit when it says:
>
> -s area size
> Sets the size of one of the runtime system's memory areas. area must be one of `h'
> (standing for heap), `d' (standing for deterministic stack), `n' (standing for
> nondeterministic stack) and, in grades with trailing, `t' (standing for trail). size
> specifies the size of that area, in kilobytes.
>
> which suggests a space between area and size
>
> I found out that the space shouldn't be there by having a look in
> in mercury_wrapper.c:
>
> case 's':
> if (sscanf(optarg+1, "%lu", &size) != 1)
> ^^^^^^^^
>
> so I am complaining about two things here: misleading doc and
> missing error message
>
> cheers
>
> Bart
Bart, why don't you review this change.
Estimated hours taken: 5
Bring the handling of MERCURY_OPTION into the 90s (a bit late :-).
Get rid of lack-of-prototype warnings from getopt.h.
runtime/getopt.[ch]:
runtime/getopt1.c:
runtime/GETOPT:
runtime/GETOPT/getopt.[ch]:
runtime/GETOPT/getopt1.c:
Move these files to a new subdirectory, GETOPT. This should avoid
the nuisance warnings one gets when stdlib.h picks up the getopt.h
in the runtime directory by accident. (The GETOPT directory should
never need to be included in -I search paths.)
runtime/mercury_getopt.[ch]:
runtime/mercury_getopt1.c:
Copies of the files in GETOPT, slightly modified to make sure that
(1) every external symbol they define starts with MR_, and (2)
we get a minimal number of compilation errors (as of now, 3 warnings
about casting away const).
These files are not to be modified by humans.
runtime/process_getopt:
This is the script that creates mercury_getopt{.h,.c,1.c} from the
files in GETOPT.
runtime/mercury_wrapper.c:
Get rid of the -s<area><size> notation, which can hard to remember,
and replace it with long options such as --heap-size=1024.
Print an error message and stop if MERCURY_OPTIONS contains anything
other than options.
Refer to everything from mercury_getopt.h with a name that starts with
MR_.
runtime/Mmakefile:
Mention the new source files.
doc/user_guide.texi:
Document the new options.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.132
diff -u -u -r1.132 user_guide.texi
--- user_guide.texi 1998/08/04 14:06:03 1.132
+++ user_guide.texi 1998/08/09 09:01:56
@@ -2899,15 +2899,6 @@
@c Repeats execution of the entry point procedure @var{num} times,
@c to enable accurate timing.
- at sp 1
- at item -s @var{area} @var{size}
-Sets the size of one of the runtime system's memory areas.
- at var{area} must be one of @samp{h} (standing for heap),
- at samp{d} (standing for deterministic stack),
- at samp{n} (standing for nondeterministic stack)
-and, in grades with trailing, @samp{t} (standing for trail).
- at var{size} specifies the size of that area, in kilobytes.
-
@c @item -t
@c Tells the runtime system to measure the time taken by
@c the (required number of repetitions of) the program,
@@ -2937,11 +2928,38 @@
@c @item -x
@c Tells the Boehm collector not to perform any garbage collection.
+
+ at sp 1
+ at item --heap-size=@var{size}
+Sets the size of the heap to @var{size} kilobytes.
+
+ at sp 1
+ at item --detstack-size=@var{size}
+Sets the size of the det stack to @var{size} kilobytes.
+
+ at sp 1
+ at item --nondetstack-size=@var{size}
+Sets the size of the nondet stack to @var{size} kilobytes.
+
+ at sp 1
+ at item --trail-size=@var{size}
+Sets the size of the trail to @var{size} kilobytes.
- at c @item -z @var{area} @var{size}
- at c Sets the size of the redzone on one of the runtime system's memory areas.
- at c The @var{area} and @var{size} parameters have the same meaning
- at c as they do for the @samp{-s} option.
+ at c @sp 1
+ at c @item --heap-zone-size=@var{size}
+ at c Sets the size of the redzone on the heap to @var{size} kilobytes.
+
+ at c @sp 1
+ at c @item --detstack-zone-size=@var{size}
+ at c Sets the size of the redzone on the det stack to @var{size} kilobytes.
+
+ at c @sp 1
+ at c @item --nondetstack-zone-size=@var{size}
+ at c Sets the size of the redzone on the nondet stack to @var{size} kilobytes.
+
+ at c @sp 1
+ at c @item --trail-zone-size=@var{size}
+ at c Sets the size of the redzone on the trail to @var{size} kilobytes.
@end table
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/Togl-1.2
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.35
diff -u -u -r1.35 Mmakefile
--- Mmakefile 1998/08/04 09:12:12 1.35
+++ Mmakefile 1998/08/09 08:02:14
@@ -105,6 +105,8 @@
mercury_dummy.c \
mercury_engine.c \
mercury_float.c \
+ mercury_getopt.c \
+ mercury_getopt1.c \
mercury_grade.c \
mercury_heap_profile.c \
mercury_ho_call.c \
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.21
diff -u -u -r1.21 mercury_wrapper.c
--- mercury_wrapper.c 1998/08/07 00:50:34 1.21
+++ mercury_wrapper.c 1998/08/09 08:58:43
@@ -33,8 +33,8 @@
#include <stdio.h>
#include <string.h>
-#include "mercury_timing.h"
#include "mercury_getopt.h"
+#include "mercury_timing.h"
#include "mercury_init.h"
#include "mercury_dummy.h"
#include "mercury_trace.h"
@@ -46,34 +46,33 @@
/* size of data areas (including redzones), in kilobytes */
/* (but we later multiply by 1024 to convert to bytes) */
#ifdef MR_DEBUG_AGC
- size_t heap_size = 128;
+ size_t heap_size = 128;
#else
- size_t heap_size = 4096;
+ size_t heap_size = 4096;
#endif
-size_t detstack_size = 2048;
-size_t nondstack_size = 128;
-size_t solutions_heap_size = 1024;
-size_t global_heap_size = 1024;
-size_t trail_size = 128;
-size_t debug_heap_size = 4096;
+size_t detstack_size = 2048;
+size_t nondstack_size = 128;
+size_t solutions_heap_size = 1024;
+size_t global_heap_size = 1024;
+size_t trail_size = 128;
+size_t debug_heap_size = 4096;
/* size of the redzones at the end of data areas, in kilobytes */
/* (but we later multiply by 1024 to convert to bytes) */
#ifdef NATIVE_GC
- size_t heap_zone_size = 96;
+ size_t heap_zone_size = 96;
#else
- size_t heap_zone_size = 16;
+ size_t heap_zone_size = 16;
#endif
-size_t detstack_zone_size = 16;
-size_t nondstack_zone_size = 16;
+size_t detstack_zone_size = 16;
+size_t nondstack_zone_size = 16;
size_t solutions_heap_zone_size = 16;
-size_t global_heap_zone_size = 16;
-size_t trail_zone_size = 16;
-size_t debug_heap_zone_size = 16;
+size_t global_heap_zone_size = 16;
+size_t trail_zone_size = 16;
+size_t debug_heap_zone_size = 16;
-/* primary cache size to optimize for, in kilobytes */
-/* (but we later multiply by 1024 to convert to bytes) */
-size_t pcache_size = 8192;
+/* primary cache size to optimize for, in bytes */
+size_t pcache_size = 8192;
/* other options */
@@ -484,17 +483,97 @@
}
+enum MR_long_option {
+ MR_HEAP_SIZE,
+ MR_DETSTACK_SIZE,
+ MR_NONDETSTACK_SIZE,
+ MR_TRAIL_SIZE,
+ MR_HEAP_ZONE_SIZE,
+ MR_DETSTACK_ZONE_SIZE,
+ MR_NONDETSTACK_ZONE_SIZE,
+ MR_TRAIL_ZONE_SIZE
+};
+
+struct MR_option MR_long_opts[] = {
+ { "heap-size", 1, 0, MR_HEAP_SIZE },
+ { "detstack-size", 1, 0, MR_DETSTACK_SIZE },
+ { "nondetstack-size", 1, 0, MR_NONDETSTACK_SIZE },
+ { "trail-size", 1, 0, MR_TRAIL_SIZE },
+ { "heap-zone-size", 1, 0, MR_HEAP_ZONE_SIZE },
+ { "detstack-zone-size", 1, 0, MR_DETSTACK_ZONE_SIZE },
+ { "nondetstack-zone-size", 1, 0, MR_NONDETSTACK_ZONE_SIZE },
+ { "trail-zone-size", 1, 0, MR_TRAIL_ZONE_SIZE },
+};
+
static void
process_options(int argc, char **argv)
{
- unsigned long size;
- int c;
+ unsigned long size;
+ int c;
+ int long_index;
- while ((c = getopt(argc, argv, "acC:d:D:P:pr:s:tT:xz:")) != EOF)
+ while ((c = MR_getopt_long(argc, argv, "acC:d:D:P:pr:tT:x",
+ MR_long_opts, &long_index)) != EOF)
{
switch (c)
{
+ case MR_HEAP_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ heap_size = size;
+ break;
+
+ case MR_DETSTACK_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ detstack_size = size;
+ break;
+
+ case MR_NONDETSTACK_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ nondstack_size = size;
+ break;
+
+ case MR_TRAIL_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ trail_size = size;
+ break;
+
+ case MR_HEAP_ZONE_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ heap_zone_size = size;
+ break;
+
+ case MR_DETSTACK_ZONE_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ detstack_zone_size = size;
+ break;
+
+ case MR_NONDETSTACK_ZONE_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ nondstack_zone_size = size;
+ break;
+
+ case MR_TRAIL_ZONE_SIZE:
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
+ usage();
+
+ trail_zone_size = size;
+ break;
+
case 'a':
benchmark_all_solns = TRUE;
break;
@@ -504,7 +583,7 @@
break;
case 'C':
- if (sscanf(optarg, "%lu", &size) != 1)
+ if (sscanf(MR_optarg, "%lu", &size) != 1)
usage();
pcache_size = size * 1024;
@@ -512,35 +591,35 @@
break;
case 'd':
- if (streq(optarg, "b"))
+ if (streq(MR_optarg, "b"))
nondstackdebug = TRUE;
- else if (streq(optarg, "c"))
+ else if (streq(MR_optarg, "c"))
calldebug = TRUE;
- else if (streq(optarg, "d"))
+ else if (streq(MR_optarg, "d"))
detaildebug = TRUE;
- else if (streq(optarg, "g"))
+ else if (streq(MR_optarg, "g"))
gotodebug = TRUE;
- else if (streq(optarg, "G"))
+ else if (streq(MR_optarg, "G"))
#ifdef CONSERVATIVE_GC
GC_quiet = FALSE;
#else
- fatal_error("-dG: GC not enabled");
+ ; /* ignore inapplicable option */
#endif
- else if (streq(optarg, "s"))
+ else if (streq(MR_optarg, "s"))
detstackdebug = TRUE;
- else if (streq(optarg, "h"))
+ else if (streq(MR_optarg, "h"))
heapdebug = TRUE;
- else if (streq(optarg, "f"))
+ else if (streq(MR_optarg, "f"))
finaldebug = TRUE;
- else if (streq(optarg, "p"))
+ else if (streq(MR_optarg, "p"))
progdebug = TRUE;
- else if (streq(optarg, "m"))
+ else if (streq(MR_optarg, "m"))
memdebug = TRUE;
- else if (streq(optarg, "r"))
+ else if (streq(MR_optarg, "r"))
sregdebug = TRUE;
- else if (streq(optarg, "t"))
+ else if (streq(MR_optarg, "t"))
tracedebug = TRUE;
- else if (streq(optarg, "a")) {
+ else if (streq(MR_optarg, "a")) {
calldebug = TRUE;
nondstackdebug = TRUE;
detstackdebug = TRUE;
@@ -562,10 +641,10 @@
case 'D':
MR_trace_enabled = TRUE;
- if (streq(optarg, "i"))
+ if (streq(MR_optarg, "i"))
MR_trace_handler = MR_TRACE_INTERNAL;
#ifdef MR_USE_EXTERNAL_DEBUGGER
- else if (streq(optarg, "e"))
+ else if (streq(MR_optarg, "e"))
MR_trace_handler = MR_TRACE_EXTERNAL;
#endif
@@ -580,7 +659,7 @@
case 'P':
#ifdef MR_THREAD_SAFE
- if (sscanf(optarg, "%u", &MR_num_threads) != 1)
+ if (sscanf(MR_optarg, "%u", &MR_num_threads) != 1)
usage();
if (MR_num_threads < 1)
@@ -590,30 +669,11 @@
break;
case 'r':
- if (sscanf(optarg, "%d", &repeats) != 1)
+ if (sscanf(MR_optarg, "%d", &repeats) != 1)
usage();
break;
- case 's':
- if (sscanf(optarg+1, "%lu", &size) != 1)
- usage();
-
- if (optarg[0] == 'h')
- heap_size = size;
- else if (optarg[0] == 'd')
- detstack_size = size;
- else if (optarg[0] == 'n')
- nondstack_size = size;
-#ifdef MR_USE_TRAIL
- else if (optarg[0] == 't')
- trail_size = size;
-#endif
- else
- usage();
-
- break;
-
case 't':
use_own_timer = TRUE;
@@ -627,11 +687,11 @@
break;
case 'T':
- if (streq(optarg, "r")) {
+ if (streq(MR_optarg, "r")) {
MR_time_profile_method = MR_profile_real_time;
- } else if (streq(optarg, "v")) {
+ } else if (streq(MR_optarg, "v")) {
MR_time_profile_method = MR_profile_user_time;
- } else if (streq(optarg, "p")) {
+ } else if (streq(MR_optarg, "p")) {
MR_time_profile_method =
MR_profile_user_plus_system_time;
} else {
@@ -646,30 +706,20 @@
break;
- case 'z':
- if (sscanf(optarg+1, "%lu", &size) != 1)
- usage();
-
- if (optarg[0] == 'h')
- heap_zone_size = size;
- else if (optarg[0] == 'd')
- detstack_zone_size = size;
- else if (optarg[0] == 'n')
- nondstack_zone_size = size;
-#ifdef MR_USE_TRAIL
- else if (optarg[0] == 't')
- trail_zone_size = size;
-#endif
- else
- usage();
-
- break;
-
default:
usage();
} /* end switch */
} /* end while */
+
+ if (MR_optind != argc) {
+ printf("The MERCURY_OPTIONS environment variable "
+ "contains something other than\n"
+ "an option. Please refer to the Environment Variables "
+ "section of the\nMercury user's guide for details.\n");
+ fflush(stdout);
+ exit(1);
+ }
} /* end process_options() */
static void
Index: runtime/process_getopt
===================================================================
RCS file: process_getopt
diff -N process_getopt
--- /dev/null Wed May 28 10:49:58 1997
+++ process_getopt Sun Aug 9 18:18:29 1998
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+for file in getopt.h getopt.c getopt1.c
+do
+ echo processing mercury_$file
+ cp GETOPT/$file mercury_$file
+ ex mercury_$file << END
+ g/#include/s/getopt/mercury_getopt/
+ g/\<getopt/s//MR_getopt/g
+ g/\<optarg/s//MR_optarg/g
+ g/\<optind/s//MR_optind/g
+ g/\<opterr/s//MR_opterr/g
+ g/\<optopt/s//MR_optopt/g
+ g/\<option/s//MR_option/g
+ g/\<_getopt/s//MR__getopt/g
+ w
+ q
+END
+done
+
+echo finalizing mercury_getopt.h
+ex mercury_getopt.h << END
+1i
+#define __GNU_LIBRARY__
+.
+w
+q
+END
+
+echo finalizing mercury_getopt.c
+ex mercury_getopt.c << END
+1i
+extern char *getenv(const char *);
+.
+g/nextchar/s//MR_nextchar/g
+g/ordering/s//MR_ordering/g
+g/posixly_correct/s//MR_posixly_correct/g
+g/first_nonopt/s//MR_first_nonopt/g
+g/last_nonopt/s//MR_last_nonopt/g
+g/__getopt_initialized/s//MR____getopt_initialized/g
+w
+q
+END
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trial
cvs diff: Diffing util
More information about the developers
mailing list