diff options
author | David Mitchell <davem@iabyn.com> | 2015-06-08 11:53:38 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-06-19 08:44:17 +0100 |
commit | 334112121fd381e21666f72ab06d79ef94f3f6a6 (patch) | |
tree | 67d664468de4d9c499df8974d5f7687ffaa2ea6f /pod/perldiag.pod | |
parent | 626ed49c374dc371a27e6734ce3d3399c07e2bb4 (diff) | |
download | perl-334112121fd381e21666f72ab06d79ef94f3f6a6.tar.gz |
simplify sort sub return arg processing
This commit:
1) makes the gimme of sort blocks, as specified by the pushed cx_gimme,
be G_SCALAR. Formerly it was likely to be G_ARRAY, as it inherited
whatever sort() was called as, and sort doesn't bother calling a sort
block unless sort was called in list context.
This change is largely cosmetic, as
a) the sort block is already compiled in scalar context; and
b) the code in S_sortcv() etc does its own return arg context
processing anyway, and assumes scalar context.
But it makes it consistent with sort SUB, which *does* set gimme to
G_SCALAR.
2) Makes use of the fact that a sort sub or block will always be
called as the first context in a new stackinfo, and such stackinfos always
have PL_stack_base[0] set to &PL_sv_undef as a guard.
So handling scalar context return (where zero args returned needs to be
converted into 1 PL_sv_undef arg) can be simplified by just always
accessing the last arg, *PL_stack_sp, regardless of whether 0,1,2+ args
were returned.
Note that some code making use of MULTICALL (e.g. List::Util) has already
been (possibly inadvertently) relying on this fact.
3) Remove the "Sort subroutine didn't return single value" fatal error.
This croak was removed from the sort BLOCK and sort NON-XS-SUB variants
in v5.15.5-82-g1715fa6, but the croak was left for XS sort subs.
That commit incorrectly asserted that for "sort BLOCK" and "sort
NON-XS-SUB", more than 1 arg could never be returned, but:
$ perl -e'sub f { return (1,2) } @a = sort f 1,2,3'
perl: pp_sort.c:1789: S_sortcv: Assertion `PL_stack_sp ==
PL_stack_base' failed.
That has been fixed by (2) above. By removing the croak from the XS branch
too, we make things consistent. This means that an XS sub which returns
more than 1 arg will just gets its return args be evaluated in scalar
context (so @return_args[-1] will be used), rather than being handled
specially.
Diffstat (limited to 'pod/perldiag.pod')
-rw-r--r-- | pod/perldiag.pod | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 0adabf5169..ab94d597b7 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -5438,11 +5438,6 @@ overhauled. (F) An ancient error message that almost nobody ever runs into anymore. But before sort was a keyword, people sometimes used it as a filehandle. -=item Sort subroutine didn't return single value - -(F) A sort comparison subroutine written in XS must return exactly one -item. See L<perlfunc/sort>. - =item Source filters apply only to byte streams (F) You tried to activate a source filter (usually by loading a |