Overview
| Artifact ID: | adfaa611e1058b35a5c80fae33fc0cc6a879aa725444bad22754789a590645fa |
|---|---|
| Ticket: | 4dc35e0c0cf24b4a997556b70396d998ebb6adfe
auto_execok on windows not always using absolute path |
| User & Date: | juliannoble2 on 2025-01-26 16:33:16 |
Changes
- icomment:
Yes, I agree. I first tried my overridden auto_execok with some auto_resets added to avoid cacheing - but broke everything for the auto_load reason you mentioned! Then using unset -nocomplain ::auto_execs I'm pretty happy with the result. I have about 90 dirs in my path - so I get a perceivable delay if I fat-finger a command and it goes out to search for a non-existant one (~200ms) This is no big deal for that case - and also no big deal for my codebase - where there are a few places I can manually cache some paths as you suggest. It does however unmask an issue, which I now realise is why I was playing with init.tcl in the first place back in '23 The auto_execok searches foreach extension and then nests foreach directory in the path - Which would make sense if the expectation is that when you type foobar - you must test all paths for that before matching things like foobar.exe or foobar.bat, but I don't *think* that's the way things should work on windows. If I have a path set as a high precedence - I expect it to match the first executable with that base in the earliest path - not match some exact match later down. e.g This has caused me some frustrations in the past with Tcl trying to run various inappropriate things such as a bash script named cmd (provided by msys for some reason) With the auto_execok caching disabled - it's now more apparent that this scanning the entire path list repeatedly for each extension in order is occurring. As .bat is later in list of extensions - there is a noticable delay typing something vs something.bat The issue will be worse if/when auto_exec is updated to handle other items commonly in PATHEXT such as .RB .PY I think it would be reasonable for auto_execok to determine the right script engine for registered extensions and call them - but perhaps that's a bug/RFE for another time. (just returning "<resolvedpath>/cmd.exe /c <name>" works for these and those obtuse 'reparse point' based windows installs - but perhaps there's a better way) At any rate - on my system, with caching disabled - it's now getting near one second to [auto_execok someuniquescriptname] if it's someuniquescriptname.py From my experiments with cmd.exe and powershell given a non-suffixed command, they both give precedence to the path order first. ie opposite of Tcl's current slow auto_execok method of scanning. I don't know if this was done deliberately to try to match some cross-platform behaviour(?) - but it has always violated my expections on windows. Below is my tweak for the searchorder in init.tcl. It seems to fix the bug in this ticket, improves the uncached auto_execok speed for unsuffixed commands, and provides a result more inline with how windows commandlines do it. set lookfor [lmap ext $execExtensions {string cat ${name} ${ext}}] foreach dir [split $path {;}] { set dir [file normalize $dir] # Skip already checked directories if {[info exists checked($dir)] || ($dir eq "")} { continue } set checked($dir) {} foreach match [glob -nocomplain -dir $dir -tail {*}$lookfor] { set file [file join $dir $match] if {[file exists $file] && ![file isdirectory $file]} { return [set auto_execs($name) [list $file]] } } } Versus the original: foreach ext $execExtensions { unset -nocomplain checked foreach dir [split $path {;}] { # Skip already checked directories if {[info exists checked($dir)] || ($dir eq "")} { continue } set checked($dir) {} set file [file join $dir ${name}${ext}] if {[file exists $file] && ![file isdirectory $file]} { return [set auto_execs($name) [list $file]] } } } - login: "juliannoble2"
- mimetype: "text/plain"