else {
SV **oldsp = PL_stack_base + cx->blk_oldsp;
if (oldsp != MARK) {
- /* shift return args to base of call stack frame */
+ /* Handle extra junk on the stack. For example,
+ * for (1,2) { return 3,4 }
+ * leaves 1,2,3,4 on the stack. In list context we
+ * have to splice out the 1,2; In scalar context for
+ * for (1,2) { return }
+ * we need to set sp = oldsp so that pp_leavesub knows
+ * to push &PL_sv_undef onto the stack.
+ * Note that in pp_return we only do the extra processing
+ * required to handle junk; everything else we leave to
+ * pp_leavesub.
+ */
SSize_t nargs = SP - MARK;
if (nargs) {
- if (cx->blk_gimme == G_ARRAY)
+ if (cx->blk_gimme == G_ARRAY) {
+ /* shift return args to base of call stack frame */
Move(MARK + 1, oldsp + 1, nargs, SV**);
- else if (cx->blk_gimme == G_SCALAR)
- oldsp[1] = *SP;
+ PL_stack_sp = oldsp + nargs;
+ }
}
- PL_stack_sp = oldsp + nargs;
+ else
+ PL_stack_sp = oldsp;
}
/* fall through to a normal sub exit */
return Perl_pp_leavesub(aTHX);