diff options
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | generic/tclEvent.c | 78 | ||||
-rw-r--r-- | generic/tclProc.c | 6 | ||||
-rw-r--r-- | generic/tclResult.c | 13 | ||||
-rw-r--r-- | tests/event.test | 41 | ||||
-rw-r--r-- | tests/init.test | 4 |
6 files changed, 117 insertions, 47 deletions
@@ -1,3 +1,25 @@ +2007-09-07 Don Porter <dgp@users.sourceforge.net> + + * generic/tclEvent.c ([::tcl::Bgerror]): Corrections to Tcl's + * tests/event.test: default [interp bgerror] handler so that when + it falls back to a hidden [bgerror] in a safe interp, it gets the + right error context data. [Bug 1790274]. + +2007-09-07 Miguel Sofer <msofer@users.sf.net> + + * generic/tclProc.c (TclInitCompiledLocals): the refCount of + resolved variables was being managed without checking if they were + Var or VarInHash: itcl [Bug 1790184] + +2007-09-06 Don Porter <dgp@users.sourceforge.net> + + * generic/tclResult.c (Tcl_GetReturnOptions): Take care that a + * tests/init.test: non-TCL_ERROR code doesn't cause existing + -errorinfo, -errorcode, and -errorline entries to be omitted. + * generic/tclEvent.c: With -errorInfo no longer lost, generate more + complete ::errorInfo when calling [bgerror] after a non-TCL_ERROR + background exception. + 2007-09-06 Don Porter <dgp@users.sourceforge.net> * generic/tclInterp.c (Tcl_Init): Removed constraint on ability diff --git a/generic/tclEvent.c b/generic/tclEvent.c index e0b4866..a98cec1 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEvent.c,v 1.72.2.2 2007/09/06 18:20:30 dgp Exp $ + * RCS: @(#) $Id: tclEvent.c,v 1.72.2.3 2007/09/07 20:20:55 dgp Exp $ */ #include "tclInt.h" @@ -310,6 +310,7 @@ TclDefaultBgErrorHandlerObjCmd( Tcl_Obj *keyPtr, *valuePtr; Tcl_Obj *tempObjv[2]; int code, level; + Tcl_InterpState saved; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "msg options"); @@ -356,38 +357,40 @@ TclDefaultBgErrorHandlerObjCmd( tempObjv[1] = Tcl_ObjPrintf("command returned bad code: %d", code); break; } - if (code == TCL_ERROR) { - /* - * Restore important state variables to what they were at the time - * the error occurred. - * - * Need to set the variables, not the interp fields, because - * Tcl_EvalObjv calls Tcl_ResetResult which would destroy - * anything we write to the interp fields. - */ + Tcl_IncrRefCount(tempObjv[1]); - TclNewLiteralStringObj(keyPtr, "-errorcode"); - Tcl_IncrRefCount(keyPtr); - Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); - if (valuePtr) { - Tcl_SetVar2Ex(interp, "errorCode", NULL, valuePtr, TCL_GLOBAL_ONLY); - } + if (code != TCL_ERROR) { + Tcl_SetObjResult(interp, tempObjv[1]); + } - TclNewLiteralStringObj(keyPtr, "-errorinfo"); - Tcl_IncrRefCount(keyPtr); - Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); - if (valuePtr) { - Tcl_SetVar2Ex(interp, "errorInfo", NULL, valuePtr, TCL_GLOBAL_ONLY); - } - } else { - Tcl_AppendObjToErrorInfo(interp, Tcl_DuplicateObj(tempObjv[1])); + TclNewLiteralStringObj(keyPtr, "-errorcode"); + Tcl_IncrRefCount(keyPtr); + Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); + Tcl_DecrRefCount(keyPtr); + if (valuePtr) { + Tcl_SetObjErrorCode(interp, valuePtr); + } + + TclNewLiteralStringObj(keyPtr, "-errorinfo"); + Tcl_IncrRefCount(keyPtr); + Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); + Tcl_DecrRefCount(keyPtr); + if (valuePtr) { + Tcl_IncrRefCount(valuePtr); + Tcl_AppendObjToErrorInfo(interp, valuePtr); + } + + if (code == TCL_ERROR) { + Tcl_SetObjResult(interp, tempObjv[1]); } - Tcl_IncrRefCount(tempObjv[1]); - valuePtr = Tcl_GetVar2Ex(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY); - Tcl_IncrRefCount(valuePtr); + /* + * Save interpreter state so we can restore it if multiple handler + * attempts are needed. + */ + + saved = Tcl_SaveInterpState(interp, code); + /* Invoke the bgerror command. */ Tcl_AllowExceptions(interp); code = Tcl_EvalObjv(interp, 2, tempObjv, TCL_EVAL_GLOBAL); @@ -403,7 +406,7 @@ TclDefaultBgErrorHandlerObjCmd( */ if (Tcl_IsSafe(interp)) { - Tcl_ResetResult(interp); + Tcl_RestoreInterpState(interp, saved); TclObjInvoke(interp, 2, tempObjv, TCL_INVOKE_HIDDEN); } else { Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); @@ -413,11 +416,12 @@ TclDefaultBgErrorHandlerObjCmd( Tcl_IncrRefCount(resultPtr); if (Tcl_FindCommand(interp, "bgerror", NULL, TCL_GLOBAL_ONLY) == NULL) { - if (valuePtr) { - Tcl_WriteObj(errChannel, valuePtr); - Tcl_WriteChars(errChannel, "\n", -1); - } + Tcl_RestoreInterpState(interp, saved); + Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp, + "errorInfo", NULL, TCL_GLOBAL_ONLY)); + Tcl_WriteChars(errChannel, "\n", -1); } else { + Tcl_DiscardInterpState(saved); Tcl_WriteChars(errChannel, "bgerror failed to handle background error.\n",-1); Tcl_WriteChars(errChannel, " Original error: ", -1); @@ -429,11 +433,15 @@ TclDefaultBgErrorHandlerObjCmd( } Tcl_DecrRefCount(resultPtr); Tcl_Flush(errChannel); + } else { + Tcl_DiscardInterpState(saved); } } code = TCL_OK; + } else { + Tcl_DiscardInterpState(saved); } - Tcl_DecrRefCount(valuePtr); + Tcl_DecrRefCount(tempObjv[0]); Tcl_DecrRefCount(tempObjv[1]); Tcl_ResetResult(interp); diff --git a/generic/tclProc.c b/generic/tclProc.c index c0a6d8e..27e9ac9 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.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: tclProc.c,v 1.115.2.9 2007/09/04 17:43:53 dgp Exp $ + * RCS: @(#) $Id: tclProc.c,v 1.115.2.10 2007/09/07 20:20:55 dgp Exp $ */ #include "tclInt.h" @@ -1204,7 +1204,9 @@ InitResolvedLocals( Var *resolvedVarPtr = (Var *) (*resVarInfo->fetchProc)(interp, resVarInfo); if (resolvedVarPtr) { - VarHashRefCount(resolvedVarPtr)++; + if (TclIsVarInHash(resolvedVarPtr)) { + VarHashRefCount(resolvedVarPtr)++; + } varPtr->flags = VAR_LINK; varPtr->value.linkPtr = resolvedVarPtr; } diff --git a/generic/tclResult.c b/generic/tclResult.c index a9b2b070..eaaa61d 100644 --- a/generic/tclResult.c +++ b/generic/tclResult.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclResult.c,v 1.36.2.1 2007/06/05 18:12:42 dgp Exp $ + * RCS: @(#) $Id: tclResult.c,v 1.36.2.2 2007/09/07 20:20:55 dgp Exp $ */ #include "tclInt.h" @@ -1452,14 +1452,13 @@ Tcl_GetReturnOptions( } if (result == TCL_ERROR) { - /* - * When result was an error, fill in any missing values for - * -errorinfo, -errorcode, and -errorline. - */ - Tcl_AddObjErrorInfo(interp, "", -1); - Tcl_DictObjPut(NULL, options, keys[KEY_ERRORINFO], iPtr->errorInfo); + } + if (iPtr->errorCode) { Tcl_DictObjPut(NULL, options, keys[KEY_ERRORCODE], iPtr->errorCode); + } + if (iPtr->errorInfo) { + Tcl_DictObjPut(NULL, options, keys[KEY_ERRORINFO], iPtr->errorInfo); Tcl_DictObjPut(NULL, options, keys[KEY_ERRORLINE], Tcl_NewIntObj(iPtr->errorLine)); } diff --git a/tests/event.test b/tests/event.test index 101a17e..4cae5ac 100644 --- a/tests/event.test +++ b/tests/event.test @@ -9,7 +9,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: event.test,v 1.24 2007/03/12 19:28:50 dgp Exp $ +# RCS: @(#) $Id: event.test,v 1.24.2.1 2007/09/07 20:20:55 dgp Exp $ package require tcltest 2 namespace import -force ::tcltest::* @@ -304,6 +304,45 @@ test event-7.5 {correct behaviour when there is no bgerror [Bug 219142]} {exec} "error hello" ("after" script)}} +test event-7.6 {safe hidden bgerror fallback} { + variable result {} + interp create -safe safe + safe alias puts puts + safe alias result ::append [namespace which -variable result] + safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} + safe hide bgerror + safe eval after 0 error foo + update + interp delete safe + set result +} {foo +NONE +foo + while executing +"error foo" + ("after" script) +} + +test event-7.7 {safe hidden bgerror fallback} { + variable result {} + interp create -safe safe + safe alias puts puts + safe alias result ::append [namespace which -variable result] + safe eval {proc bgerror m {result $m\n$::errorCode\n$::errorInfo\n}} + safe hide bgerror + safe eval {proc bgerror m {error bar soom baz}} + safe eval after 0 error foo + update + interp delete safe + set result +} {foo +NONE +foo + while executing +"error foo" + ("after" script) +} + # someday : add a test checking that # when there is no bgerror, an error msg goes to stderr diff --git a/tests/init.test b/tests/init.test index da94d67..661cb27 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.15 2006/11/03 00:34:52 hobbs Exp $ +# RCS: @(#) $Id: init.test,v 1.15.2.1 2007/09/07 20:20:55 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -207,7 +207,7 @@ test init-5.0 {return options passed through ::unknown} -setup { list $code $foo $bar $code2 $foo2 $bar2 } -cleanup { unset ::auto_index(::xxx) -} -result {2 xxx {-code 1 -level 1} 2 xxx {-code 1 -level 1}} +} -result {2 xxx {-code 1 -level 1 -errorcode NONE} 2 xxx {-code 1 -level 1 -errorcode NONE}} cleanupTests } ;# End of [interp eval $testInterp] |