From 02d8d08520b48fae236b2c0073b0d3e4fcc61845 Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 26 Oct 2004 20:14:12 +0000 Subject: * tests/compile.test (compile-12.4): Backport test for Bug 1001997. * tests/timer.test (timer-10.1): Backport test for Bug 1016167. * tests/tcltest.test (tcltest-12.3,4): Backport setup corrections. * tests/error.test (error-6.3,4,7,9): Backport of some tests. * tests/basic.test (basic-49.*): * tests/namespace.test (namespace-8.7): * tests/init.test (init-2.8): Updated to not rely on http package. * generic/tclThreadTest.c (ThreadEventProc): Corrected subtle bug where the returned (char *) from Tcl_GetStringResult(interp) continued to be used without copying or refcounting, while activity on the interp continued. --- ChangeLog | 15 +++++++++++++ generic/tclThreadTest.c | 4 ++-- tests/basic.test | 22 +++++++++++++++++- tests/compile.test | 60 ++++++++++++++++++++++++++++++++++++++++++++++++- tests/error.test | 26 ++++++++++++++++++++- tests/init.test | 19 ++++++++-------- tests/namespace.test | 9 +++++++- tests/tcltest.test | 4 +++- tests/timer.test | 15 +++++++++++-- 9 files changed, 155 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 500ff62..5cdad14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-10-26 Don Porter + + * tests/compile.test (compile-12.4): Backport test for Bug 1001997. + * tests/timer.test (timer-10.1): Backport test for Bug 1016167. + * tests/tcltest.test (tcltest-12.3,4): Backport setup corrections. + * tests/error.test (error-6.3,4,7,9): Backport of some tests. + * tests/basic.test (basic-49.*): + * tests/namespace.test (namespace-8.7): + * tests/init.test (init-2.8): Updated to not rely on http package. + + * generic/tclThreadTest.c (ThreadEventProc): Corrected subtle + bug where the returned (char *) from Tcl_GetStringResult(interp) + continued to be used without copying or refcounting, while + activity on the interp continued. + 2004-10-14 Donal K. Fellows * generic/tclUtil.c (TclMatchIsTrivial): Detect degenerate cases diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index c830687..f551746 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -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: tclThreadTest.c,v 1.16 2002/01/26 01:10:08 dgp Exp $ + * RCS: @(#) $Id: tclThreadTest.c,v 1.16.2.1 2004/10/26 20:14:29 dgp Exp $ */ #include "tclInt.h" @@ -868,13 +868,13 @@ ThreadEventProc(evPtr, mask) code = Tcl_GlobalEval(interp, threadEventPtr->script); Tcl_DeleteThreadExitHandler(ThreadFreeProc, (ClientData) threadEventPtr->script); - result = Tcl_GetStringResult(interp); if (code != TCL_OK) { errorCode = Tcl_GetVar(interp, "errorCode", TCL_GLOBAL_ONLY); errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY); } else { errorCode = errorInfo = NULL; } + result = Tcl_GetStringResult(interp); } ckfree(threadEventPtr->script); if (resultPtr) { diff --git a/tests/basic.test b/tests/basic.test index 39c9f67..294746f 100644 --- a/tests/basic.test +++ b/tests/basic.test @@ -15,7 +15,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: basic.test,v 1.25.2.4 2004/07/28 16:28:21 dgp Exp $ +# RCS: @(#) $Id: basic.test,v 1.25.2.5 2004/10/26 20:14:32 dgp Exp $ # package require tcltest 2 @@ -24,6 +24,7 @@ namespace import -force ::tcltest::* testConstraint testcmdtoken [llength [info commands testcmdtoken]] testConstraint testcmdtrace [llength [info commands testcmdtrace]] testConstraint testcreatecommand [llength [info commands testcreatecommand]] +testConstraint testevalex [llength [info commands testevalex]] testConstraint exec [llength [info commands exec]] # This variable needs to be changed when the major or minor version number for @@ -658,6 +659,25 @@ test basic-47.1 {Tcl_EvalEx: check for missing close-bracket} -body { subst {a[set b [format cd]} } -returnCodes error -result {missing close-bracket} +test basic-49.1 {Tcl_EvalEx: verify TCL_EVAL_GLOBAL operation} testevalex { + set ::x global + namespace eval ns { + variable x namespace + testevalex {set x changed} global + set ::result [list $::x $x] + } + namespace delete ns + set ::result +} {changed namespace} +test basic-49.2 {Tcl_EvalEx: verify TCL_EVAL_GLOBAL operation} testevalex { + set ::x global + namespace eval ns { + variable x namespace + testevalex {set ::context $x} global + } + namespace delete ns + set ::context +} {global} # cleanup catch {eval namespace delete [namespace children :: test_ns_*]} diff --git a/tests/compile.test b/tests/compile.test index 9a7b3b8..69d3d77 100644 --- a/tests/compile.test +++ b/tests/compile.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: compile.test,v 1.24.2.2 2004/03/15 20:34:13 msofer Exp $ +# RCS: @(#) $Id: compile.test,v 1.24.2.3 2004/10/26 20:14:36 dgp Exp $ package require tcltest 2 namespace import -force ::tcltest::* @@ -321,6 +321,64 @@ test compile-12.3 {check for a buffer overrun} { list [catch crash msg] $msg } {1 {syntax error in expression "a+2": variable references require preceding $}} +test compile-12.4 {TclCleanupLiteralTable segfault} { + # Tcl Bug 1001997 + # Here, we're trying to test a case that causes a crash in + # TclCleanupLiteralTable. The conditions that we're trying to + # establish are: + # - TclCleanupLiteralTable is attempting to clean up a bytecode + # object in the literal table. + # - The bytecode object in question contains the only reference + # to another literal. + # - The literal in question is in the same hash bucket as the bytecode + # object, and immediately follows it in the chain. + # Since newly registered literals are added at the FRONT of the + # bucket chains, and since the bytecode object is registered before + # its literals, this is difficult to achieve. What we do is: + # (a) do a [namespace eval] of a string that's calculated to + # hash into the same bucket as a literal that it contains. + # In this case, the script and the variable 'bugbug' + # land in the same bucket. + # (b) do a [namespace eval] of a string that contains enough + # literals to force TclRegisterLiteral to rebuild the global + # literal table. The newly created hash buckets will contain + # the literals, IN REVERSE ORDER, thus putting the bytecode + # immediately ahead of 'bugbug' and 'bug4345bug'. The bytecode + # object will contain the only references to those two literals. + # (c) Delete the interpreter to invoke TclCleanupLiteralTable + # and tickle the bug. + proc foo {} { + set i [interp create] + $i eval { + namespace eval ::w {concat 4649; variable bugbug} + namespace eval ::w { + concat x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 \ + x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 \ + x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 \ + x31 x32 X33 X34 X35 X36 X37 X38 X39 X40 \ + x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 \ + x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 \ + x61 x62 x63 x64 + concat y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 \ + y11 y12 y13 y14 y15 y16 y17 y18 y19 y20 \ + y21 y22 y23 y24 y25 y26 y27 y28 y29 y30 \ + y31 y32 Y33 Y34 Y35 Y36 Y37 Y38 Y39 Y40 \ + y41 y42 y43 y44 y45 y46 y47 y48 y49 y50 \ + y51 y52 y53 y54 y55 y56 y57 y58 y59 y60 \ + y61 y62 y63 y64 + concat z1 z2 z3 z4 z5 z6 z7 z8 z9 z10 \ + z11 z12 z13 z14 z15 z16 z17 z18 z19 z20 \ + z21 z22 z23 z24 z25 z26 z27 z28 z29 z30 \ + z31 z32 + } + } + interp delete $i; # must not crash + return ok + } + foo +} ok + + # Special test for underestimating the maxStackSize required for a # compiled command. A failure will cause a segfault in the child # process. diff --git a/tests/error.test b/tests/error.test index 1d5f9a0..737faa4 100644 --- a/tests/error.test +++ b/tests/error.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: error.test,v 1.9 2002/01/29 03:03:02 hobbs Exp $ +# RCS: @(#) $Id: error.test,v 1.9.2.1 2004/10/26 20:14:36 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -176,6 +176,30 @@ test error-6.1 {catch must reset error state} { catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]} list $errorCode $errorInfo } {NONE 1} +test error-6.3 {catch must reset error state} { + set errorCode BUG + catch {error outer [catch set]} + list $errorCode $errorInfo +} {NONE 1} +test error-6.4 {catch must reset error state} { + catch {error [catch {error foo bar baz}] 1} + list $errorCode $errorInfo +} {NONE 1} +test error-6.7 {catch must reset error state} { + proc foo {} { + return -code error -errorinfo [catch {error foo bar baz}] + } + catch foo + list $errorCode +} {NONE} +test error-6.9 {catch must reset error state} { + proc foo {} { + return -code error [catch {error foo bar baz}] + } + catch foo + list $errorCode +} {NONE} + # cleanup catch {rename p ""} diff --git a/tests/init.test b/tests/init.test index 67a23a6..db97c35 100644 --- a/tests/init.test +++ b/tests/init.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: init.test,v 1.9.2.1 2003/07/18 23:35:39 dgp Exp $ +# RCS: @(#) $Id: init.test,v 1.9.2.2 2004/10/26 20:14:36 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -125,17 +125,16 @@ test init-2.7 {oad setLogCmd from safe:: - stage 2} { } {} -auto_reset -package require http 2.0 -catch {rename ::http::geturl {}} -test init-2.8 {load http::geturl (package)} { +test init-2.8 {load tcl::HistAdd} -setup { + auto_reset + catch {rename ::tcl::HistAdd {}} +} -body { # 3 ':' on purpose - set ret [catch {http:::geturl} error] - # removing it, for the next test. should not fail. - rename ::http::geturl {} ; - list $ret $error -} {1 {wrong # args: should be "http:::geturl url args"}} + list [catch {tcl:::HistAdd} error] $error +} -cleanup { + rename ::tcl::HistAdd {} ; +} -result {1 {wrong # args: should be "tcl:::HistAdd command ?exec?"}} test init-3.0 {random stuff in the auto_index, should still work} { diff --git a/tests/namespace.test b/tests/namespace.test index daa6ecd..542f137 100644 --- a/tests/namespace.test +++ b/tests/namespace.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: namespace.test,v 1.21.2.3 2004/09/30 22:45:17 dgp Exp $ +# RCS: @(#) $Id: namespace.test,v 1.21.2.4 2004/10/26 20:14:36 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -211,6 +211,13 @@ test namespace-8.6 {TclTeardownNamespace: preserve errorInfo; errorCode values} } {bar invoked from within "slave eval error foo bar baz"} +test namespace-8.7 {TclTeardownNamespace: preserve errorInfo; errorCode values} { + interp create slave + slave eval {trace add execution error leave {namespace delete :: ;#}} + catch {slave eval error foo bar baz} + interp delete slave + set ::errorCode +} baz test namespace-9.1 {Tcl_Import, empty import pattern} { catch {eval namespace delete [namespace children :: test_ns_*]} diff --git a/tests/tcltest.test b/tests/tcltest.test index 42797fa..90a87af 100755 --- a/tests/tcltest.test +++ b/tests/tcltest.test @@ -6,7 +6,7 @@ # Copyright (c) 2000 by Ajuba Solutions # All rights reserved. # -# RCS: @(#) $Id: tcltest.test,v 1.37.2.4 2004/05/26 16:24:38 dgp Exp $ +# RCS: @(#) $Id: tcltest.test,v 1.37.2.5 2004/10/26 20:14:37 dgp Exp $ # Note that there are several places where the value of # tcltest::currentFailure is stored/reset in the -setup/-cleanup @@ -822,6 +822,7 @@ test tcltest-12.2 {-loadfile load.tcl} {unixOrPc} { test tcltest-12.3 {loadScript} { -setup { set old $::tcltest::loadScript + set ::tcltest::loadScript {} } -body { set f1 [loadScript] @@ -838,6 +839,7 @@ test tcltest-12.3 {loadScript} { test tcltest-12.4 {loadFile} { -setup { set olds $::tcltest::loadScript + set ::tcltest::loadScript {} set oldf $::tcltest::loadFile set ::tcltest::loadFile {} } diff --git a/tests/timer.test b/tests/timer.test index 2b9c9c5..cd76ef0 100644 --- a/tests/timer.test +++ b/tests/timer.test @@ -13,10 +13,10 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: timer.test,v 1.7 2000/04/10 17:19:05 ericm Exp $ +# RCS: @(#) $Id: timer.test,v 1.7.22.1 2004/10/26 20:14:51 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { - package require tcltest + package require tcltest 2 namespace import -force ::tcltest::* } @@ -537,6 +537,17 @@ test timer-9.1 {AfterCleanupProc procedure} { update set x } {before after2 after4} +test timer-10.1 {Bug 1016167: [after] overwrites imports} -setup { + interp create slave + slave eval namespace export after + slave eval namespace eval foo namespace import ::after +} -body { + slave eval foo::after 1 + slave eval namespace origin foo::after +} -cleanup { + # Bug will cause crash here; would cause failure otherwise + interp delete slave +} -result ::after # cleanup ::tcltest::cleanupTests -- cgit v0.12