Artifacts Associated With Ticket 58fa7cc7f88d70c4
Ticket change [4df28275d7] (rid 237613) by erikleunissen on 2025-02-20 10:04:51:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The script below exercises two different inexplicable issues: 1. (Cases A1+B1 below) The variable x is unset, the trace callback redefines x, but x does not become visible. Only if the callback command is called another time (directly), the namespace variable becomes visible again. 2. (Case A2) The namespace variable (with the same initial visibility as case A1) is unset but this does not trigger the callback command. This issue impedes the implementation of redefining namespace variables in project tk_collect_test_utils, forcing that it reverts to a less effective method. -- namespace eval ::child { variable x proc callback {args} { if {[llength $args] > 0} { puts "After callback triggered by unset trace" } else { puts "After callback invoked directly (not as a trace callback)" } variable x; # restore namespace variable } trace add variable x unset [list ::child::callback] } # Experiment with different invocations of the callback proc # Case 0: visibility of the namespace variable puts "O. Initial situation\n|[namespace inscope ::child [list info vars x]]|" # Case A1. let "unset" trigger the callback puts -nonewline "\nA1. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B1. invoke "callback" directly, i.e. not as a callback command puts -nonewline "\nB1. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" # Repeat A. and B. and see the different results # Case A2: should trigger the callback as in A1, but it doesn't puts -nonewline "\nA2. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B2: as B1 puts -nonewline "\nB2. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" # EOF - foundin initialized to: "trunk"
- is_private initialized to: "0"
- login: "erikleunissen"
- priority initialized to: "5 Medium"
- private_contact initialized to: "609f4c7ecf7dbb7a46acdc7eb164753d196088a6"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "erikleunissen"
- subsystem initialized to: "21. [namespace]"
- title initialized to:
Callback for unset trace on namespace variable has inexplicable effect on its visibility
- type initialized to: "Bug"
Ticket change [ba3dc7ad7d] (rid 237619) by erikleunissen on 2025-02-20 13:04:57:
- comment changed to:
The script below exercises two different inexplicable issues: 1. (Cases A1+B1 below) The variable x is unset, the trace callback redefines x, but x does not become visible. Only if the callback command is called another time (directly), the namespace variable becomes visible again. 2. (Case A2) The namespace variable (with the same initial visibility as case A1) is unset but this does not trigger the callback command. -- namespace eval ::child { variable x proc callback {args} { if {[llength $args] > 0} { puts "After callback triggered by unset trace" } else { puts "After callback invoked directly (not as a trace callback)" } variable x; # restore namespace variable } trace add variable x unset [list ::child::callback] } # Experiment with different invocations of the callback proc # Case 0: Initial visibility of the namespace variable puts "O. Initial situation\n|[namespace inscope ::child [list info vars x]]|" # Case A1. let "unset" trigger the callback puts -nonewline "\nA1. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B1. invoke "callback" directly, i.e. not as a callback command puts -nonewline "\nB1. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" # Repeat A. and B. and see the different results # Case A2: should trigger the callback as in A1, but it doesn't puts -nonewline "\nA2. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B2: as B1 puts -nonewline "\nB2. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" -- Results: ------- O. Initial situation |x| A1. After callback triggered by unset trace || B1. After callback invoked directly (not as a trace callback) |x| A2. || B2. After callback invoked directly (not as a trace callback) |x| -- end of message -- - login: "erikleunissen"
- mimetype: "text/plain"
- comment changed to:
Ticket change [a92c6c68a4] (rid 237620) by erikleunissen on 2025-02-20 13:07:48:
- comment changed to:
The script below exercises two different inexplicable issues: 1. (Cases A1+B1 below) The variable x is unset, the trace callback redefines x, but x does not become visible. Only if the callback command is called another time (directly), the namespace variable becomes visible again. 2. (Case A2) The namespace variable (with the same initial visibility as case A1) is unset but this does not trigger the callback command. -- namespace eval ::child { variable x proc callback {args} { if {[llength $args] > 0} { puts "Callback triggered by unset trace" } else { puts "Callback invoked directly (not as a trace callback)" } variable x; # restore namespace variable } trace add variable x unset [list ::child::callback] } # Experiment with different invocations of the callback proc # Case 0: Initial visibility of the namespace variable puts "O. Initial situation\n|[namespace inscope ::child [list info vars x]]|" # Case A1. let "unset" trigger the callback puts -nonewline "\nA1. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B1. invoke "callback" directly, i.e. not as a callback command puts -nonewline "\nB1. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" # Repeat A. and B. and see the different results # Case A2: should trigger the callback as in A1, but it doesn't puts -nonewline "\nA2. " namespace inscope ::child {unset -nocomplain x} puts "|[namespace inscope ::child [list info vars x]]|" # Case B2: as B1 puts -nonewline "\nB2. " ::child::callback puts "|[namespace inscope ::child [list info vars x]]|" -- Results: ------- O. Initial situation |x| A1. Callback triggered by unset trace || B1. Callback invoked directly (not as a trace callback) |x| A2. || B2. Callback invoked directly (not as a trace callback) |x| -- end of message -- - login: "erikleunissen"
- mimetype: "text/plain"
- comment changed to:
Ticket change [ff1b5ca1cc] (rid 237621) by erikleunissen on 2025-02-20 13:11:19:
- foundin changed to: "9.0.1"
- login: "erikleunissen"
- mimetype: "text/plain"
Ticket change [9e91d89e0a] (rid 237622) by sebres on 2025-02-20 13:56:01:
- closedate changed to: "2460727.08057381"
- closer changed to: "sebres"
- icomment:
This is fully expected behaviour and can be simply explained: Invocation of `variable x` without value in a proc-frame doesn't restore the variable, so after all the unset-trace would not retain it and variable gets deleted hereafter (by the way together with the trace). Basically `variable` without value only creates a link in local proc-frame (scope), which then points to non-existing variable. And if trace leaves the proc callback, this local link gets removed together with the proc-frame. So one has to set variable in trace-callkback (e. g. with `variable x some-val`) then it'd be retained. Otherwise it will be always removed by unset. Even in a NS or global level, `variable x` would not really create a variable, but rather a link to var (which still doesn't exist): ``` % variable x % list [info vars x] [info exists x] x 0 ``` As for the case by repeat, it is also pretty obvious: the unset of variable also removes its trace, so one has to register it again if needed. Here is a code that hopefully explains it: ``` % trace add variable x unset {apply {args {puts "** $args"; variable x}}} % unset -nocomplain x ** x {} unset % list [info vars x] [info exists x] {} 0 % trace add variable x unset {apply {args {puts "** $args"; variable x "restored"}}} % list [info vars x] [info exists x] {} 0 % unset -nocomplain x ** x {} unset % list [info vars x] [info exists x] x 1 ``` Thus closed as invalid. - login: "sebres"
- mimetype: "text/x-markdown"
- resolution changed to: "Invalid"
- status changed to: "Closed"