diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | library/clock.tcl | 63 | ||||
-rw-r--r-- | tests/clock.test | 14 |
3 files changed, 63 insertions, 23 deletions
@@ -1,3 +1,12 @@ +2005-04-19 Kevin B. Kenny <kennykb@acm.org> + + * library/clock.tcl (Initialize): Put initialization code into a + proc to avoid inadvertently clobbering global variables. + [Bug 1185933] + * tests/clock.test (clock-48.1): Added regression test for the + above bug. + Thanks to Ulrich Ring for reporting this bug. + 2005-04-16 Miguel Sofer <msofer@users.sf.net> * generic/Var.c (Tcl_ArrayObjCmd - ARRAY_NAMES): fix Tcl_Obj leak diff --git a/library/clock.tcl b/library/clock.tcl index 337ed5a..ec97d2d 100644 --- a/library/clock.tcl +++ b/library/clock.tcl @@ -13,7 +13,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: clock.tcl,v 1.14 2005/04/13 19:28:51 kennykb Exp $ +# RCS: @(#) $Id: clock.tcl,v 1.15 2005/04/19 15:11:07 kennykb Exp $ # #---------------------------------------------------------------------- @@ -82,9 +82,37 @@ namespace eval ::tcl::clock { namespace import ::msgcat::mcload namespace import ::msgcat::mclocale +} + +#---------------------------------------------------------------------- +# +# ::tcl::clock::Initialize -- +# +# Finish initializing the 'clock' subsystem +# +# Results: +# None. +# +# Side effects: +# Namespace variable in the 'clock' subsystem are initialized. +# +# The '::tcl::clock::Initialize' procedure initializes the namespace +# variables and root locale message catalog for the 'clock' subsystem. +# It is broken into a procedure rather than simply evaluated as a script +# so that it will be able to use local variables, avoiding the dangers +# of 'creative writing' as in Bug 1185933. +# +#---------------------------------------------------------------------- + +proc ::tcl::clock::Initialize {} { + + rename ::tcl::clock::Initialize {} + + variable LibDir + # Define the Greenwich time zone - proc initTZData {} { + proc InitTZData {} { variable TZData array unset TZData set TZData(:Etc/GMT) { @@ -96,7 +124,7 @@ namespace eval ::tcl::clock { } set TZData(:UTC) $TZData(:Etc/UTC) } - initTZData + InitTZData # Define the message catalog for the root locale. @@ -227,21 +255,16 @@ namespace eval ::tcl::clock { # are known to reside on various operating systems variable ZoneinfoPaths {} - proc ZoneinfoInit {} { - variable ZoneinfoPaths - rename ZoneinfoInit {} - foreach path { - /usr/share/zoneinfo - /usr/share/lib/zoneinfo - /usr/local/etc/zoneinfo - C:/Progra~1/cygwin/usr/local/etc/zoneinfo - } { - if { [file isdirectory $path] } { - lappend ZoneinfoPaths $path - } + foreach path { + /usr/share/zoneinfo + /usr/share/lib/zoneinfo + /usr/local/etc/zoneinfo + C:/Progra~1/cygwin/usr/local/etc/zoneinfo + } { + if { [file isdirectory $path] } { + lappend ZoneinfoPaths $path } } - ZoneinfoInit # Define the directories for time zone data and message catalogs. @@ -264,7 +287,6 @@ namespace eval ::tcl::clock { foreach j $DaysInRomanMonthInLeapYear { lappend DaysInPriorMonthsInLeapYear [incr i $j] } - unset i j # Another epoch (Hi, Jeff!) @@ -598,6 +620,7 @@ namespace eval ::tcl::clock { # Daylight Saving Time indicator, and # time zone abbreviation. } +::tcl::clock::Initialize #---------------------------------------------------------------------- # @@ -1304,10 +1327,6 @@ proc ::tcl::clock::FreeScan { string base timezone locale } { if { [llength $parseWeekday] > 0 } { - # TODO - There's no reason for this to involve the - # ISO calendar; day of week is determined by - # Julian Day and there's no need to extract - # week of year foreach {dayOrdinal dayOfWeek} $parseWeekday break set date2 [GetJulianDay \ [ConvertUTCToLocal \ @@ -5042,6 +5061,6 @@ proc ::tcl::clock::ClearCaches {} { set LocaleNumeralCache {} set McLoaded {} catch {unset CachedSystemTimeZone} - initTZData + InitTZData } diff --git a/tests/clock.test b/tests/clock.test index 7cd4509..7c2673d 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: clock.test,v 1.53 2004/12/29 20:57:28 kennykb Exp $ +# RCS: @(#) $Id: clock.test,v 1.54 2005/04/19 15:11:08 kennykb Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -35399,6 +35399,18 @@ test clock-47.2 {regression test - four digit time} { clock scan 0039 } [clock scan 0039 -format %H%M] +test clock-48.1 {Bug 1185933: 'i' destroyed by clock init} -setup { + interp create child +} -body { + interp eval child { + set i 12345 + clock format 0 + list [catch { set i } result] $result + } +} -cleanup { + interp delete child +} -result {0 12345} + # cleanup namespace delete ::testClock |