Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.331
diff -u -r1.331 tclExecute.c
--- generic/tclExecute.c	9 Sep 2007 16:51:19 -0000	1.331
+++ generic/tclExecute.c	9 Sep 2007 19:05:42 -0000
@@ -3107,7 +3107,7 @@
 	    Tcl_Namespace *nsPtr, *savedNsPtr;
 
 	    result = TclGetNamespaceFromObj(interp, OBJ_UNDER_TOS, &nsPtr);
-	    if ((result == TCL_OK) && nsPtr) {
+	    if (result == TCL_OK) {
 		/*
 		 * Locate the other variable.
 		 */
@@ -3119,18 +3119,9 @@
 			/*createPart1*/ 1, /*createPart2*/ 1, &varPtr);
 		iPtr->varFramePtr->nsPtr = (Namespace *) savedNsPtr;
 		if (otherPtr) {
-		    result = TCL_OK;
 		    goto doLinkVars;
 		}
 	    }
-	    if (!nsPtr) {
-		/*
-		 * The namespace does not exist, leave an error message.
-		 */
-
-		Tcl_SetObjResult(interp, Tcl_Format(NULL,
-			"namespace \"%s\" does not exist", 1,&OBJ_UNDER_TOS));
-	    }
 	    result = TCL_ERROR;
 	    goto checkForCatch;
 	}
Index: generic/tclInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclInt.h,v
retrieving revision 1.333
diff -u -r1.333 tclInt.h
--- generic/tclInt.h	23 Aug 2007 00:27:15 -0000	1.333
+++ generic/tclInt.h	9 Sep 2007 19:05:43 -0000
@@ -2283,7 +2283,6 @@
 MODULE_SCOPE Tcl_ObjType tclProcBodyType;
 MODULE_SCOPE Tcl_ObjType tclStringType;
 MODULE_SCOPE Tcl_ObjType tclArraySearchType;
-MODULE_SCOPE Tcl_ObjType tclNsNameType;
 MODULE_SCOPE Tcl_ObjType tclEnsembleCmdType;
 #ifndef NO_WIDE_TYPE
 MODULE_SCOPE Tcl_ObjType tclWideIntType;
Index: generic/tclNamesp.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclNamesp.c,v
retrieving revision 1.148
diff -u -r1.148 tclNamesp.c
--- generic/tclNamesp.c	3 Aug 2007 13:51:40 -0000	1.148
+++ generic/tclNamesp.c	9 Sep 2007 19:05:44 -0000
@@ -13,6 +13,7 @@
  * Copyright (c) 1998-1999 by Scriptics Corporation.
  * Copyright (c) 2002-2005 Donal K. Fellows.
  * Copyright (c) 2006 Neil Madden.
+ * Contributions from Don Porter, NIST, 2007. (not subject to US copyright)
  *
  * Originally implemented by
  *   Michael J. McLennan
