| Ticket UUID: | ba79c2f0ce408c09c8967eb037503251c4b525ac | ||
| Title: | Use of Itcl with auto load and namespace import result in command errors | ||
| Type: | Bug | Created on: | 2017-01-30 20:02:52 |
| Submitter: | anonymous | Assigned to: | dgp |
| Subsystem: | 81. Bundled Packages | Severity: | Severe |
| Priority: | 5 Medium | Last modified: | 2017-02-21 19:53:39 |
| Status: | Closed | Closed by: | dgp |
| Resolution: | Wont Fix | Closed on: | 2017-02-21 19:53:39 |
| Version: | 8.6.4 | ||
| Description: | ||||
Any command imported (namespace import) from a script that has been auto_loaded fails if used in conjunction with the Iwidgets package.
This is true for 8.5 and 8.6
Consider the following two procs:
src.tcl --------------------------------------
namespace eval src {
proc a {} {return "alpha"}
proc b {} {return "beta"}
proc etc {} {return "..."}
namespace export a b
}
dst.tcl -------------------------------------------
package require Iwidgets
lappend ::auto_path [file dirname [info script]]
puts $::auto_path
namespace eval dst {
namespace import ::src::*
proc c {} {return "Charlie"}
puts "[a] [b] [c]"
}
use mk to create a tcl index and run dst.
The result "a" is an invalid command.
Next: comment the package require.
=> alpha beta charlie
Now, consider the mods to dst.tcl - namespace import commented.
dst.tcl ----------------------------------
package require Iwidgets
lappend ::auto_path [file dirname [info script]]
puts $::auto_path
namespace eval dst {
#namespace import ::src::*
proc c {} {return "Charlie"}
puts "[::src::a] [::src::b] [c]"
}
=> alpha beta charlie
| ||||
| User Comments: | ||||
fvogel added on 2017-02-01 21:24:11:
Same ticket in the Tk tracker. dgp added on 2017-02-21 18:05:41:
Itcl replaces the [::auto_import] with its own customized version. The customized approach adds another layer of indirection. On [namespace import] all indexed auto-load-able commands have stub-versions created, which will then only invoke the actual auto-loading when the are called. The problem with this is that it misses the [namespace export] command that takes place when the actual auto-loading [source]s the implementation. With out an enabling [namespace export], the [namespace import] fails to get the auto-loaded command. This is so broken, I cannot imagine anyone wishing for this, but since I'm not an Itcl user it's hard to say with any confidence. dgp added on 2017-02-21 19:53:39:
I looked. I tried. I will not fix this. Itcl breaks Tcl's built-in hackery to try to make the snapshot-oriented command [namespace import] "Do What You Mean" in combination with the "delay until the last minute" scheme of the built-in auto-loader. Choose one or the other, magical imports of autoloaded commands or use of the Itcl package, but you cannot have both. Accommodating this was a dumb idea to begin with. [namespace import] has snapshot semantics. That's documented. So create commands before you attempt to [namespace import] them. You cannot make water that is not wet. You cannot take a snapshot of something that hasn't yet been brought into existence. Beyond that, give serious contemplation to ditching all use of Tcl's built-in auto-load system completely. It's ancient, not well-maintained, and the case for it is very hard to make anymore. If you can make the case, you can make your own stub-powered auto-loading scheme that works better in every way than this relic. As a workaround to the trouble reported in the ticket, you could remove the definition of [::auto_import] found in the itcl.tcl file installed as part of your Itcl installation. That will avoid the bug associated with this ticket, but I have no idea what impact that may have on the internal expectations of Itcl. Test suite doesn't care, but only a fool thinks the Itcl test suite is comprehensive. That workaround is what I would adapt if I had confidence it would not upset established Itcl uses. At this point though, the only winning move is not to play. | ||||
