From a5805ca073019b470b8b21ac7ae5e0ebf0843bab Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Wed, 6 Jan 2016 21:00:07 -0800
Subject: [PATCH] If -dynamic-space-size is 0, use the max heap.

If the user specifies -dynamic-space-size 0, then use the
platform-specific maximum heap size.

Update the docstring for the switch too.
---
 src/code/commandline.lisp |  5 +++--
 src/lisp/lisp.c           | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/code/commandline.lisp b/src/code/commandline.lisp
index 2480a935f..36f037a01 100644
--- a/src/code/commandline.lisp
+++ b/src/code/commandline.lisp
@@ -283,8 +283,9 @@
 
 (defswitch "dynamic-space-size" nil
   "Specifies the number of megabytes that should be allocated to the
-  heap.  If not specified, a platform-specific default is used.  The
-  actual maximum allowed heap size is platform-specific."
+  heap.  If not specified, a platform-specific default is used.  If 0,
+  the platform-specific maximum heap size is used.  The actual maximum
+  allowed heap size is platform-specific."
   "megabytes")
 
 (defswitch "read-only-space-size" nil
diff --git a/src/lisp/lisp.c b/src/lisp/lisp.c
index 72a523dba..94611e261 100644
--- a/src/lisp/lisp.c
+++ b/src/lisp/lisp.c
@@ -622,7 +622,16 @@ main(int argc, const char *argv[], const char *envp[])
 		exit(1);
 	    }
 #ifndef sparc
-	    dynamic_space_size = atoi(str) * 1024 * 1024;
+	    dynamic_space_size = atoi(str);
+
+	    /*
+	     * A size of 0 means using the largest possible space
+	     */
+	    if (dynamic_space_size == 0) {
+		dynamic_space_size = DYNAMIC_SPACE_SIZE;
+	    } else {
+		dynamic_space_size *= 1024 * 1024;
+	    }
 #else
 	    {
 		int val;
@@ -646,6 +655,9 @@ main(int argc, const char *argv[], const char *envp[])
 			    "Note:  Rounding dynamic-space-size from %d MB to %d MB\n",
 			    val, dynamic_space_size);
 		}
+		if (dynamic_space_size == 0) {
+		    dynamic_space_size = DYNAMIC_SPACE_SIZE;
+		}
 		dynamic_space_size *= 1024 * 1024;
 	    }
 #endif
-- 
GitLab