@@ -54,15 +55,12 @@
  */
 
 typedef struct ResolvedNsName {
-    Namespace *nsPtr;		/* A cached namespace pointer. */
-    long nsId;			/* nsPtr's unique namespace id. Used to verify
-				 * that nsPtr is still valid (e.g., it's
-				 * possible that the namespace was deleted and
-				 * a new one created at the same address). */
-    Namespace *refNsPtr;	/* Points to the namespace containing the
-				 * reference (not the namespace that contains
-				 * the referenced namespace). NULL if the name
-				 * is fully qualified.*/
+    Namespace *nsPtr;          /* A cached pointer to the Namespace that the
+                                * name resolved to. */
+    Namespace *refNsPtr;       /* Points to the namespace context in which
+                                * the name was resolved.  NULL if the name
+                                * is fully qualified and thus the resolution
+                                * does not depend on the context. */
     int refCount;		/* Reference count: 1 for each nsName object
 				 * that has a pointer to this ResolvedNsName
 				 * structure as its internal rep. This
@@ -167,6 +165,8 @@
 			    Tcl_Interp *interp, const char *name1,
 			    const char *name2, int flags);
 static void		FreeNsNameInternalRep(Tcl_Obj *objPtr);
+static int		GetNamespaceFromObj(Tcl_Interp *interp,
+			    Tcl_Obj *objPtr, Tcl_Namespace **nsPtrPtr);
 static int		InvokeImportedCmd(ClientData clientData,
 			    Tcl_Interp *interp,int objc,Tcl_Obj *const objv[]);
 static int		NamespaceChildrenCmd(ClientData dummy,
@@ -210,7 +210,6 @@
 static int		NamespaceWhichCmd(ClientData dummy, Tcl_Interp *interp,
 			    int objc, Tcl_Obj *const objv[]);
 static int		SetNsNameFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
-static void		UpdateStringOfNsName(Tcl_Obj *objPtr);
 static int		NsEnsembleImplementationCmd(ClientData clientData,
 			    Tcl_Interp *interp,int objc,Tcl_Obj *const objv[]);
 static void		BuildEnsembleConfig(EnsembleConfig *ensemblePtr);
@@ -232,11 +231,11 @@
  * the object.
  */
 
-Tcl_ObjType tclNsNameType = {
+static Tcl_ObjType nsNameType = {
     "nsName",			/* the type's name */
     FreeNsNameInternalRep,	/* freeIntRepProc */
     DupNsNameInternalRep,	/* dupIntRepProc */
-    UpdateStringOfNsName,	/* updateStringProc */
+    NULL,			/* updateStringProc */
     SetNsNameFromAny		/* setFromAnyProc */
 };
 
@@ -381,6 +380,15 @@
 	nsPtr = (Namespace *) TclGetCurrentNamespace(interp);
     } else {
 	nsPtr = (Namespace *) namespacePtr;
+	/*
+	 * TODO: Examine whether it would be better to guard based
+	 * on NS_DYING or NS_KILLED.  It appears that these are not
+	 * tested because they can be set in a global interp that
+	 * has been [namespace delete]d, but which never really
+	 * completely goes away because of lingering global things
+	 * like ::errorInfo and [::unknown] and hidden commands.
+	 * Review of those designs might permit stricter checking here.
+	 */
 	if (nsPtr->flags & NS_DEAD) {
 	    Tcl_Panic("Trying to push call frame for dead namespace");
 	    /*NOTREACHED*/
@@ -2411,7 +2419,7 @@
 		&simpleName);
 	if ((realNsPtr != NULL) && (simpleName != NULL)) {
 	    if ((cxtNsPtr == realNsPtr)
-		    || !(realNsPtr->flags & (NS_DEAD|NS_DYING))) {
+		    || !(realNsPtr->flags & NS_DYING)) {
 		entryPtr = Tcl_FindHashEntry(&realNsPtr->cmdTable, simpleName);
 		if (entryPtr != NULL) {
 		    cmdPtr = (Command *) Tcl_GetHashValue(entryPtr);
@@ -2432,7 +2440,7 @@
 		    TCL_NAMESPACE_ONLY, &realNsPtr, &dummyNsPtr, &dummyNsPtr,
 		    &simpleName);
 	    if ((realNsPtr != NULL) && (simpleName != NULL)
-		    && !(realNsPtr->flags & (NS_DEAD|NS_DYING))) {
+		    && !(realNsPtr->flags & NS_DYING)) {
 		entryPtr = Tcl_FindHashEntry(&realNsPtr->cmdTable, simpleName);
 		if (entryPtr != NULL) {
 		    cmdPtr = (Command *) Tcl_GetHashValue(entryPtr);
@@ -2450,7 +2458,7 @@
 		    TCL_GLOBAL_ONLY, &realNsPtr, &dummyNsPtr, &dummyNsPtr,
 		    &simpleName);
 	    if ((realNsPtr != NULL) && (simpleName != NULL)
-		    && !(realNsPtr->flags & (NS_DEAD|NS_DYING))) {
+		    && !(realNsPtr->flags & NS_DYING)) {
 		entryPtr = Tcl_FindHashEntry(&realNsPtr->cmdTable, simpleName);
 		if (entryPtr != NULL) {
 		    cmdPtr = (Command *) Tcl_GetHashValue(entryPtr);
@@ -2658,50 +2666,49 @@
 				 * namespace. */
     Tcl_Namespace **nsPtrPtr)	/* Result namespace pointer goes here. */
 {
-    ResolvedNsName *resPtr;
-    Namespace *nsPtr;
-    int result = TCL_OK;
-
-    /*
-     * Get the internal representation, converting to a namespace type if
-     * needed. The internal representation is a ResolvedNsName that points to
-     * the actual namespace.
-     *
-     * Check the context namespace of the resolved symbol to make sure that it
-     * is fresh. Note that we verify that the namespace id of the context
-     * namespace is the same as the one we cached; this insures that the
-     * namespace wasn't deleted and a new one created at the same address.
-     * Note that fully qualified names have a NULL refNsPtr, these checks
-     * needn't be made.
-     *
-     * If any check fails, then force another conversion to the command type,
-     * to discard the old rep and create a new one.
-     */
-
-    resPtr = (ResolvedNsName *) objPtr->internalRep.twoPtrValue.ptr1;
-    if ((objPtr->typePtr != &tclNsNameType)
-	    || (resPtr == NULL)
-	    || (resPtr->refNsPtr &&
-		    (resPtr->refNsPtr != (Namespace *) TclGetCurrentNamespace(interp)))
-	    || (nsPtr = resPtr->nsPtr, nsPtr->flags & NS_DEAD)
-	    || (interp != nsPtr->interp)
-	    || (resPtr->nsId != nsPtr->nsId)) {
-
-	result = tclNsNameType.setFromAnyProc(interp, objPtr);
-
-	resPtr = (ResolvedNsName *) objPtr->internalRep.twoPtrValue.ptr1;
-	if ((result == TCL_OK) && resPtr) {
-	    nsPtr = resPtr->nsPtr;
-	    if (nsPtr && (nsPtr->flags & NS_DEAD)) {
-		nsPtr = NULL;
-	    }
+    if (GetNamespaceFromObj(interp, objPtr, nsPtrPtr) == TCL_ERROR) {
+	const char *name = Tcl_GetString(objPtr);
+	if ((name[0] == ':') && (name[1] == ':')) {
+	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+		    "namespace \"%s\" not found", name));
 	} else {
-	    nsPtr = NULL;
+	    /* Get the current namespace name */
+	    NamespaceCurrentCmd(NULL, interp, 2, NULL);
+	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+		    "namespace \"%s\" not found in \"%s\"", name,
+		    Tcl_GetStringResult(interp)));
 	}
+	return TCL_ERROR;
     }
+    return TCL_OK;
+}
+static int
+GetNamespaceFromObj(
+    Tcl_Interp *interp,		/* The current interpreter. */
+    Tcl_Obj *objPtr,		/* The object to be resolved as the name of a
+				 * namespace. */
+    Tcl_Namespace **nsPtrPtr)	/* Result namespace pointer goes here. */
+{
+    ResolvedNsName *resNamePtr;
+    Namespace *nsPtr;
 
-    *nsPtrPtr = (Tcl_Namespace *) nsPtr;
-    return result;
+    if (objPtr->typePtr == &nsNameType) {
+	/* Check that the ResolvedNsName is still valid. */
+	resNamePtr = (ResolvedNsName *) objPtr->internalRep.twoPtrValue.ptr1;
+	nsPtr = resNamePtr->nsPtr;
+	if (!(nsPtr->flags & NS_DYING)
+		&& ((resNamePtr->refNsPtr == NULL) || (resNamePtr->refNsPtr
+		== (Namespace *) Tcl_GetCurrentNamespace(interp)))) {
+	    *nsPtrPtr = (Tcl_Namespace *) nsPtr;
+	    return TCL_OK;
+	}
+    }
+    if (SetNsNameFromAny(interp, objPtr) == TCL_OK) {
+	resNamePtr = (ResolvedNsName *) objPtr->internalRep.twoPtrValue.ptr1;
+	*nsPtrPtr = (Tcl_Namespace *) resNamePtr->nsPtr;
+	return TCL_OK;
+    }
+    return TCL_ERROR;
 }
 
 /*
@@ -2889,12 +2896,6 @@
 	if (TclGetNamespaceFromObj(interp, objv[2], &namespacePtr) != TCL_OK) {
 	    return TCL_ERROR;
 	}
-	if (namespacePtr == NULL) {
-	    Tcl_AppendResult(interp, "unknown namespace \"",
-		    TclGetString(objv[2]),
-		    "\" in namespace children command", NULL);
-	    return TCL_ERROR;
-	}
 	nsPtr = (Namespace *) namespacePtr;
     } else {
 	Tcl_WrongNumArgs(interp, 2, objv, "?name? ?pattern?");
@@ -3229,16 +3230,13 @@
      * namespace object along the way.
      */
 
-    result = TclGetNamespaceFromObj(interp, objv[2], &namespacePtr);
-    if (result != TCL_OK) {
-	return result;
-    }
+    result = GetNamespaceFromObj(interp, objv[2], &namespacePtr);
 
     /*
      * If the namespace wasn't found, try to create it.
      */
 
-    if (namespacePtr == NULL) {
+    if (result == TCL_ERROR) {
 	char *name = TclGetString(objv[2]);
 	namespacePtr = Tcl_CreateNamespace(interp, name, (ClientData) NULL,
 		NULL);
@@ -3341,15 +3339,8 @@
 	return TCL_ERROR;
     }
 
-    /*
-     * Check whether the given namespace exists
-     */
-
-    if (TclGetNamespaceFromObj(interp, objv[2], &namespacePtr) != TCL_OK) {
-	return TCL_ERROR;
-    }
-
-    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(namespacePtr != NULL));
+    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
+	    GetNamespaceFromObj(interp, objv[2], &namespacePtr) == TCL_OK));
     return TCL_OK;
 }
 
@@ -3682,11 +3673,6 @@
     if (result != TCL_OK) {
 	return result;
     }
-    if (namespacePtr == NULL) {
-	Tcl_AppendResult(interp, "unknown namespace \"", TclGetString(objv[2]),
-		"\" in inscope namespace command", NULL);
-	return TCL_ERROR;
-    }
 
     /*
      * Make the specified namespace the current namespace.
@@ -3856,12 +3842,6 @@
 	if (result != TCL_OK) {
 	    return result;
 	}
-	if (nsPtr == NULL) {
-	    Tcl_AppendResult(interp, "unknown namespace \"",
-		    TclGetString(objv[2]),
-		    "\" in namespace parent command", NULL);
-	    return TCL_ERROR;
-	}
     } else {
 	Tcl_WrongNumArgs(interp, 2, objv, "?name?");
 	return TCL_ERROR;
@@ -3957,11 +3937,6 @@
 		    &namespaceList[i]) != TCL_OK) {
 		goto badNamespace;
 	    }
-	    if (namespaceList[i] == NULL) {
-		Tcl_AppendResult(interp, "unknown namespace \"",
-			TclGetString(nsObjv[i]), "\"", NULL);
-		goto badNamespace;
-	    }
 	}
     }
 
@@ -4459,14 +4434,6 @@
     if (result != TCL_OK) {
 	return TCL_ERROR;
     }
-    if (nsPtr == NULL) {
-	/*
-	 * The namespace does not exist, leave an error message.
-	 */
-	Tcl_SetObjResult(interp, Tcl_Format(NULL,
-		"namespace \"%s\" does not exist", 1, objv+2));
-	return TCL_ERROR;
-    }
 
     objc -= 3;
     objv += 3;
