diff options
author | dgp <dgp@users.sourceforge.net> | 2019-05-15 17:16:15 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2019-05-15 17:16:15 (GMT) |
commit | 1673645f691d6a028123a612d5476541b8305d91 (patch) | |
tree | 997fdd527429a66e102d778bb8ad17196245fb28 | |
parent | 9c596d150ad96b9e928fb86d4dad82ebfcefa2d2 (diff) | |
download | tk-1673645f691d6a028123a612d5476541b8305d91.zip tk-1673645f691d6a028123a612d5476541b8305d91.tar.gz tk-1673645f691d6a028123a612d5476541b8305d91.tar.bz2 |
Tests and fix for [menubutton ... -textvariable].
-rw-r--r-- | generic/tkMenubutton.c | 22 | ||||
-rw-r--r-- | tests/menubut.test | 28 |
2 files changed, 49 insertions, 1 deletions
diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c index 1a4d5ae..9faa263 100644 --- a/generic/tkMenubutton.c +++ b/generic/tkMenubutton.c @@ -887,7 +887,27 @@ MenuButtonTextVarProc( */ if (flags & TCL_TRACE_UNSETS) { - if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { + if (!Tcl_InterpDeleted(interp) && mbPtr->textVarName) { + ClientData probe = NULL; + + do { + probe = Tcl_VarTraceInfo(interp, + mbPtr->textVarName, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + MenuButtonTextVarProc, probe); + if (probe == (ClientData)mbPtr) { + break; + } + } while (probe); + if (probe) { + /* + * We were able to fetch the unset trace for our + * textVarName, 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_SetVar2(interp, mbPtr->textVarName, NULL, mbPtr->text, TCL_GLOBAL_ONLY); Tcl_TraceVar2(interp, mbPtr->textVarName, NULL, diff --git a/tests/menubut.test b/tests/menubut.test index 6efdb0f..93b2482 100644 --- a/tests/menubut.test +++ b/tests/menubut.test @@ -747,6 +747,34 @@ test menubutton-8.1 {menubutton vs hidden commands} -body { expr {$res1 eq $res2} } -result 1 +test menubutton-9.1 {Bug [5d991b822e]} { + # Want this not to segfault, or write to variable with empty name + set var INIT + menubutton .b -textvariable var + trace add variable var unset {apply {args { + .b configure -textvariable {} + }}} + pack .b + bind .b <Configure> {unset var} + update + destroy .b + info exists {} +} 0 +test menubutton-9.2 {Bug [5d991b822e]} { + # Want this not to leak traces + set var INIT + menubutton .b -textvariable var + trace add variable var unset {apply {args { + .b configure -textvariable new + }}} + pack .b + bind .b <Configure> {unset -nocomplain var} + update + destroy .b + unset new +} {} + + deleteWindows |