summaryrefslogtreecommitdiff
path: root/pp_sort.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-11-19 18:21:46 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-11-19 18:21:46 -0800
commita9ea019aef3b2976fab5d804799be8a75f0de48d (patch)
treef18638e886bce98dc0053f2e25b2110d35374583 /pp_sort.c
parent0e82bbcd2c141a233d06826ca4011728c8287daf (diff)
downloadperl-a9ea019aef3b2976fab5d804799be8a75f0de48d.tar.gz
Make sort’s warnings dependent on the right hints
sort’s warnings about uninitialized (or non-numeric) values returned from comparison routines are emitted in the scope of the compar- ison routine, not the sort function itself. So, not only does ‘use warnings; sort...’ not always warn, but the line numbers can be off, too: $ ./perl -Ilib -e '()=sort flobbp 1,2;' -e'use warnings;sub flobbp{"foo"}' Argument "foo" isn't numeric in sort at -e line 2. The solution is to restore PL_curcop to its previous value before get- ting a number out of the comparison routine’s return value.
Diffstat (limited to 'pp_sort.c')
-rw-r--r--pp_sort.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/pp_sort.c b/pp_sort.c
index da014e8073..6c2e301f7a 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1765,6 +1765,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b)
I32 result;
PMOP * const pm = PL_curpm;
OP * const sortop = PL_op;
+ COP * const cop = PL_curcop;
SV **pad;
PERL_ARGS_ASSERT_SORTCV;
@@ -1777,6 +1778,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b)
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);
PL_curpad = pad;
@@ -1798,6 +1800,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
AV * const av = GvAV(PL_defgv);
PMOP * const pm = PL_curpm;
OP * const sortop = PL_op;
+ COP * const cop = PL_curcop;
SV **pad;
PERL_ARGS_ASSERT_SORTCV_STACKED;
@@ -1830,6 +1833,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
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);
PL_curpad = pad;