Tk Library Source Code

View Ticket
Login
Ticket UUID: 2538424
Title: unset in namespace has global side effects
Type: Bug Version: None
Submitter: mtsmith Created on: 2009-01-26 19:51:30
Subsystem: base64 Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-01-29 11:31:10
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2009-01-29 04:31:10
Description:
revision 1.29 of base64.tcl (latest revision) has an unset in the namespace eval base64 call when Trf isn't present. The specific line is:

199: unset base64_tmp i char len val

It also uses base64_tmp, i, char, len, and val earlier within the namespace eval. Since they're never declared with a "variable" call, they're resolved to global namespace. So the following example results in unappreciated behavior:

set i 0
package require base64
puts $i

The variable i is unset by base64. This should really be fixed by removing the "unset" call in namespace eval, and instead declaring these temporary variables in namespace scope with calls to variable.


Fix:
add after line 161: variable base64_tmp; variable i; variable char; variable len; variable val
remove line 199: unset base64_tmp i char len val
User Comments: andreas_kupries added on 2009-01-29 11:31:10:

allow_comments - 1

The removal of the 'unset' is not required if the variables are initialized with 'variable'.
Another instance of what is known as the 'creative writing' problem.
See http://wiki.tcl.tk/1030

Fixed in CVS head.