summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-07-05 17:27:06 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-07-05 17:27:06 (GMT)
commitbf7695058ddedaee83cf8f2386277dded31a5260 (patch)
treecef3768290a51e324c8309559e41773898412085
parente539042615457f25e32cc481db82a48146b76495 (diff)
downloadtcl-bf7695058ddedaee83cf8f2386277dded31a5260.zip
tcl-bf7695058ddedaee83cf8f2386277dded31a5260.tar.gz
tcl-bf7695058ddedaee83cf8f2386277dded31a5260.tar.bz2
* generic/tclNamesp.c: Allow for [namespace import] of a command
* tests/namespace.test: over a previous [namespace import] of itself without throwing an error. [RFE 1230597]
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclNamesp.c12
-rw-r--r--tests/namespace.test4
3 files changed, 19 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 6cc9f05..a9c5495 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-07-05 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclNamesp.c: Allow for [namespace import] of a command
+ * tests/namespace.test: over a previous [namespace import] of itself
+ without throwing an error. [RFE 1230597]
+
2005-07-01 Zoran Vasiljevic <vasiljevic@users.sourceforge.net>
* unix/tclUnixNotfy.c: protect against spurious wake-ups while
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 55e92af..3eb1bb2 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -19,7 +19,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.31.2.6 2004/10/05 16:22:34 dgp Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.31.2.7 2005/07/05 17:27:08 dgp Exp $
*/
#include "tclInt.h"
@@ -1277,6 +1277,16 @@ Tcl_Import(interp, namespacePtr, pattern, allowOverwrite)
refPtr->nextPtr = cmdPtr->importRefPtr;
cmdPtr->importRefPtr = refPtr;
} else {
+ Command *overwrite = (Command *) Tcl_GetHashValue(found);
+ if (overwrite->deleteProc == DeleteImportedCmd) {
+ ImportedCmdData *dataPtr =
+ (ImportedCmdData *) overwrite->objClientData;
+ if (dataPtr->realCmdPtr
+ == (Command *) Tcl_GetHashValue(hPtr)) {
+ /* Repeated import of same command -- acceptable */
+ return TCL_OK;
+ }
+ }
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
"can't import command \"", cmdName,
"\": already exists", (char *) NULL);
diff --git a/tests/namespace.test b/tests/namespace.test
index 096af88..311f3af 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.5 2004/10/28 00:01:11 dgp Exp $
+# RCS: @(#) $Id: namespace.test,v 1.21.2.6 2005/07/05 17:27:09 dgp Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -244,7 +244,7 @@ test namespace-9.4 {Tcl_Import, simple import} {
} {cmd1: 123}
test namespace-9.5 {Tcl_Import, can't redefine cmd unless allowOverwrite!=0} {
list [catch {namespace eval test_ns_import {namespace import ::test_ns_export::*}} msg] $msg
-} {1 {can't import command "cmd1": already exists}}
+} {0 {}}
test namespace-9.6 {Tcl_Import, cmd redefinition ok if allowOverwrite!=0} {
namespace eval test_ns_import {
namespace import -force ::test_ns_export::*