summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclProc.c8
-rw-r--r--tests/apply.test9
2 files changed, 17 insertions, 0 deletions
diff --git a/generic/tclProc.c b/generic/tclProc.c
index 17635e7..9677f02 100644
--- a/generic/tclProc.c
+++ b/generic/tclProc.c
@@ -2457,6 +2457,14 @@ SetLambdaFromAny(
argsPtr = objv[0];
bodyPtr = objv[1];
+ /*
+ * Bugfix for testapplylambda. If we are constructing a new lambda,
+ * the body must be recompiled even if it is already a ByteCode object.
+ * Otherwise the procPtr->numCompiledLocals will not get updated causing
+ * a crash as local variable space is not allocated.
+ */
+ (void) TclGetString(bodyPtr); /* Ensure string representation exists */
+ TclFreeInternalRep(bodyPtr);
/*
* Create and initialize the Proc struct. The cmdPtr field is set to NULL
diff --git a/tests/apply.test b/tests/apply.test
index e2be172..32dff08 100644
--- a/tests/apply.test
+++ b/tests/apply.test
@@ -22,6 +22,8 @@ if {[info commands ::apply] eq {}} {
}
testConstraint memory [llength [info commands memory]]
+testConstraint applylambda [llength [info commands testapplylambda]]
+
# Tests for wrong number of arguments
@@ -306,6 +308,13 @@ test apply-9.3 {leaking internal rep} -setup {
unset -nocomplain end i x tmp leakedBytes
} -result 0
+# Tests for specific bugs
+test apply-10.1 {Test for precompiled bytecode body} -constraints {
+ applylambda
+} -body {
+ testapplylambda
+} -result 42
+
# Tests for the avoidance of recompilation
# cleanup