|
2015-06-16
| ||
| 00:47 | • Ticket [a4cb3f06c4] Using end-n as second index on lreplace broken in 8.6.4 ... artifact: a23fc6be7c user: anonymous | |
|
2015-02-20
| ||
| 20:20 | • Closed ticket [32b6159246]: lreplace where idx2 < idx1 not compiled correctly... artifact: d6ba3d8326 user: dgp | |
| 20:19 | [32b6159246] Accept aspect patch for broken [lreplace] bytecode. No more [lreplace {1 2 3} 2 0] => 1... check-in: a3653be454 user: dgp tags: trunk | |
|
2015-02-19
| ||
| 20:47 | • Ticket [32b6159246] lreplace where idx2 < idx1 not compiled correctly sta... artifact: e885b011d4 user: anonymous | |
| 20:47 | • Add attachment aspect-lreplace-fix.fbun to ticket [32b6159246574b94|32b... artifact: 1553b72f15 user: anonymous | |
| 06:37 | • Ticket [32b6159246] lreplace where idx2 < idx1 not compiled correctly sta... artifact: 4542fd032d user: anonymous | |
| 03:11 | • Ticket [32b6159246]: 5 changes artifact: 27edc149e1 user: dgp | |
| 02:55 | • Ticket [32b6159246]: 5 changes artifact: d87dbcf07b user: anonymous | |
| 02:50 | • New ticket [32b6159246]. artifact: 9737d09940 user: anonymous | |
| 02:34 | (core ticket [32b6159246]) Fix for [lreplace l x y] where y<x-1 check-in: a6f0049368 user: aspect tags: aspect-lreplace-fix | |
lreplace where idx2 < idx1 not compiled correctly
Closed / Fixed32b6159246574b9480f83800d4347126c3998af9Created 12 years agoUpdated 12 years ago
Descriptionplain2015-02-19 02:50:19
% lreplace {1 2 3} 2 0
1 2 2 3
It looks like TclCompileLreplaceCommand doesn't handle idx2 < idx1 properly. Similar errors with >3 arguments too.
Hopefully the following patch formats correctly - chiselapp's struggling to sync.
It passes the extra tests, but negative indices might still break.
Of course, the case where numWords==4 and idx2<idx1 is the identity function, so it could be optimised further.
Index: generic/tclCompCmdsGR.c
==================================================================
--- generic/tclCompCmdsGR.c
+++ generic/tclCompCmdsGR.c
@@ -1498,10 +1498,14 @@
tokenPtr = TokenAfter(tokenPtr);
if (GetIndexFromToken(tokenPtr, &idx2) != TCL_OK) {
return TCL_ERROR;
}
+
+ if(idx2 != INDEX_END && idx2 < idx1) {
+ idx2 = idx1-1;
+ }
/*
* Work out what this [lreplace] is actually doing.
*/
==================================================================
--- tests/lreplace.test
+++ tests/lreplace.test
@@ -135,14 +135,23 @@
} {}
# Note that this test will fail in 8.5
test lreplace-4.2 {Bug ccc2c2cc98: lreplace edge case} {
lreplace { } 1 1
} {}
+test lreplace-4.3 {lreplace edge case} {
+ lreplace {1 2 3} 2 0
+} {1 2 3}
+test lreplace-4.4 {lreplace edge case} {
+ lreplace {1 2 3 4 5} 3 1
+} {1 2 3 4 5}
+test lreplace-4.4 {lreplace edge case} {
+ lreplace {1 2 3 4 5} 3 0 _
+} {1 2 3 _ 4 5}
# cleanup
catch {unset foo}
::tcltest::cleanupTests
return
# Local Variables:
# mode: tcl
# End:
Referenced by2
a3653be454[32b6159246] Accept aspect patch for broken [lreplace] bytecode. No more [lreplace {1 2 3} 2 0] => 1 2 2 3 check-in2015-02-20 20:19:48a6f0049368(core ticket [32b6159246]) Fix for [lreplace l x y] where y<x-1 check-in2015-02-19 02:34:43
anonymous (claiming to be aspect)plain2015-02-19 02:55:27
also a little suspicious of the block at line 1554:
if (idx1 > 0 && idx2 > 0 && idx2 < idx1) {
idx2 = idx1 - 1;
} else if (idx1 < 0 && idx2 < 0 && idx2 < idx1) {
idx2 = idx1 - 1;
}
I'm not 100% clear, but it looks strange idx1 or idx2 == 0 isn't handled.
dgp Ticket [32b6159246]: 5 changes
[History diff]2015-02-19 03:11:38
anonymous (claiming to be aspect)html2015-02-19 06:37:43
Patch is now pushed to chiselapp: http://chiselapp.com/user/aspect/repository/tcl/timeline?r=aspect-lreplace-fix
anonymous (claiming to be rkeene)plain2015-02-19 20:47:38
I attached a "fossil bundle" with this branch (minus the merge from trunk)
dgpplain2015-02-20 20:20:21
Patch accepted for 8.6.4.
Log in (anonymous is fine) to add a comment.