Tcl Source Code

Artifact [3bfc156819]
Login

Artifact 3bfc15681915b656b2ad74ca9173b070c6c5de87:

Attachment "import.patch" to ticket [1230597fff] added by dgp 2005-07-01 04:05:30.
Index: generic/tclNamesp.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclNamesp.c,v
retrieving revision 1.77
diff -u -r1.77 tclNamesp.c
--- generic/tclNamesp.c	7 Jun 2005 21:46:18 -0000	1.77
+++ generic/tclNamesp.c	30 Jun 2005 21:04:01 -0000
@@ -1639,6 +1639,15 @@
 	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_AppendResult(interp, "can't import command \"", cmdName,
 		"\": already exists", (char *) NULL);
 	return TCL_ERROR;
Index: tests/namespace.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/namespace.test,v
retrieving revision 1.45
diff -u -r1.45 namespace.test
--- tests/namespace.test	14 Jun 2005 13:46:04 -0000	1.45
+++ tests/namespace.test	30 Jun 2005 21:04:03 -0000
@@ -244,7 +244,7 @@
 } {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::*