diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-04-27 04:26:44 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-04-27 04:26:44 +0000 |
commit | 8e3f9bdf33f266c6e827493ca82149fc1598579a (patch) | |
tree | 3a8c06ecaeb5850b1d0e8dc8bf41154d25550aa7 /op.c | |
parent | 81fe5db4bb9398b820c41fdfb6fb4ba6ec6ac18d (diff) | |
download | perl-8e3f9bdf33f266c6e827493ca82149fc1598579a.tar.gz |
longstanding bug exposed by change#3307: sort arguments weren't
compiled with the right wantarray context (ensuing runtime lookup
via block_gimme() was getting the incidental context of the
sort() itself)
p4raw-link: @3307 on //depot/perl: 82092f1dcd6e496644fe74540fa706cb390be431
p4raw-id: //depot/perl@5955
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -5995,6 +5995,7 @@ Perl_ck_shift(pTHX_ OP *o) OP * Perl_ck_sort(pTHX_ OP *o) { + OP *firstkid; o->op_private = 0; #ifdef USE_LOCALE if (PL_hints & HINT_LOCALE) @@ -6003,10 +6004,10 @@ Perl_ck_sort(pTHX_ OP *o) if (o->op_type == OP_SORT && o->op_flags & OPf_STACKED) simplify_sort(o); - if (o->op_flags & OPf_STACKED) { /* may have been cleared */ - OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ + firstkid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ + if (o->op_flags & OPf_STACKED) { /* may have been cleared */ OP *k; - kid = kUNOP->op_first; /* get past null */ + OP *kid = cUNOPx(firstkid)->op_first; /* get past null */ if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) { linklist(kid); @@ -6036,17 +6037,26 @@ Perl_ck_sort(pTHX_ OP *o) } peep(k); - kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ - if (o->op_type == OP_SORT) + kid = firstkid; + if (o->op_type == OP_SORT) { + /* provide scalar context for comparison function/block */ + kid = scalar(kid); kid->op_next = kid; + } else kid->op_next = k; o->op_flags |= OPf_SPECIAL; } else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV) - null(cLISTOPo->op_first->op_sibling); + null(firstkid); + + firstkid = firstkid->op_sibling; } + /* provide list context for arguments */ + if (o->op_type == OP_SORT) + list(firstkid); + return o; } |