diff options
author | apnadkarni <apnmbx-wits@yahoo.com> | 2022-07-22 11:10:15 (GMT) |
---|---|---|
committer | apnadkarni <apnmbx-wits@yahoo.com> | 2022-07-22 11:10:15 (GMT) |
commit | 5f5c1bf7f1f0c4fb33e50301c87ad228cc1cc366 (patch) | |
tree | bf7b683bd347e29ff327df8e775cc3af78c4b88f | |
parent | 951e955d2c89cad1bd96d2e9ec08233d1a14f2f1 (diff) | |
download | tcl-5f5c1bf7f1f0c4fb33e50301c87ad228cc1cc366.zip tcl-5f5c1bf7f1f0c4fb33e50301c87ad228cc1cc366.tar.gz tcl-5f5c1bf7f1f0c4fb33e50301c87ad228cc1cc366.tar.bz2 |
Fix and test crash using apply when the passed argument
does NOT have already Lambda internal representation but the body
of the lambda DOES have an internal ByteCode representation.
-rw-r--r-- | generic/tclProc.c | 8 | ||||
-rw-r--r-- | tests/apply.test | 9 |
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 |