Skip to content

Commit

Permalink
Return list length in scalar context
Browse files Browse the repository at this point in the history
  • Loading branch information
syohex committed Apr 27, 2016
1 parent 7340b45 commit 6a2a631
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions xs-src/UtilsBy.xs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ CODE:
dMULTICALL;
GV *gv;
HV *stash;
I32 gimme = G_SCALAR;
I32 gimme = G_SCALAR, ret_gimme = GIMME_V;
SV **args = &PL_stack_base[ax];
IV i, len;
AV *ret_vals, *remains, *origs;
Expand Down Expand Up @@ -671,9 +671,14 @@ CODE:
av_push(origs, newSVsv(val));
}

len = av_len(ret_vals) + 1;
for (i = 0; i < len; i++) {
ST(i) = sv_mortalcopy(*av_fetch(ret_vals, i, 0));
if (ret_gimme == G_SCALAR) {
len = 1;
ST(0) = sv_2mortal(newSViv(av_len(ret_vals)+1));
} else {
len = av_len(ret_vals) + 1;
for (i = 0; i < len; i++) {
ST(i) = sv_mortalcopy(*av_fetch(ret_vals, i, 0));
}
}

XSRETURN(len);
Expand Down

0 comments on commit 6a2a631

Please sign in to comment.