diff options
author | David Mitchell <davem@iabyn.com> | 2023-01-19 14:11:28 +0000 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-28 20:53:51 +0800 |
commit | fecade69c526caa9c157a2405486b9089047fc72 (patch) | |
tree | d51961de6f06d4700c5bc8f6d6d96e855018999a /pp_ctl.c | |
parent | 214a9432e04871da2b88eba02ea3f1148a99f9c8 (diff) | |
download | perl-fecade69c526caa9c157a2405486b9089047fc72.tar.gz |
eval_sv(): call pp_entereval() via runops
Like the previous commit which did it for amagic_call() and call_sv(),
this commit makes executing the faked-up OP_ENTEREVAL be executed as
part of the runops loop rather than as a separate call. This is to allow
shortly fixing up for a reference-counted stack. (CALLRUNOPS() will
reify the stack if necessary, while the raw call to pp_entereval() won't
fix up the stack unless its part of the runops loop too.)
However, this is a bit more complex than call_sv() etc in that there is
a good reason for calling pp_entereval() separately. The faked up
OP_ENTEREVAL has its op_next set to NULL - this is the op which would
normally be returned on failure of the eval compilation. By seeing
whether the retuned value from pp_entereval() is NULL or not, eval_sv()
can tell whether compilation failed.
On the other hand, if pp_entereval() was made to be called as part of
the runops loop, then the runops loop *always* finishes with PL_op set
to NULL. So we can no lo longer distinguish between compile-failed and
compile-succeeded-and-eval-ran-to-completion.
This commit moves the entereval into the runops loop, but restores the
ability to distinguish in a slightly hacky way. It adds a new private
flag for OP_ENTEREVAL - OPpEVAL_EVALSV - which indicates to
pp_entereval() that it was called from eval_sv(). And of course
eval_sv() sets this flag on the OPpEVAL_EVALSV op it fakes up. If
pp_entereval() fails to compile, then if that flag is set, it pushes a
null pointer onto the argument stack before returning.
Thus by checking whether *PL_stack_sp is NULL or not on return from
CALLRUNOPS(), eval_sv() regains the ability to distinguish the two
cases.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -5116,6 +5116,9 @@ PP(pp_entereval) } else if (!saved_delete) { (void)hv_delete(PL_defstash, tmpbuf, len, G_DISCARD); } + if (PL_op->op_private & OPpEVAL_EVALSV) + /* signal compiletime failure to our eval_sv() caller */ + *++PL_stack_sp = NULL; return PL_op->op_next; } } |