Skip to content

Commit

Permalink
[perl #78194] Make sort copy PADTMPs
Browse files Browse the repository at this point in the history
Copy PADTMPs (op return values) when there is a sort block/sub that is
not optimised away and we are not sorting in place, so that \$a == \$a
will return true.

Many ops return the same scalar each time, for efficiency; refgen (\)
knows about that and copies them, to hide the implementation detail,
but other ops (sort in this case) need to do the same thing.
  • Loading branch information
Father Chrysostomos committed Jul 26, 2013
1 parent da9e430 commit 2b66f6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pp_sort.c
Expand Up @@ -1483,6 +1483,7 @@ PP(pp_sort)
OP* const nextop = PL_op->op_next;
I32 overloading = 0;
bool hasargs = FALSE;
bool copytmps;
I32 is_xsub = 0;
I32 sorting_av = 0;
const U8 priv = PL_op->op_private;
Expand Down Expand Up @@ -1604,8 +1605,11 @@ PP(pp_sort)
/* shuffle stack down, removing optional initial cv (p1!=p2), plus
* any nulls; also stringify or converting to integer or number as
* required any args */
copytmps = !sorting_av && PL_sortcop;
for (i=max; i > 0 ; i--) {
if ((*p1 = *p2++)) { /* Weed out nulls. */
if (copytmps && SvPADTMP(*p1) && !IS_PADGV(*p1))
*p1 = sv_mortalcopy(*p1);
SvTEMP_off(*p1);
if (!PL_sortcop) {
if (priv & OPpSORT_NUMERIC) {
Expand Down
1 change: 0 additions & 1 deletion t/op/sort.t
Expand Up @@ -1008,7 +1008,6 @@ $#a = -1;
() = [sort { $a = 10; $b = 10; 0 } $#a, $#a];
is $#a, 10, 'sort block modifying $a and $b';

$::TODO = ' ';
() = sort {
is \$a, \$a, '[perl #78194] op return values passed to sort'; 0
} "${\''}", "${\''}";

0 comments on commit 2b66f6d

Please sign in to comment.