Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-09-10
00:13 • Closed ticket [1017299fff]: namespace import loop not prevented plus 8 oth... artifact: 8a77350c90 user: dgp
00:02 • Ticket [1017299fff]: 4 changes artifact: 6835d34647 user: dgp
00:02 • Add attachment 1017299.patch to ticket [1017299fff] artifact: 8fd5ce7b5a user: dgp
2004-08-27
21:27 • Ticket [1017299fff] namespace import loop not prevented status still Open ... artifact: cd971a7569 user: dgp
20:52 • Ticket [1017299fff]: 4 changes artifact: a23e571d2f user: dgp
00:42 • New ticket [1017299fff]. artifact: 2d2752a550 user: dgp

[namespace import] loop not prevented

Closed / Fixed1017299fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-08-27 00:42:36
% namespace eval one {
    namespace export foo
    proc foo {} {}
}
% namespace eval two {
    namespace export foo
    namespace import ::one::foo
}
% namespace eval three {
    namespace export foo
    namespace import ::two::foo
}
% namespace eval two namespace import -force ::three::foo
% namespace origin two::foo     

...leaves Tcl hung in an internal
infinite loop.

The import loop prevention check
inside Tcl_Import only prevents
"end-to-end" loops, not lesser
cycles of reference.
dgpplain2004-08-27 20:52:06
Logged In: YES 
user_id=80530


In the spirit of "snapshot semantics"
I think this bug can be fixed by not
using import chains internally.  Have
each import refer directly to its origin.
dgpplain2004-08-27 21:27:31
Logged In: YES 
user_id=80530


miguel points out that would
change the following script
behavior:

%  namespace eval a {namespace export *; proc a {} {puts hi}}
%  namespace eval b {namespace export *;namespace import ::a::a}
%  namespace eval c {namespace import ::b::a}
% c::a
hi
% namespace eval b {proc a {} {puts lo}}
% c::a
lo
% b::a
lo
% a::a
hi

From my perspective, that code just
demonstrates that we have an
"inconsistent [namespace import] model"
(See Bug 565823).  Do we implement
snapshot semantics or not?

But, it's probably unchangeable at
this point.
dgpplain2004-09-10 00:02:33
File Added - 100907: 1017299.patch

Logged In: YES 
user_id=80530

having looked into the internals
quite a bit now, I think I had the
wrong idea about "snapshot
semantics".  Appears that phrase
is only intended to refer to 
export sets, not to the very definition
of commands.

Note another bug.  Tcl_Import
accepts as an argument the
namespace to import into, and
if that argument is NULL, uses
the current namespace of the interp.
When checking for import loops,
the current namespace of the interp
is checked, rather than the namespace
to import into.

Here's a patch for the bugs.
dgpplain2004-09-10 00:13:34
Logged In: YES 
user_id=80530

Patch committed to HEAD
and 8-4-branch.
Log in (anonymous is fine) to add a comment.

Attachments: