|
2017-02-21
| ||
| 19:53 | • Closed ticket [ba79c2f0ce]: Use of Itcl with auto load and namespace import resu... artifact: c44f174801 user: dgp | |
| 18:05 | • Ticket [ba79c2f0ce]: 3 changes artifact: 25373ebfa7 user: dgp | |
|
2017-02-01
| ||
| 21:24 | • Ticket [ba79c2f0ce]: 3 changes artifact: 6c32b4429f user: fvogel | |
|
2017-01-30
| ||
| 20:02 | • New ticket [ba79c2f0ce]. artifact: 28c0b1b990 user: anonymous | |
Use of Itcl with auto load and namespace import result in command errors
Closed / Wont Fixba79c2f0ce408c09c8967eb037503251c4b525acCreated 10 years agoUpdated 10 years ago
Descriptionplain2017-01-30 20:02:52
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
fvogelwiki2017-02-01 21:24:11
Same ticket in the Tk tracker.
dgpplain2017-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.
dgpplain2017-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.
Log in (anonymous is fine) to add a comment.