1From ac15f9f7c75c1fb5767514e64b609e2a75e6fe9d Mon Sep 17 00:00:00 2001
2From: Hraban Luyat <hraban@0brg.net>
3Date: Sat, 13 Apr 2024 14:04:57 -0400
4Subject: [PATCH] feat: NIX_SBCL_DYNAMIC_SPACE_SIZE envvar
5
6Read SBCL dynamic space size configuration from env if available.
7---
8 src/runtime/runtime.c | 25 +++++++++++++++++++++++++
9 1 file changed, 25 insertions(+)
10
11diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c
12index 274687c8f..970caa8f4 100644
13--- a/src/runtime/runtime.c
14+++ b/src/runtime/runtime.c
15@@ -422,6 +422,29 @@ static int is_memsize_arg(char *argv[], int argi, int argc, int *merge_core_page
16 return 0;
17 }
18
19+/**
20+ * Read memory options from the environment, if present.
21+ *
22+ * Memory settings are read in the following priority:
23+ *
24+ * 1. command line arguments
25+ * 2. environment variable
26+ * 3. embedded options in core
27+ * 4. default
28+ */
29+static void
30+read_memsize_from_env(void) {
31+ const char *val = getenv("NIX_SBCL_DYNAMIC_SPACE_SIZE");
32+ // The distinction is blurry between setting an envvar to the empty string and
33+ // unsetting it entirely. Depending on the calling environment it can even be
34+ // tricky to properly unset an envvar in the first place. An empty envvar is
35+ // practically always intended to just mean “unset”, so let’s interpret it
36+ // that way.
37+ if (val != NULL && (strcmp(val, "") != 0)) {
38+ dynamic_space_size = parse_size_arg(val, "NIX_SBCL_DYNAMIC_SPACE_SIZE");
39+ }
40+}
41+
42 static struct cmdline_options
43 parse_argv(struct memsize_options memsize_options,
44 int argc, char *argv[], char *envp[], char *core)
45@@ -462,6 +485,7 @@ parse_argv(struct memsize_options memsize_options,
46 dynamic_space_size = memsize_options.dynamic_space_size;
47 thread_control_stack_size = memsize_options.thread_control_stack_size;
48 dynamic_values_bytes = memsize_options.thread_tls_bytes;
49+ read_memsize_from_env();
50 int stop_parsing = 0; // have we seen '--'
51 int output_index = 1;
52
53@@ -488,6 +512,7 @@ parse_argv(struct memsize_options memsize_options,
54 }
55 sbcl_argv[output_index] = 0;
56 } else {
57+ read_memsize_from_env();
58 bool end_runtime_options = 0;
59 /* Parse our any of the command-line options that we handle from C,
60 * stopping at the first one that we don't, and leave the rest */
61--
622.44.0
63