summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2003-02-03 20:16:52 (GMT)
committerKevin B Kenny <kennykb@acm.org>2003-02-03 20:16:52 (GMT)
commit6c76b17acdfef82d68e6edab9a29210cadc63df3 (patch)
tree7f4146e4f6fd25e776781cf6c10b506a924eb593 /generic/tclBasic.c
parent7bc2d8dd9e518114299f600782715f52bb30b5a5 (diff)
downloadtcl-6c76b17acdfef82d68e6edab9a29210cadc63df3.zip
tcl-6c76b17acdfef82d68e6edab9a29210cadc63df3.tar.gz
tcl-6c76b17acdfef82d68e6edab9a29210cadc63df3.tar.bz2
* generic/tclBasic.c: Changed [trace add command] so that 'rename'
callbacks get fully qualified names of the command. [Bug 651271]. ***POTENTIAL INCOMPATIBILITY*** * tests/trace.test: Modified the test cases for [trace add command] to expect fully qualified names on the 'rename' callbacks. Added a case for renaming a proc within a namespace. * doc/trace.n: Added language about use of fully qualified names in trace callbacks.
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 6702240..e7b0aa0 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -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: tclBasic.c,v 1.71 2003/01/17 14:19:40 vincentdarley Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.72 2003/02/03 20:16:52 kennykb Exp $
*/
#include "tclInt.h"
@@ -1918,6 +1918,8 @@ TclRenameCommand(interp, oldName, newName)
Command *cmdPtr;
Tcl_HashEntry *hPtr, *oldHPtr;
int new, result;
+ Tcl_Obj* oldFullName;
+ Tcl_DString newFullName;
/*
* Find the existing command. An error is returned if cmdName can't
@@ -1934,6 +1936,9 @@ TclRenameCommand(interp, oldName, newName)
return TCL_ERROR;
}
cmdNsPtr = cmdPtr->nsPtr;
+ oldFullName = Tcl_NewObj();
+ Tcl_IncrRefCount( oldFullName );
+ Tcl_GetCommandFullName( interp, cmd, oldFullName );
/*
* If the new command name is NULL or empty, delete the command. Do this
@@ -1968,7 +1973,6 @@ TclRenameCommand(interp, oldName, newName)
return TCL_ERROR;
}
-
/*
* Warning: any changes done in the code here are likely
* to be needed in Tcl_HideCommand() code too.
@@ -2006,9 +2010,26 @@ TclRenameCommand(interp, oldName, newName)
* Therefore increment the reference count for cmdPtr so that
* it's Command structure is freed only towards the end of this
* function by calling TclCleanupCommand.
+ *
+ * The trace procedure needs to get a fully qualified name for
+ * old and new commands [Tcl bug #651271], or else there's no way
+ * for the trace procedure to get the namespace from which the old
+ * command is being renamed!
*/
+
+ Tcl_DStringInit( &newFullName );
+ Tcl_DStringAppend( &newFullName, newNsPtr->fullName, -1 );
+ if ( newNsPtr != iPtr->globalNsPtr ) {
+ Tcl_DStringAppend( &newFullName, "::", 2 );
+ }
+ Tcl_DStringAppend( &newFullName, newTail, -1 );
cmdPtr->refCount++;
- CallCommandTraces(iPtr,cmdPtr,oldName,newName,TCL_TRACE_RENAME);
+ CallCommandTraces( iPtr, cmdPtr,
+ Tcl_GetString( oldFullName ),
+ Tcl_DStringValue( &newFullName ),
+ TCL_TRACE_RENAME);
+ Tcl_DecrRefCount( oldFullName );
+ Tcl_DStringFree( &newFullName );
/*
* The new command name is okay, so remove the command from its
@@ -2305,7 +2326,7 @@ Tcl_GetCommandFullName(interp, command, objPtr)
if (cmdPtr->hPtr != NULL) {
name = Tcl_GetHashKey(cmdPtr->hPtr->tablePtr, cmdPtr->hPtr);
Tcl_AppendToObj(objPtr, name, -1);
- }
+ }
}
}