| Ticket UUID: | 5d6de65036f6ecd229c8c46e591aae520547968a | ||
| Title: | [package require] misses stable options with stable preference | ||
| Type: | Bug | Created on: | 2017-11-03 16:11:02 |
| Submitter: | dgp | Assigned to: | aku |
| Subsystem: | 39. Package Manager | Severity: | Severe |
| Priority: | 5 Medium | Last modified: | 2017-11-14 17:38:33 |
| Status: | Closed | Closed by: | aku |
| Resolution: | Fixed | Closed on: | 2017-11-14 17:38:33 |
| Version: | 8.5+ | ||
| Description: | ||||
First posted in a stackoverflow question:
https://stackoverflow.com/questions/47099580/tcl-package-require-loads-the-wrong-package-version
% package prefer
stable
% package ifneeded p 1.4a1 {package provide p 1.4a1}
% package ifneeded p 1.1 {package provide p 1.1}
% package require p 1.1
1.4a1
The search loop in PkgRequireCore() is simply wrong.
| ||||
| User Comments: | ||||
dgp added on 2017-11-06 00:07:50:
aku, maybe you should take the first try at this, because looking over the code is filling me with the impulse for a substantial rewrite. (Available version lists kept sorted). If you can devise a less radical fix that may be more appropriate on the 8.5 branch. dgp added on 2017-11-06 00:11:33:
Branch bug-5d6de65036 contains a test case demonstrating the bug to be fixed. aku added on 2017-11-13 19:06:11:
See commit [12e286e121] for my fix. No radical change. Kept a single search loop with choice after its completion. Simply made sure that a failure in the first comparison of each iteration does not prevent the comparison for stable to be run. Moved the requirements check before both. Passes the extended testsuite. If acceptable, please merge. A more radical approach would be to move the search loop into a separate function, add flag to distinguish search for stable vs search for any. Then run search for any if stable is not requested, or search for stable failed to find anything. Comment indicated that the list of available versions is sorted ? Ascending or descending ? If descending we can take first element matching our criteria and then stop. For ascending I see no way to an early stop. jan.nijtmans added on 2017-11-14 08:44:35:
I think this looks good for 8.5. So her's my +1 to merge (FWIW). dgp added on 2017-11-14 13:37:42:
Thank you for the fix. I am merging it forward. dgp added on 2017-11-14 13:43:15:
We have to prioritize correctness over other things. Clarity is usually the right second place. Performance after those. The prior implementation, I believe, was complicated out of an optimization attempt to minimize calls to SomeRequirementSatisfied(). Too bad that complicated often leads to wrong. It will be interesting to see if this change leads to fresh complaints about [package require] getting slower. There is ample room here for a refactoring that can improve both clarity and performance I think. Hopefully someone can find time to pursue that in the 8.7+ branches. Finally, I think there's still arguably a selection bug, though the spec is vague enough that I'm not certain. I will post that in a fresh ticket. dgp added on 2017-11-14 17:24:18:
Merge completed. aku added on 2017-11-14 17:38:33:
> We have to prioritize correctness over other things. Yes, of course. Apologies if anything I said came across as not advocating that. That was definitely not my intention. > Clarity is usually the right second place. > Performance after those. True as well. > The prior implementation, I believe, was complicated > out of an optimization attempt to minimize calls to > SomeRequirementSatisfied(). I honestly do not remember anymore. > There is ample room here for a refactoring that can > improve both clarity and performance I think. Yes. The text starting from `A more radical approach ...` were my notes and thoughts on that matter so far. > Finally, I think there's still arguably a selection bug, > though the spec is vague enough that I'm not certain. I > will post that in a fresh ticket. Ok. Keeping my eyes open for it. | ||||
