about summary refs log tree commit diff
path: root/pkgs/development/compilers/sbcl/dynamic-space-size-envvar-feature.patch
blob: f1596958a6f8f81e6f2da448022f67407403d5c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From ac15f9f7c75c1fb5767514e64b609e2a75e6fe9d Mon Sep 17 00:00:00 2001
From: Hraban Luyat <hraban@0brg.net>
Date: Sat, 13 Apr 2024 14:04:57 -0400
Subject: [PATCH] feat: NIX_SBCL_DYNAMIC_SPACE_SIZE envvar

Read SBCL dynamic space size configuration from env if available.
---
 src/runtime/runtime.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c
index 274687c8f..970caa8f4 100644
--- a/src/runtime/runtime.c
+++ b/src/runtime/runtime.c
@@ -422,6 +422,29 @@ static int is_memsize_arg(char *argv[], int argi, int argc, int *merge_core_page
     return 0;
 }
 
+/**
+ * Read memory options from the environment, if present.
+ *
+ * Memory settings are read in the following priority:
+ *
+ * 1. command line arguments
+ * 2. environment variable
+ * 3. embedded options in core
+ * 4. default
+ */
+static void
+read_memsize_from_env(void) {
+  const char *val = getenv("NIX_SBCL_DYNAMIC_SPACE_SIZE");
+  // The distinction is blurry between setting an envvar to the empty string and
+  // unsetting it entirely. Depending on the calling environment it can even be
+  // tricky to properly unset an envvar in the first place. An empty envvar is
+  // practically always intended to just mean “unset”, so let’s interpret it
+  // that way.
+  if (val != NULL && (strcmp(val, "") != 0)) {
+    dynamic_space_size = parse_size_arg(val, "NIX_SBCL_DYNAMIC_SPACE_SIZE");
+  }
+}
+
 static struct cmdline_options
 parse_argv(struct memsize_options memsize_options,
            int argc, char *argv[], char *envp[], char *core)
@@ -462,6 +485,7 @@ parse_argv(struct memsize_options memsize_options,
         dynamic_space_size = memsize_options.dynamic_space_size;
         thread_control_stack_size = memsize_options.thread_control_stack_size;
         dynamic_values_bytes = memsize_options.thread_tls_bytes;
+        read_memsize_from_env();
         int stop_parsing = 0; // have we seen '--'
         int output_index = 1;
 
@@ -488,6 +512,7 @@ parse_argv(struct memsize_options memsize_options,
         }
         sbcl_argv[output_index] = 0;
     } else {
+        read_memsize_from_env();
         bool end_runtime_options = 0;
         /* Parse our any of the command-line options that we handle from C,
          * stopping at the first one that we don't, and leave the rest */
-- 
2.44.0