diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-11-20 16:50:37 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-11-21 00:32:31 -0800 |
commit | 1715fa648339558035d9920399c9f04263c0a14e (patch) | |
tree | d205c722d8f26af9475ef8ce307956154f93fac0 /pp_sort.c | |
parent | cfe287a06b2ed98c25aebb477f6b400409f1fc85 (diff) | |
download | perl-1715fa648339558035d9920399c9f04263c0a14e.tar.gz |
Make sort {} and sort {()} equivalent
sub {} and sub{()} are equivalent. In list context they both return
the empty list. In scalar context they both return undef. But sort
doesn’t seem to think so. It croaks on sub{}. This commit fixes that
and makes it consistent.
I left XSUBs alone, since I’m not sure how they are supposed
to behave.
Diffstat (limited to 'pp_sort.c')
-rw-r--r-- | pp_sort.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -1775,12 +1775,14 @@ S_sortcv(pTHX_ SV *const a, SV *const b) PL_stack_sp = PL_stack_base; PL_op = PL_sortcop; CALLRUNOPS(aTHX); - if (PL_stack_sp != PL_stack_base + 1) - Perl_croak(aTHX_ "Sort subroutine didn't return single value"); PL_op = sortop; PL_curcop = cop; pad = PL_curpad; PL_curpad = 0; - result = SvIV(*PL_stack_sp); + if (PL_stack_sp != PL_stack_base + 1) { + assert(PL_stack_sp == PL_stack_base); + result = SvIV(&PL_sv_undef); + } + else result = SvIV(*PL_stack_sp); PL_curpad = pad; while (PL_scopestack_ix > oldscopeix) { LEAVE; @@ -1830,12 +1832,14 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b) PL_stack_sp = PL_stack_base; PL_op = PL_sortcop; CALLRUNOPS(aTHX); - if (PL_stack_sp != PL_stack_base + 1) - Perl_croak(aTHX_ "Sort subroutine didn't return single value"); PL_op = sortop; PL_curcop = cop; pad = PL_curpad; PL_curpad = 0; - result = SvIV(*PL_stack_sp); + if (PL_stack_sp != PL_stack_base + 1) { + assert(PL_stack_sp == PL_stack_base); + result = SvIV(&PL_sv_undef); + } + else result = SvIV(*PL_stack_sp); PL_curpad = pad; while (PL_scopestack_ix > oldscopeix) { LEAVE; |