- DEBUG_STATE_r( PerlIO_printf(Perl_debug_log,
- " re EVAL PL_op=0x%"UVxf"\n", PTR2UV(PL_op)) );
- /* wrap the call in two SAVECOMPPADs. This ensures that
- * when the save stack is eventually unwound, all the
- * accumulated SAVEt_CLEARSV's will be processed with
- * interspersed SAVEt_COMPPAD's to ensure that lexicals
- * are cleared in the right pad */
- if (PL_comppad == new_comppad)
- old_comppad = new_comppad;
- else {
- SAVECOMPPAD();
- PAD_SAVE_LOCAL(old_comppad, new_comppad);
+
+ /* normally if we're about to execute code from the same
+ * CV that we used previously, we just use the existing
+ * CX stack entry. However, its possible that in the
+ * meantime we may have backtracked, popped from the save
+ * stack, and undone the SAVECOMPPAD(s) associated with
+ * PUSH_MULTICALL; in which case PL_comppad no longer
+ * points to newcv's pad. */
+ if (newcv != last_pushed_cv || PL_comppad != last_pad)
+ {
+ I32 depth = (newcv == caller_cv) ? 0 : 1;
+ if (last_pushed_cv) {
+ CHANGE_MULTICALL_WITHDEPTH(newcv, depth);
+ }
+ else {
+ PUSH_MULTICALL_WITHDEPTH(newcv, depth);
+ }
+ last_pushed_cv = newcv;
+ }
+ last_pad = PL_comppad;
+
+ /* the initial nextstate you would normally execute
+ * at the start of an eval (which would cause error
+ * messages to come from the eval), may be optimised
+ * away from the execution path in the regex code blocks;
+ * so manually set PL_curcop to it initially */
+ {
+ OP *o = cUNOPx(nop)->op_first;
+ assert(o->op_type == OP_NULL);
+ if (o->op_targ == OP_SCOPE) {
+ o = cUNOPo->op_first;
+ }
+ else {
+ assert(o->op_targ == OP_LEAVE);
+ o = cUNOPo->op_first;
+ assert(o->op_type == OP_ENTER);
+ o = o->op_sibling;
+ }
+
+ if (o->op_type != OP_STUB) {
+ assert( o->op_type == OP_NEXTSTATE
+ || o->op_type == OP_DBSTATE
+ || (o->op_type == OP_NULL
+ && ( o->op_targ == OP_NEXTSTATE
+ || o->op_targ == OP_DBSTATE
+ )
+ )
+ );
+ PL_curcop = (COP*)o;
+ }