Skip to content

Commit ccf9d66

Browse files
committed
make RC-stack-aware: pp_readline(), pp_glob() etc
Remove the temporary wrappers from: pp_readline() pp_rcatline() pp_glob() pp_rv2gv() and dependent functions. This started out as an attempt to unwrap the simple pp_rv2gv() function. But pp_readline() calls pp_rv2gv() too, so that had to be unwrapped too. Then the bulk of pp_readline()'s implementation is done by do_readline(), so that had to be updated too. But pp_rcatline() and pp_glob() also call out to do_readline(), so they had to be fixed too. And pp_glob() outsources most of its work to the XS module File::Glob, so calling that had to be wrapped to handle a non-refcounted stack in the XS code. Then it turns out that code in IO.xs calls pp_readline() directly and needed tweaking. So now its a large commit that updates nearly everything in one big go. While fixing up everything, I took the opportunity to add many code comments and asserts to better document what these various functions do, and what args they expect on the stack under what flag conditions. The op_flag processing is now more strict, so potentially other code which directly fakes up an op with sloppy flag settings and calls one of these pp functions directly might now trigger an assert failure. (See the fix-up to IO.xs a couple of commits ago for an example.)
1 parent eb7b270 commit ccf9d66

File tree

4 files changed

+366
-81
lines changed

4 files changed

+366
-81
lines changed

gv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,13 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
41954195
res = newSV_type_mortal(SVt_PVAV);
41964196
av_extend((AV *)res, nret);
41974197
while (nret--)
4198+
/* Naughtily, we don't increment the ref counts
4199+
* of the items we push onto the temporary array.
4200+
* So we rely on the caller knowing not to decrement them,
4201+
* and to empty the array before there's any chance of
4202+
* it being freed. (Probably should either turn off
4203+
* AvREAL or actually increment.)
4204+
*/
41984205
av_store((AV *)res, nret, POPs);
41994206
break;
42004207
}

pp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ S_rv2gv(pTHX_ SV *sv, const bool vivify_sv, const bool strict,
186186
return sv;
187187
}
188188

189-
PP_wrapped(pp_rv2gv, 1, 0)
189+
190+
PP(pp_rv2gv)
190191
{
191-
dSP; dTOPss;
192+
SV *sv = *PL_stack_sp;
192193

193194
sv = S_rv2gv(aTHX_
194195
sv, PL_op->op_private & OPpDEREF,
@@ -198,10 +199,11 @@ PP_wrapped(pp_rv2gv, 1, 0)
198199
);
199200
if (PL_op->op_private & OPpLVAL_INTRO)
200201
save_gp(MUTABLE_GV(sv), !(PL_op->op_flags & OPf_SPECIAL));
201-
SETs(sv);
202-
RETURN;
202+
rpp_replace_1_1(sv);
203+
return NORMAL;
203204
}
204205

206+
205207
/* Helper function for pp_rv2sv and pp_rv2av/hv.
206208
*
207209
* Return a GV based on the value of sv, using symbolic references etc.

0 commit comments

Comments
 (0)