Skip to content

Commit 3b66035

Browse files
committed
IO::getline(): use CALLRUNOPS
This XS function calls Perl_pp_readline() directly. Instead, invoke the op via CALLRUNOPS(): the run loop (that will just run a single op) can handle the case of the caller having a non-reference-counted stack, but when the ops it calls are expecting a reference-counted stack. Perl_pp_readline() will (in a few commits' time) indeed be expecting a reference-counted stack.
1 parent 8771123 commit 3b66035

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

dist/IO/IO.xs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,7 @@ PPCODE:
556556
myop.op_flags = (ix ? OPf_WANT_SCALAR : OPf_WANT_LIST ) | OPf_STACKED;
557557
myop.op_ppaddr = PL_ppaddr[OP_READLINE];
558558
myop.op_type = OP_READLINE;
559-
/* I don't know if we need this, but it's correct as far as the control flow
560-
goes. However, if we *do* need it, do we need to set anything else up? */
561-
myop.op_next = PL_op->op_next;
559+
myop.op_next = NULL; /* return from the runops loop below after 1 op */
562560
/* Sigh, because pp_readline calls pp_rv2gv, and *it* has this wonderful
563561
state check for PL_op->op_type == OP_READLINE */
564562
PL_op = (OP *) &myop;
@@ -569,9 +567,12 @@ PPCODE:
569567
PUSHs(sv_newmortal());
570568
XPUSHs(io);
571569
PUTBACK;
570+
/* call a new runops loop for just the one op rather than just calling
571+
* pp_readline directly, as the former will handle the call coming
572+
* from a ref-counted stack */
572573
/* And effectively we get away with tail calling pp_readline, as it stacks
573574
exactly the return value(s) we need to return. */
574-
PL_ppaddr[OP_READLINE](aTHX);
575+
CALLRUNOPS(aTHX);
575576
PL_op = was;
576577
/* And we don't want to reach the line
577578
PL_stack_sp = sp;

0 commit comments

Comments
 (0)