From aefe754799655f3fa04cc84f4ea5d110d0289c46 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 15 May 2019 17:30:35 +0000 Subject: Tests and fix for [scale ... -variable]. --- generic/tkScale.c | 23 ++++++++++++++++++++++- tests/scale.test | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/generic/tkScale.c b/generic/tkScale.c index ef67630..3920aea 100644 --- a/generic/tkScale.c +++ b/generic/tkScale.c @@ -1198,7 +1198,28 @@ ScaleVarProc( */ if (flags & TCL_TRACE_UNSETS) { - if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { + + if (!Tcl_InterpDeleted(interp) && scalePtr->varNamePtr) { + ClientData probe = NULL; + + do { + probe = Tcl_VarTraceInfo(interp, + Tcl_GetString(scalePtr->varNamePtr), + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ScaleVarProc, probe); + if (probe == (ClientData)scalePtr) { + break; + } + } while (probe); + if (probe) { + /* + * We were able to fetch the unset trace for our + * varNamePtr, which means it is not unset and not + * the cause of this unset trace. Instead some outdated + * former variable must be, and we should ignore it. + */ + return NULL; + } Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, ScaleVarProc, clientData); diff --git a/tests/scale.test b/tests/scale.test index 79524eb..ba70285 100644 --- a/tests/scale.test +++ b/tests/scale.test @@ -1524,6 +1524,32 @@ test scale-21.2 {Bug [55b95f578a] again - Bignum value for -from/-to with scale destroy .s } -result {} +test scale-22.1 {Bug [5d991b822e]} { + # Want this not to crash + set var INIT + scale .b -variable var + trace add variable var unset {apply {args { + .b configure -variable {} + }}} + pack .b + bind .b {unset var} + update + destroy .b +} {} +test scale-22.2 {Bug [5d991b822e]} { + # Want this not to leak traces + set var INIT + scale .b -variable var + trace add variable var unset {apply {args { + .b configure -variable new + }}} + pack .b + bind .b {unset -nocomplain var} + update + destroy .b + unset new +} {} + option clear # cleanup -- cgit v0.12