diff options
author | Yves Orton <demerphq@gmail.com> | 2020-01-31 15:34:48 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2020-01-31 15:37:45 +0100 |
commit | 2b301921ff7682e54ab74ad30dbf2ce1c9fc24b1 (patch) | |
tree | be847e310a47167a95628f59deaf59c0d27639e8 /t/op/sort.t | |
parent | 3eb35b099f783db0ec40f0ca9f20fd1666c54cdb (diff) | |
download | perl-2b301921ff7682e54ab74ad30dbf2ce1c9fc24b1.tar.gz |
pp_sort.c: fix fencepost error in call to av_extend()
In [rt.cpan.org #39196] issue #17496 there is a report
that Tie::File produced spurious blank lines in the file
after
@tied= sort @tied;
it turns out that this is because Tie::File treats
EXTEND similarly to STORESIZE (which is arguably not
entirely correct, but also not that weird) coupled
with an off by one error in the calls to av_extend()
in pp_sort.
This patch fixes the fencepost error, adds some comments
to av_extend() to make it clear what it is doing, and
adds a test that EXTEND is called by this code with
correct argument.
Diffstat (limited to 't/op/sort.t')
-rw-r--r-- | t/op/sort.t | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/t/op/sort.t b/t/op/sort.t index d201f00afd..f2e139dff0 100644 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -7,7 +7,8 @@ BEGIN { set_up_inc('../lib'); } use warnings; -plan(tests => 199); +plan(tests => 203); +use Tie::Array; # we need to test sorting tied arrays # these shouldn't hang { @@ -433,7 +434,6 @@ cmp_ok($x,'eq','123',q(optimized-away comparison block doesn't take any other ar @a = qw(b c a); $r1 = \$a[1]; @a = sort mysort @a; $r2 = \$a[0]; is "$$r1-$$r2-@a", "c-c-c b a", "inplace sort with function of lexical"; - use Tie::Array; my @t; tie @t, 'Tie::StdArray'; @@ -494,6 +494,25 @@ cmp_ok($x,'eq','123',q(optimized-away comparison block doesn't take any other ar is ("@a", "3 4 5", "RT #128340"); } +{ + @Tied_Array_EXTEND_Test::ISA= 'Tie::StdArray'; + my $extend_count; + sub Tied_Array_EXTEND_Test::EXTEND { + $extend_count= $_[1]; + return; + } + my @t; + tie @t, "Tied_Array_EXTEND_Test"; + is($extend_count, undef, "test that EXTEND has not been called prior to initialization"); + $t[0]=3; + $t[1]=1; + $t[2]=2; + is($extend_count, undef, "test that EXTEND has not been called during initialization"); + @t= sort @t; + is($extend_count, 3, "test that EXTEND was called with an argument of 3 by pp_sort()"); + is("@t","1 2 3","test that sorting the tied array worked even though EXTEND is a no-op"); +} + # Test optimisations of reversed sorts. As we now guarantee stability by # default, # optimisations which do not provide this are bogus. |