From 97e38369e9957929ab86d1536018c97f921ec9ad Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Fri, 10 Oct 2014 18:45:34 +1000 Subject: [PATCH] namespace: restore namespace import support Commit 8e28d066 "fixed" infinite namespace import recursion by simply disabling support for import. This commit restores support by detecting self-import. Signed-off-by: Steve Bennett --- jim-namespace.c | 1 - nshelper.tcl | 3 +++ tests/namespace.test | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jim-namespace.c b/jim-namespace.c index 600f8ec..bcc7259 100644 --- a/jim-namespace.c +++ b/jim-namespace.c @@ -268,7 +268,6 @@ static int JimNamespaceCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_SetResult(interp, Jim_NamespaceQualifiers(interp, argv[2])); return JIM_OK; - case OPT_IMPORT: case OPT_EXPORT: return JIM_OK; diff --git a/nshelper.tcl b/nshelper.tcl index 33acb51..d0cb35a 100644 --- a/nshelper.tcl +++ b/nshelper.tcl @@ -63,6 +63,9 @@ proc {namespace import} {args} { foreach pattern $args { foreach cmd [info commands [namespace canon $current $pattern]] { + if {[namespace qualifiers $cmd] eq $current} { + return -code error "import pattern \"$pattern\" tries to import from namespace \"$current\" into itself" + } alias ${current}::[namespace tail $cmd] $cmd } } diff --git a/tests/namespace.test b/tests/namespace.test index 98acf3e..090fcf0 100644 --- a/tests/namespace.test +++ b/tests/namespace.test @@ -470,6 +470,21 @@ test namespace-11.1 {command caching} { lappend result [ns1::cmd2] } {ns1 global} +test namespace-12.1 {namespace import} { + namespace eval test_ns_scope1 { + proc a {} { return a } + namespace export a + } + namespace eval test_ns_scope2 { + namespace import ::test_ns_scope1::a + a + } +} {a} + +test namespace-12.2 {namespace import recursive} -body { + namespace import * +} -returnCodes error -match glob -result {import pattern "*" tries to import from namespace "*" into itself} + foreach cmd [info commands test_ns_*] { rename $cmd "" } -- 2.11.4.GIT