@@ -4612,23 +4579,21 @@
      * references, free it up.
      */
 
-    if (resNamePtr != NULL) {
-	resNamePtr->refCount--;
-	if (resNamePtr->refCount == 0) {
+    resNamePtr->refCount--;
+    if (resNamePtr->refCount == 0) {
 
-	    /*
-	     * Decrement the reference count for the cached namespace. If the
-	     * namespace is dead, and there are no more references to it, free
-	     * it.
-	     */
+	/*
+	 * Decrement the reference count for the cached namespace. If the
+	 * namespace is dead, and there are no more references to it, free
+	 * it.
+	 */
 
-	    nsPtr = resNamePtr->nsPtr;
-	    nsPtr->refCount--;
-	    if ((nsPtr->refCount == 0) && (nsPtr->flags & NS_DEAD)) {
-		NamespaceFree(nsPtr);
-	    }
-	    ckfree((char *) resNamePtr);
+	nsPtr = resNamePtr->nsPtr;
+	nsPtr->refCount--;
+	if ((nsPtr->refCount == 0) && (nsPtr->flags & NS_DEAD)) {
+	    NamespaceFree(nsPtr);
 	}
+	ckfree((char *) resNamePtr);
     }
 }
 
@@ -4660,10 +4625,8 @@
 	    srcPtr->internalRep.twoPtrValue.ptr1;
 
     copyPtr->internalRep.twoPtrValue.ptr1 = (void *) resNamePtr;
-    if (resNamePtr != NULL) {
-	resNamePtr->refCount++;
-    }
-    copyPtr->typePtr = &tclNsNameType;
+    resNamePtr->refCount++;
+    copyPtr->typePtr = &nsNameType;
 }
 
 /*
@@ -4695,118 +4658,47 @@
 				 * NULL. */
     register Tcl_Obj *objPtr)	/* The object to convert. */
 {
-    char *name;
     const char *dummy;
     Namespace *nsPtr, *dummy1Ptr, *dummy2Ptr;
     register ResolvedNsName *resNamePtr;
+    const char *name = TclGetString(objPtr);
 
-    /*
-     * Look for the namespace "name" in the current namespace. If there is an
-     * error parsing the (possibly qualified) name, return an error. If the
-     * namespace isn't found, we convert the object to an nsName object with a
-     * NULL ResolvedNsName* internal rep.
-     */
-
-    name = TclGetString(objPtr);
     TclGetNamespaceForQualName(interp, name, NULL, TCL_FIND_ONLY_NS,
 	     &nsPtr, &dummy1Ptr, &dummy2Ptr, &dummy);
 
     /*
      * If we found a namespace, then create a new ResolvedNsName structure
      * that holds a reference to it.
-     *
-     * Free the old internalRep before setting the new one. Do this after
-     * getting the string rep to allow the conversion code (in particular,
-     * Tcl_GetStringFromObj) to use that old internalRep.
      */
 
-    if (nsPtr) {
+    if ((nsPtr != NULL) && !(nsPtr->flags & NS_DYING)) {
 	nsPtr->refCount++;
-	resNamePtr = (ResolvedNsName *) objPtr->internalRep.twoPtrValue.ptr1;
-	if ((objPtr->typePtr == &tclNsNameType)
-		&& resNamePtr && (resNamePtr->refCount == 1)) {
-	    /*
-	     * Reuse the old ResolvedNsName struct instead of freeing it
-	     */
-
-	    Namespace *oldNsPtr = resNamePtr->nsPtr;
-	    if ((--oldNsPtr->refCount == 0) && (oldNsPtr->flags & NS_DEAD)) {
-		NamespaceFree(oldNsPtr);
-	    }
-	} else {
-	    TclFreeIntRep(objPtr);
-	    resNamePtr = (ResolvedNsName *) ckalloc(sizeof(ResolvedNsName));
-	    resNamePtr->refCount = 1;
-	    objPtr->internalRep.twoPtrValue.ptr1 = (void *) resNamePtr;
-	    objPtr->typePtr = &tclNsNameType;
-	}
+	resNamePtr = (ResolvedNsName *) ckalloc(sizeof(ResolvedNsName));
 	resNamePtr->nsPtr = nsPtr;
-	resNamePtr->nsId = nsPtr->nsId;
-	if ((*name++ == ':') && (*name == ':')) {
+	if ((name[0] == ':') && (name[1] == ':')) {
 	    resNamePtr->refNsPtr = NULL;
 	} else {
 	    resNamePtr->refNsPtr =
-		(Namespace *) TclGetCurrentNamespace(interp);
+		    (Namespace *) Tcl_GetCurrentNamespace(interp);
 	}
-    } else {
+	resNamePtr->refCount = 1;
 	TclFreeIntRep(objPtr);
-	objPtr->internalRep.twoPtrValue.ptr1 = (void *) NULL;
-	objPtr->typePtr = &tclNsNameType;
-    }
-    return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * UpdateStringOfNsName --
- *
- *	Updates the string representation for a nsName object. Note: This
- *	function does not free an existing old string rep so storage will be
- *	lost if this has not already been done.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	The object's string is set to a copy of the fully qualified namespace
- *	name.
- *
- *----------------------------------------------------------------------
- */
-
-static void
-UpdateStringOfNsName(
-    register Tcl_Obj *objPtr)	/* nsName object with string rep to update. */
-{
-    ResolvedNsName *resNamePtr =
-	    (ResolvedNsName *) objPtr->internalRep.otherValuePtr;
-    char *name = "";
-    int length = 0;
-
-    if ((resNamePtr != NULL)
-	    && (resNamePtr->nsId == resNamePtr->nsPtr->nsId)) {
-	register Namespace *nsPtr = resNamePtr->nsPtr;
-
-	if (nsPtr != NULL && !(nsPtr->flags & NS_DEAD)) {
-	    name = nsPtr->fullName;
-	    length = strlen(name);
+	objPtr->internalRep.twoPtrValue.ptr1 = (void *) resNamePtr;
+	objPtr->typePtr = &nsNameType;
+	return TCL_OK;
+     } else {
+	if (objPtr->typePtr == &nsNameType) {
+	    /*
+	     * Our failed lookup proves any previously cached nsName
+	     * intrep is no longer valid.  Get rid of it so we no longer
+	     * waste memory storing it, nor time determining its invalidity
+	     * again and again.
+	     */
+	    TclFreeIntRep(objPtr);
+	    objPtr->typePtr = NULL;
 	}
+	return TCL_ERROR;
     }
-
-    /*
-     * The following sets the string rep to an empty string on the heap if the
-     * internal rep is NULL.
-     */
-
-    if (length == 0) {
-	objPtr->bytes = tclEmptyStringRep;
-    } else {
-	objPtr->bytes = (char *) ckalloc((unsigned) (length + 1));
-	memcpy(objPtr->bytes, name, (unsigned) length);
-	objPtr->bytes[length] = '\0';
-    }
-    objPtr->length = length;
 }
 
 /*
@@ -4861,7 +4753,7 @@
     int index;
 
     nsPtr = (Namespace *) TclGetCurrentNamespace(interp);
-    if (nsPtr == NULL || nsPtr->flags & NS_DEAD) {
+    if (nsPtr == NULL || nsPtr->flags & NS_DYING) {
 	if (!Tcl_InterpDeleted(interp)) {
 	    Tcl_AppendResult(interp,
 		    "tried to manipulate ensemble of deleted namespace", NULL);
@@ -5989,7 +5881,7 @@
     }
 
   restartEnsembleParse:
-    if (!(ensemblePtr->nsPtr->flags & NS_DEAD)) {
+    if (!(ensemblePtr->nsPtr->flags & NS_DYING)) {
 	if (ensemblePtr->epoch == ensemblePtr->nsPtr->exportLookupEpoch) {
 	    /*
 	     * Table of subcommands is still valid; therefore there might be a
Index: generic/tclObj.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclObj.c,v
retrieving revision 1.133
diff -u -r1.133 tclObj.c
--- generic/tclObj.c	3 Sep 2007 01:36:54 -0000	1.133
+++ generic/tclObj.c	9 Sep 2007 19:05:44 -0000
@@ -360,7 +360,6 @@
     Tcl_RegisterObjType(&tclDictType);
     Tcl_RegisterObjType(&tclByteCodeType);
     Tcl_RegisterObjType(&tclArraySearchType);
-    Tcl_RegisterObjType(&tclNsNameType);
     Tcl_RegisterObjType(&tclCmdNameType);
     Tcl_RegisterObjType(&tclRegexpType);
     Tcl_RegisterObjType(&tclProcBodyType);
Index: generic/tclProc.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclProc.c,v
retrieving revision 1.132
diff -u -r1.132 tclProc.c
--- generic/tclProc.c	7 Sep 2007 18:01:36 -0000	1.132
+++ generic/tclProc.c	9 Sep 2007 19:05:44 -0000
@@ -2549,7 +2549,7 @@
 {
     Interp *iPtr = (Interp *) interp;
     Proc *procPtr = NULL;
-    Tcl_Obj *lambdaPtr, *nsObjPtr, *errPtr;
+    Tcl_Obj *lambdaPtr, *nsObjPtr;
     int result, isRootEnsemble;
     Command cmd;
     Tcl_Namespace *nsPtr;
@@ -2627,14 +2627,6 @@
 	return result;
     }
 
-    if (nsPtr == NULL) {
-	TclNewLiteralStringObj(errPtr, "cannot find namespace \"");
-	Tcl_AppendObjToObj(errPtr, nsObjPtr);
-	Tcl_AppendToObj(errPtr, "\"", -1);
-	Tcl_SetObjResult(interp, errPtr);
-	return TCL_ERROR;
-    }
-
     cmd.nsPtr = (Namespace *) nsPtr;
 
     isRootEnsemble = (iPtr->ensembleRewrite.sourceObjs == NULL);
Index: tests/apply.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/apply.test,v
retrieving revision 1.10
diff -u -r1.10 apply.test
--- tests/apply.test	29 Mar 2007 19:22:08 -0000	1.10
+++ tests/apply.test	9 Sep 2007 19:05:45 -0000
@@ -15,7 +15,7 @@
 # RCS: @(#) $Id: apply.test,v 1.10 2007/03/29 19:22:08 msofer Exp $
 
 if {[lsearch [namespace children] ::tcltest] == -1} {
-    package require tcltest
+    package require tcltest 2.2
     namespace import -force ::tcltest::*
 }
 
@@ -79,32 +79,26 @@
 
 # Tests for runtime errors in the lambda expression
 
-test apply-3.1 {non-existing namespace} {
-    set lambda [list x {set x 1} ::NONEXIST::FOR::SURE]
-    set res [catch {apply $lambda x} msg]
-    list $res $msg
-} {1 {cannot find namespace "::NONEXIST::FOR::SURE"}}
-test apply-3.2 {non-existing namespace} {
+test apply-3.1 {non-existing namespace} -body {
+    apply [list x {set x 1} ::NONEXIST::FOR::SURE] x
+} -returnCodes error -result {namespace "::NONEXIST::FOR::SURE" not found}
+test apply-3.2 {non-existing namespace} -body {
     namespace eval ::NONEXIST::FOR::SURE {}
     set lambda [list x {set x 1} ::NONEXIST::FOR::SURE]
     apply $lambda x
     namespace delete ::NONEXIST
-    set res [catch {apply $lambda x} msg]
-    list $res $msg
-} {1 {cannot find namespace "::NONEXIST::FOR::SURE"}}
-test apply-3.3 {non-existing namespace} {
-    set lambda [list x {set x 1} NONEXIST::FOR::SURE]
-    set res [catch {apply $lambda x} msg]
-    list $res $msg
-} {1 {cannot find namespace "::NONEXIST::FOR::SURE"}}
-test apply-3.4 {non-existing namespace} {
+    apply $lambda x
+} -returnCodes error -result {namespace "::NONEXIST::FOR::SURE" not found}
+test apply-3.3 {non-existing namespace} -body {
+    apply [list x {set x 1} NONEXIST::FOR::SURE] x
+} -returnCodes error -result {namespace "::NONEXIST::FOR::SURE" not found}
+test apply-3.4 {non-existing namespace} -body {
     namespace eval ::NONEXIST::FOR::SURE {}
     set lambda [list x {set x 1} NONEXIST::FOR::SURE]
     apply $lambda x
     namespace delete ::NONEXIST
-    set res [catch {apply $lambda x} msg]
-    list $res $msg
-} {1 {cannot find namespace "::NONEXIST::FOR::SURE"}}
+    apply $lambda x
+} -returnCodes error -result {namespace "::NONEXIST::FOR::SURE" not found}
 
 test apply-4.1 {error in arguments to lambda expression} {
     set lambda [list x {set x 1}]
Index: tests/namespace-old.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/namespace-old.test,v
retrieving revision 1.11
diff -u -r1.11 namespace-old.test
--- tests/namespace-old.test	23 Nov 2006 15:35:31 -0000	1.11
+++ tests/namespace-old.test	9 Sep 2007 19:05:45 -0000
@@ -17,7 +17,7 @@
 # RCS: @(#) $Id: namespace-old.test,v 1.11 2006/11/23 15:35:31 dkf Exp $
 
 if {[lsearch [namespace children] ::tcltest] == -1} {
-    package require tcltest
+    package require tcltest 2.2
     namespace import -force ::tcltest::*
 }
 
@@ -336,9 +336,9 @@
     list [catch {namespace children test_ns_hier1 y z} msg] $msg
 } {1 {wrong # args: should be "namespace children ?name? ?pattern?"}}
 
-test namespace-old-5.10 {command "namespace children" must get valid namespace} {
-    list [catch {namespace children xyzzy} msg] $msg
-} {1 {unknown namespace "xyzzy" in namespace children command}}
+test namespace-old-5.10 {command "namespace children" must get valid namespace} -body {
+    namespace children xyzzy
+} -returnCodes error -result {namespace "xyzzy" not found in "::"}
 
 test namespace-old-5.11 {querying namespace children} {
     lsort [namespace children :: test_ns_hier*]
@@ -372,9 +372,9 @@
     list [catch {namespace parent x y} msg] $msg
 } {1 {wrong # args: should be "namespace parent ?name?"}}
 
-test namespace-old-5.19 {command "namespace parent" must get valid namespace} {
-    list [catch {namespace parent xyzzy} msg] $msg
-} {1 {unknown namespace "xyzzy" in namespace parent command}}
+test namespace-old-5.19 {command "namespace parent" must get valid namespace} -body {
+    namespace parent xyzzy
+} -returnCodes error -result {namespace "xyzzy" not found in "::"}
 
 test namespace-old-5.20 {querying namespace parent} {
     list [namespace eval :: {namespace parent}] \
Index: tests/namespace.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/namespace.test,v
retrieving revision 1.67
diff -u -r1.67 namespace.test
--- tests/namespace.test	12 Jun 2007 12:34:04 -0000	1.67
+++ tests/namespace.test	9 Sep 2007 19:05:45 -0000
@@ -232,7 +232,7 @@
          [namespace children test_ns_1] \
          [catch {namespace children test_ns_1::test_ns_2} msg] $msg \
          [info commands test_ns_1::test_ns_2::test_ns_3a::*]
-} {::test_ns_1::test_ns_2 {} {} 1 {unknown namespace "test_ns_1::test_ns_2" in namespace children command} {}}
+} {::test_ns_1::test_ns_2 {} {} 1 {namespace "test_ns_1::test_ns_2" not found in "::"} {}}
 test namespace-8.4 {TclTeardownNamespace, cmds imported from deleted ns go away} {
     catch {namespace delete {*}[namespace children :: test_ns_*]}
     namespace eval test_ns_export {
@@ -572,7 +572,7 @@
         list [catch {set ::test_ns_777::v} msg] $msg \
              [catch {namespace children test_ns_777} msg] $msg
     }
-} {1 {can't read "::test_ns_777::v": no such variable} 1 {unknown namespace "test_ns_777" in namespace children command}}
+} {1 {can't read "::test_ns_777::v": no such variable} 1 {namespace "test_ns_777" not found in "::test_ns_1"}}
 test namespace-14.3 {TclGetNamespaceForQualName, relative names} {
     namespace eval test_ns_1 {
         list $v $test_ns_2::v
@@ -586,7 +586,7 @@
         list [namespace children test_ns_2] \
              [catch {namespace children test_ns_1} msg] $msg
     }
-} {::test_ns_1::test_ns_2::foo 1 {unknown namespace "test_ns_1" in namespace children command}}
+} {::test_ns_1::test_ns_2::foo 1 {namespace "test_ns_1" not found in "::test_ns_1"}}
 test namespace-14.5 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} {
     namespace eval ::test_ns_2 {
         namespace eval bar {}
@@ -604,7 +604,7 @@
         list [namespace children test_ns_2] \
              [catch {namespace children test_ns_1} msg] $msg
     }
-} {::test_ns_1::test_ns_2::foo 1 {unknown namespace "test_ns_1" in namespace children command}}
+} {::test_ns_1::test_ns_2::foo 1 {namespace "test_ns_1" not found in "::test_ns_1"}}
 test namespace-14.7 {TclGetNamespaceForQualName, ignore extra :s if ns} {
     namespace children test_ns_1:::
 } {::test_ns_1::test_ns_2}
@@ -867,11 +867,11 @@
         namespace children test_ns_2
     }
 } {}
-test namespace-19.3 {GetNamespaceFromObj, name not found} {
+test namespace-19.3 {GetNamespaceFromObj, name not found} -body {
     namespace eval test_ns_1 {
-        list [catch {namespace children test_ns_99} msg] $msg
+        namespace children test_ns_99
     }
-} {1 {unknown namespace "test_ns_99" in namespace children command}}
+} -returnCodes error -result {namespace "test_ns_99" not found in "::test_ns_1"}
 test namespace-19.4 {GetNamespaceFromObj, invalidation of cached ns refs} {
     namespace eval test_ns_1 {
         proc foo {} {
@@ -1148,9 +1148,9 @@
 test namespace-29.2 {NamespaceInscopeCmd, bad args} {
     list [catch {namespace inscope ::} msg] $msg
 } {1 {wrong # args: should be "namespace inscope name arg ?arg...?"}}
-test namespace-29.3 {NamespaceInscopeCmd, specified ns must exist} {
-    list [catch {namespace inscope test_ns_1 {set v}} msg] $msg
-} {1 {unknown namespace "test_ns_1" in inscope namespace command}}
+test namespace-29.3 {NamespaceInscopeCmd, specified ns must exist} -body {
+    namespace inscope test_ns_1 {set v}
+} -returnCodes error -result {namespace "test_ns_1" not found in "::"}
 test namespace-29.4 {NamespaceInscopeCmd, simple case} {
     namespace eval test_ns_1 {
         variable v 747
@@ -1220,9 +1220,9 @@
          [namespace parent test_ns_1::test_ns_2] \
          [namespace eval test_ns_1::test_ns_2::test_ns_3 {namespace parent ::test_ns_1::test_ns_2}]
 } {{} ::test_ns_1 ::test_ns_1}
-test namespace-31.4 {NamespaceParentCmd, bad namespace specified} {
-    list [catch {namespace parent test_ns_1::test_ns_foo} msg] $msg
-} {1 {unknown namespace "test_ns_1::test_ns_foo" in namespace parent command}}
+test namespace-31.4 {NamespaceParentCmd, bad namespace specified} -body {
+    namespace parent test_ns_1::test_ns_foo
+} -returnCodes error -result {namespace "test_ns_1::test_ns_foo" not found in "::"}
 
 test namespace-32.1 {NamespaceQualifiersCmd, bad args} {
     catch {namespace delete {*}[namespace children :: test_ns_*]}
@@ -1368,11 +1368,11 @@
         namespace children ::test_ns_1
     }
 } {::test_ns_1::test_ns_2}
-test namespace-37.2 {SetNsNameFromAny, ns name not found} {
+test namespace-37.2 {SetNsNameFromAny, ns name not found} -body {
     namespace eval test_ns_1 {
-        list [catch {namespace children ::test_ns_1::test_ns_foo} msg] $msg
+        namespace children ::test_ns_1::test_ns_foo
     }
-} {1 {unknown namespace "::test_ns_1::test_ns_foo" in namespace children command}}
+} -returnCodes error -result {namespace "::test_ns_1::test_ns_foo" not found}
 
 test namespace-38.1 {UpdateStringOfNsName} {
     catch {namespace delete {*}[namespace children :: test_ns_*]}
@@ -2334,7 +2334,7 @@
     namespace eval ::test_ns_1 {
 	namespace path does::not::exist
     }
-} -returnCodes error -result {unknown namespace "does::not::exist"} -cleanup {
+} -returnCodes error -result {namespace "does::not::exist" not found in "::test_ns_1"} -cleanup {
     catch {namespace delete ::test_ns_1}
 }
 test namespace-51.11 {name resolution path control} -body {
Index: tests/obj.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/obj.test,v
retrieving revision 1.19
diff -u -r1.19 obj.test
--- tests/obj.test	8 Oct 2005 14:42:54 -0000	1.19
+++ tests/obj.test	9 Sep 2007 19:05:45 -0000
@@ -31,7 +31,6 @@
 	cmdName
 	dict
 	end-offset
-	nsName
 	regexp
 	string
     } {
Index: tests/upvar.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/upvar.test,v
retrieving revision 1.14
diff -u -r1.14 upvar.test
--- tests/upvar.test	3 Nov 2006 00:34:53 -0000	1.14
+++ tests/upvar.test	9 Sep 2007 19:05:45 -0000
@@ -455,7 +455,7 @@
 	    set w
 	}
     } \
-    -result {namespace "test_ns_0" does not exist} \
+    -result {namespace "test_ns_0" not found in "::test_ns_1"} \
     -returnCodes error \
     -cleanup {namespace delete test_ns_1}
 
@@ -469,7 +469,7 @@
 	    return [a]
 	}
     } \
-    -result {namespace "test_ns_0" does not exist} \
+    -result {namespace "test_ns_0" not found in "::test_ns_1"} \
     -returnCodes error \
     -cleanup {namespace delete test_ns_1}
 
@@ -540,7 +540,7 @@
 	    return [a]
 	}
     } \
-    -result {namespace "test_ns_0" does not exist} \
+    -result {namespace "test_ns_0" not found in "::test_ns_1"} \
     -returnCodes error \
     -cleanup {namespace delete test_ns_1}
 
