summaryrefslogtreecommitdiffstats
path: root/generic/tclNamesp.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2004-09-30 23:06:47 (GMT)
committerdgp <dgp@users.sourceforge.net>2004-09-30 23:06:47 (GMT)
commita5b7e1af2aad6b044ed0c093d8f4d27f68f1497a (patch)
tree80cd1a43eaad19a6b5ca302dc244897f6602805b /generic/tclNamesp.c
parent36fd8cc0959204088d97c32156f269faaaca2402 (diff)
downloadtcl-a5b7e1af2aad6b044ed0c093d8f4d27f68f1497a.zip
tcl-a5b7e1af2aad6b044ed0c093d8f4d27f68f1497a.tar.gz
tcl-a5b7e1af2aad6b044ed0c093d8f4d27f68f1497a.tar.bz2
* generic/tclBasic.c (Tcl_AddObjErrorInfo): More re-organization
* generic/tclCmdAH.c (Tcl_ErrorObjCmd): of the management of * generic/tclCmdMZ.c (TclProcessReturn): the errorCode value. * tests/error.test (error-6.4-9): * generic/tclNamespace.c (TclTeardownNamespace): Tcl_Obj-ified * tests/namespace.test (namespace-8.5,6): the save/restore of ::errorInfo and ::errorCode during global namespace teardown. Revised the comment to clarify why this is done, and added tests that will fail if this is not done. * generic/tclResult.c (TclTransferResult): Added safety checks so that unexpected undefined ::errorInfo or ::errorCode will not lead to a segfault. * generic/tclTrace.c (TclCallVarTraces): Save/restore the flag * tests/var.test (var-16.1): values that define part of the interpreter state during variable traces. [Bug 10381021].
Diffstat (limited to 'generic/tclNamesp.c')
-rw-r--r--generic/tclNamesp.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 9238001..9c7e7c2 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -21,7 +21,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclNamesp.c,v 1.56 2004/09/29 22:17:30 dkf Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.57 2004/09/30 23:06:48 dgp Exp $
*/
#include "tclInt.h"
@@ -860,45 +860,37 @@ TclTeardownNamespace(nsPtr)
if (nsPtr == globalNsPtr) {
/*
- * This is the global namespace, so be careful to preserve the
- * "errorInfo" and "errorCode" variables. These might be needed
- * later on if errors occur while deleting commands. We are careful
- * to destroy and recreate the "errorInfo" and "errorCode"
- * variables, in case they had any traces on them.
+ * This is the global namespace. Tearing it down will destroy the
+ * ::errorInfo and ::errorCode variables. We save and restore them
+ * in case there are any errors in progress, so the error details
+ * they contain will not be lost. See test namespace-8.5
*/
- CONST char *str;
- char *errorInfoStr, *errorCodeStr;
-
- str = Tcl_GetVar((Tcl_Interp *) iPtr, "errorInfo", TCL_GLOBAL_ONLY);
- if (str != NULL) {
- errorInfoStr = ckalloc((unsigned) (strlen(str)+1));
- strcpy(errorInfoStr, str);
- } else {
- errorInfoStr = NULL;
- }
-
- str = Tcl_GetVar((Tcl_Interp *) iPtr, "errorCode", TCL_GLOBAL_ONLY);
- if (str != NULL) {
- errorCodeStr = ckalloc((unsigned) (strlen(str)+1));
- strcpy(errorCodeStr, str);
- } else {
- errorCodeStr = NULL;
- }
-
- TclDeleteVars(iPtr, &nsPtr->varTable);
- Tcl_InitHashTable(&nsPtr->varTable, TCL_STRING_KEYS);
+ Tcl_Obj *errorInfo = Tcl_GetVar2Ex(nsPtr->interp, "errorInfo",
+ NULL, TCL_GLOBAL_ONLY);
+ Tcl_Obj *errorCode = Tcl_GetVar2Ex(nsPtr->interp, "errorCode",
+ NULL, TCL_GLOBAL_ONLY);
+
+ if (errorInfo) {
+ Tcl_IncrRefCount(errorInfo);
+ }
+ if (errorCode) {
+ Tcl_IncrRefCount(errorCode);
+ }
- if (errorInfoStr != NULL) {
- Tcl_SetVar((Tcl_Interp *) iPtr, "errorInfo", errorInfoStr,
- TCL_GLOBAL_ONLY);
- ckfree(errorInfoStr);
- }
- if (errorCodeStr != NULL) {
- Tcl_SetVar((Tcl_Interp *) iPtr, "errorCode", errorCodeStr,
- TCL_GLOBAL_ONLY);
- ckfree(errorCodeStr);
- }
+ TclDeleteVars(iPtr, &nsPtr->varTable);
+ Tcl_InitHashTable(&nsPtr->varTable, TCL_STRING_KEYS);
+
+ if (errorInfo) {
+ Tcl_SetVar2Ex(nsPtr->interp, "errorInfo", NULL,
+ errorInfo, TCL_GLOBAL_ONLY);
+ Tcl_DecrRefCount(errorInfo);
+ }
+ if (errorCode) {
+ Tcl_SetVar2Ex(nsPtr->interp, "errorCode", NULL,
+ errorCode, TCL_GLOBAL_ONLY);
+ Tcl_DecrRefCount(errorCode);
+ }
} else {
/*
* Variable table should be cleared but not freed! TclDeleteVars