sbcl: fix patches ahead of 2.5.3 release

+11 -4
pkgs/development/compilers/sbcl/default.nix
···
# have it block a release.
"futex-wait.test.sh"
];
-
patches = [
# Support the NIX_SBCL_DYNAMIC_SPACE_SIZE envvar. Upstream SBCL didn’t want
# to include this (see
# "https://sourceforge.net/p/sbcl/mailman/sbcl-devel/thread/2cf20df7-01d0-44f2-8551-0df01fe55f1a%400brg.net/"),
# but for Nix envvars are sufficiently useful that it’s worth maintaining
# this functionality downstream.
-
./dynamic-space-size-envvar-feature.patch
-
./dynamic-space-size-envvar-tests.patch
-
];
postPatch =
lib.optionalString (self.disabledTestFiles != [ ]) ''
(cd tests ; rm -f ${lib.concatStringsSep " " self.disabledTestFiles})
···
# have it block a release.
"futex-wait.test.sh"
];
+
patches =
# Support the NIX_SBCL_DYNAMIC_SPACE_SIZE envvar. Upstream SBCL didn’t want
# to include this (see
# "https://sourceforge.net/p/sbcl/mailman/sbcl-devel/thread/2cf20df7-01d0-44f2-8551-0df01fe55f1a%400brg.net/"),
# but for Nix envvars are sufficiently useful that it’s worth maintaining
# this functionality downstream.
+
if lib.versionOlder "2.5.2" self.version then
+
[
+
./dynamic-space-size-envvar-2.5.3-feature.patch
+
./dynamic-space-size-envvar-2.5.3-tests.patch
+
]
+
else
+
[
+
./dynamic-space-size-envvar-2.5.2-feature.patch
+
./dynamic-space-size-envvar-2.5.2-tests.patch
+
];
postPatch =
lib.optionalString (self.disabledTestFiles != [ ]) ''
(cd tests ; rm -f ${lib.concatStringsSep " " self.disabledTestFiles})
+64
pkgs/development/compilers/sbcl/dynamic-space-size-envvar-2.5.3-feature.patch
···
···
+
From 9c899f7b8089eee7ce471f237d2046882298c4fc Mon Sep 17 00:00:00 2001
+
From: Hraban Luyat <hraban@0brg.net>
+
Date: Sat, 13 Apr 2024 14:04:57 -0400
+
Subject: [PATCH 1/2] feat: NIX_SBCL_DYNAMIC_SPACE_SIZE envvar
+
+
---
+
src/runtime/runtime.c | 27 +++++++++++++++++++++++++++
+
1 file changed, 27 insertions(+)
+
+
diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c
+
index 2b1f8b634..4f3f51139 100644
+
--- a/src/runtime/runtime.c
+
+++ b/src/runtime/runtime.c
+
@@ -416,6 +416,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)
+
@@ -457,6 +480,9 @@ parse_argv(struct memsize_options memsize_options,
+
thread_control_stack_size = memsize_options.thread_control_stack_size;
+
dynamic_values_bytes = memsize_options.thread_tls_bytes;
+
if (memsize_options.present_in_core == 2) {
+
+ /* Only accept environment variable memory options where you would
+
+ * accept those options as command-line arguments. */
+
+ read_memsize_from_env();
+
int stop_parsing = 0; // have we seen '--'
+
int output_index = 1;
+
#ifndef LISP_FEATURE_WIN32
+
@@ -490,6 +516,7 @@ parse_argv(struct memsize_options memsize_options,
+
#endif
+
}
+
} 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.48.1
+
+130
pkgs/development/compilers/sbcl/dynamic-space-size-envvar-2.5.3-tests.patch
···
···
+
From 979a92d10731bae90e611b98d29be8d187f0f1f8 Mon Sep 17 00:00:00 2001
+
From: Hraban Luyat <hraban@0brg.net>
+
Date: Sat, 13 Apr 2024 15:39:58 -0400
+
Subject: [PATCH 2/2] test: dynamic space size envvar and precedence
+
+
---
+
tests/memory-args.test.sh | 22 ++++++++++++++++++
+
tests/save7.test.sh | 49 ++++++++++++++++++++++++++++++++++-----
+
2 files changed, 65 insertions(+), 6 deletions(-)
+
create mode 100755 tests/memory-args.test.sh
+
+
diff --git a/tests/memory-args.test.sh b/tests/memory-args.test.sh
+
new file mode 100755
+
index 000000000..72ef0cc79
+
--- /dev/null
+
+++ b/tests/memory-args.test.sh
+
@@ -0,0 +1,22 @@
+
+#!/bin/sh
+
+
+
+. ./subr.sh
+
+
+
+use_test_subdirectory
+
+
+
+set -e
+
+
+
+# Allow slight shrinkage if heap relocation has to adjust for alignment
+
+NIX_SBCL_DYNAMIC_SPACE_SIZE=234mb run_sbcl_with_args --script <<EOF
+
+(assert (<= 0 (- (* 234 1024 1024) (sb-ext:dynamic-space-size)) 65536))
+
+EOF
+
+
+
+NIX_SBCL_DYNAMIC_SPACE_SIZE=555mb run_sbcl_with_args --dynamic-space-size 234mb --script <<EOF
+
+(assert (<= 0 (- (* 234 1024 1024) (sb-ext:dynamic-space-size)) 65536))
+
+EOF
+
+
+
+run_sbcl_with_args --dynamic-space-size 234mb --script <<EOF
+
+(assert (<= 0 (- (* 234 1024 1024) (sb-ext:dynamic-space-size)) 65536))
+
+EOF
+
+
+
+exit $EXIT_TEST_WIN
+
diff --git a/tests/save7.test.sh b/tests/save7.test.sh
+
index dd112f220..d56bddbc2 100644
+
--- a/tests/save7.test.sh
+
+++ b/tests/save7.test.sh
+
@@ -25,6 +25,9 @@ echo "::: Success"
+
+
run_sbcl_with_args --noinform --control-stack-size 384KB --dynamic-space-size 260MB \
+
--disable-debugger --no-userinit --no-sysinit --noprint <<EOF
+
+ ; allow slight shrinkage if heap relocation has to adjust for alignment
+
+ (defun dynamic-space-size-good-p (expected-mb)
+
+ (<= 0 (- (* expected-mb 1024 1024) (dynamic-space-size)) 65536))
+
(save-lisp-and-die "$tmpcore" :executable t :save-runtime-options :accept-runtime-options)
+
EOF
+
chmod u+x "$tmpcore"
+
@@ -57,6 +60,29 @@ if [ $? -ne 0 ]; then
+
fi
+
echo "::: Success"
+
+
+echo "::: Running :DYNAMIC-SPACE-SIZE-ENV-ACCEPT"
+
+NIX_SBCL_DYNAMIC_SPACE_SIZE=432MB ./"$tmpcore" --no-userinit --no-sysinit --noprint <<EOF
+
+ (when (dynamic-space-size-good-p 432)
+
+ (exit :code 42))
+
+EOF
+
+if [ $? -ne 42 ]; then
+
+ exit 1
+
+fi
+
+echo "::: Success"
+
+
+
+echo "::: Running :DYNAMIC-SPACE-SIZE-PRECEDENCE"
+
+NIX_SBCL_DYNAMIC_SPACE_SIZE=432MB ./"$tmpcore" --dynamic-space-size 333MB \
+
+ --no-userinit --no-sysinit --noprint <<EOF
+
+ (when (dynamic-space-size-good-p 333))
+
+ (exit :code 42))
+
+EOF
+
+status=$?
+
+if [ $status -ne 42 ]; then
+
+ echo "saved core should have prioritized memory specification from arg"
+
+ exit 1
+
+fi
+
+echo "::: Success"
+
+
+
echo "::: Running :DYNAMIC-SPACE-SIZE-ARG"
+
run_sbcl_with_core "$tmpcore" --noinform --control-stack-size 640KB \
+
--tls-limit 5000 \
+
@@ -64,10 +90,7 @@ run_sbcl_with_core "$tmpcore" --noinform --control-stack-size 640KB \
+
(assert (eql (extern-alien "thread_control_stack_size" unsigned) (* 640 1024)))
+
(assert (eql (extern-alien "dynamic_values_bytes" (unsigned 32))
+
(* 5000 sb-vm:n-word-bytes)))
+
- ; allow slight shrinkage if heap relocation has to adjust for alignment
+
- (defun dynamic-space-size-good-p ()
+
- (<= 0 (- (* 260 1048576) (dynamic-space-size)) 65536))
+
- (assert (dynamic-space-size-good-p))
+
+ (assert (dynamic-space-size-good-p 260))
+
(save-lisp-and-die "${tmpcore}2" :executable t :save-runtime-options t)
+
EOF
+
chmod u+x "${tmpcore}2"
+
@@ -76,15 +99,29 @@ echo "::: INFO: prepared test core"
+
(when (and (eql (extern-alien "thread_control_stack_size" unsigned) (* 640 1024))
+
(eql (extern-alien "dynamic_values_bytes" (unsigned 32))
+
(* 5000 sb-vm:n-word-bytes))
+
- (dynamic-space-size-good-p))
+
+ (dynamic-space-size-good-p 260))
+
(exit :code 42))
+
EOF
+
status=$?
+
-rm "$tmpcore" "${tmpcore}2"
+
if [ $status -ne 42 ]; then
+
echo "re-saved executable used wrong memory size options"
+
exit 1
+
fi
+
echo "::: Success"
+
+
+echo "::: Running :DYNAMIC-SPACE-SIZE-ENV-IGNORE"
+
+NIX_SBCL_DYNAMIC_SPACE_SIZE=432MB ./"${tmpcore}2" --no-userinit --no-sysinit --noprint <<EOF
+
+ (when (dynamic-space-size-good-p 260)
+
+ (exit :code 42))
+
+EOF
+
+status=$?
+
+if [ $status -ne 42 ]; then
+
+ echo "re-saved executable should have ignored memory specification from env"
+
+ exit 1
+
+fi
+
+echo "::: Success"
+
+rm "$tmpcore" "${tmpcore}2"
+
+
+
+
+
+
+
exit $EXIT_TEST_WIN
+
--
+
2.48.1
+
pkgs/development/compilers/sbcl/dynamic-space-size-envvar-feature.patch pkgs/development/compilers/sbcl/dynamic-space-size-envvar-2.5.2-feature.patch
pkgs/development/compilers/sbcl/dynamic-space-size-envvar-tests.patch pkgs/development/compilers/sbcl/dynamic-space-size-envvar-2.5.2-tests.patch