make --dynamic-space-size and --control-stack-size understand power-suffixes
authorNikodemus Siivola <nikodemus@random-state.net>
Mon, 21 Nov 2011 13:52:31 +0000 (15:52 +0200)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 21 Nov 2011 16:18:40 +0000 (18:18 +0200)
  All of Kb, KiB, Mb, MiB, Gb, GiB are accepted, in a case-insentitive manner
  -- all taken to mean powers of two.

NEWS
src/runtime/runtime.c

diff --git a/NEWS b/NEWS
index 4472e46..b9fcd77 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,10 +24,23 @@ changes relative to sbcl-1.0.53:
        STANDARD-INSTANCE-ACCESS, and FUNCALLABLE-STANDARD-INSTANCE-ACCESS.
     ** Users can now defined new places usable with SB-EXT:COMPARE-AND-SWAP
        using an API anologous to defining new SETFable places.
+  * GC-related enhancements and bug fixes:
+    ** --dynamic-space-size and --control-stack-size now understand Kb, Mb,
+         and Gb suffixes. Default is megabytes as before.
+    ** on GENCGC systems nursery and generation sizes now default to 5% of
+       dynamic-space size.
+    ** on 64-bit systems setting the nursery size above 4Gb now
+       works. (lp#870868)
+    ** SB-KERNEL:MAKE-LISP-OBJ on GENCGC no longer categorically refuses to
+       create SIMPLE-FUN objects.
+  * SB-BSD-SOCKETS bug fixes:
+    ** GET-PROTOCOL-BY-NAME had a significant memory leak.
+    ** GET-HOST-BY-NAME and GET-HOST-BY-ADDRESS small amounts of memory on
+       systems with getaddrinfo().
+    ** GET-HOST-BY-NAME and GET-HOST-BY-ADDRESS weren't thread or interrupt
+       safe outside systems with getaddrinfo().
   * enhancement: debug-names of anonymous and local function are more
     descriptive. Affects backtraces and SB-SPROF results. (lp#805100)
-  * enhancement: on GENCGC systems nursery and generation sizes now default to
-    5% of dynamic-space size.
   * enhancement: on CHENEYGC targets, SB-KERNEL:MAKE-LISP-OBJ now does
     the same validation of pointer objects as GENCGC does, instead of a
     comparatively weak bounds-check against the heap spaces.
@@ -42,20 +55,10 @@ changes relative to sbcl-1.0.53:
     correctly, even on wide-fixnum builds. (lp#887220)
   * bug fix: (directory "foo/*/*.*") did not follow symlinks in foo/ that
     resolved to directories.
-  * bug fix: SB-KERNEL:MAKE-LISP-OBJ on GENCGC no longer categorically
-    refuses to create SIMPLE-FUN objects.
   * bug fix: type mismatch when assigning to lexical variables no longer
     result in fasl-dumping internal type objects. (lp#890750)
   * bug fix: type mismatch on (setf aref) and function return values no
     longer result in fasl-dumping internal type objects.
-  * bug fix: SB-BSD-SOCKETS issues
-    ** GET-PROTOCOL-BY-NAME had a significant memory leak.
-    ** GET-HOST-BY-NAME and GET-HOST-BY-ADDRESS small amounts of memory on
-       systems with getaddrinfo().
-    ** GET-HOST-BY-NAME and GET-HOST-BY-ADDRESS weren't thread or interrupt
-       safe outside systems with getaddrinfo().
-  * bug fix: on 64-bit systems setting the nursery size above 4Gb now works.
-    (lp#870868)
   * bug fix: With several combinations of argument types, for example (EXPT
     <integer> <(complex double)>), EXPT now uses double-precision throughout
     instead of partially calculating only to single-precision.  (lp#741564;
index b84d6af..d2cb732 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 #ifndef LISP_FEATURE_WIN32
 #include <libgen.h>
 #endif
@@ -291,6 +292,46 @@ search_for_executable(const char *argv0)
 }
 #endif /* LISP_FEATURE_WIN32 */
 
+long parse_size_arg(char *arg, char *arg_name)
+{
+  char *tail, *power_name;
+  long power, res;
+  res = strtol(arg, &tail, 0);
+  if (arg == tail) {
+    lose("%s argument is not a number: %s", arg_name, arg);
+  } else if (tail[0]) {
+    int i, size;
+    power_name = copied_string(tail);
+    size = strlen(power_name);
+    for (i=0; i<size; i++)
+      power_name[i] = toupper(power_name[i]);
+  } else {
+    power = 20;
+    power_name = NULL;
+  }
+  if (power_name) {
+    if ((0==strcmp("KB", power_name)) ||
+        (0==strcmp("KIB", power_name))) {
+      power = 10;
+    } else if ((0==strcmp("MB", power_name)) ||
+               (0==strcmp("MIB", power_name))) {
+      power = 20;
+    } else if ((0==strcmp("GB", power_name)) ||
+               (0==strcmp("GIB", power_name))) {
+      power = 30;
+    } else {
+      lose("%s argument has an unknown suffix: %s", arg_name, tail);
+    }
+    free(power_name);
+  }
+  if ((res <= 0) ||
+      (res >= (LONG_MAX >> power))) {
+    lose("%s argument is out of range: %s", arg_name, arg);
+  }
+  res <<= power;
+  return res;
+}
+
 char **posix_argv;
 char *core_string;
 
@@ -402,32 +443,21 @@ main(int argc, char *argv[], char *envp[])
                 ++argi;
                 if (argi >= argc)
                     lose("missing argument for --dynamic-space-size");
-                {
-                  char *tail;
-                  long tmp = strtol(argv[argi++], &tail, 0);
-                  if (tail[0])
-                    lose("--dynamic-space-size argument is not a number");
-                  if ((tmp <= 0) ||
-                      (tmp >= (LONG_MAX >> 20))) {
-                    lose("--dynamic-space-size argument is out of range");
-                  }
-                  dynamic_space_size = tmp << 20;
-                }
+                  dynamic_space_size = parse_size_arg(argv[argi++], "--dynamic-space-size");
 #               ifdef MAX_DYNAMIC_SPACE_END
                 if (!((DYNAMIC_SPACE_START <
                        DYNAMIC_SPACE_START+dynamic_space_size) &&
                       (DYNAMIC_SPACE_START+dynamic_space_size <=
                        MAX_DYNAMIC_SPACE_END)))
-                    lose("--dynamic-space-size argument is too large");
+                  lose("--dynamic-space-size argument %s is too large, max %ldMiB",
+                       argv[argi-1], MAX_DYNAMIC_SPACE_END-DYNAMIC_SPACE_START);
 #               endif
             } else if (0 == strcmp(arg, "--control-stack-size")) {
                 ++argi;
                 if (argi >= argc)
                     lose("missing argument for --control-stack-size");
                 errno = 0;
-                thread_control_stack_size = strtol(argv[argi++], 0, 0) << 20;
-                if (errno)
-                    lose("argument to --control-stack-size is not a number");
+                thread_control_stack_size = parse_size_arg(argv[argi++], "--control-stack-size");
             } else if (0 == strcmp(arg, "--debug-environment")) {
                 int n = 0;
                 printf("; Commandline arguments:\n");