I knew this didn't feel quite right somehow.
Turns out the hax/cx_pushblock I copied from mauke was wrong. It shouldn't ENTER; SAVETMPS. Instead, each callsite should do what is the right thing, but only on pre-5.24 perls.
Attached patch.
This also means I can delete the frame->scopename hacks as well.
--
Paul Evans
=== modified file 'hax/cx_pushblock.c.inc'
--- hax/cx_pushblock.c.inc 2018-01-15 18:20:52 +0000
+++ hax/cx_pushblock.c.inc 2019-04-13 19:35:37 +0000
@@ -9,9 +9,6 @@
PERL_CONTEXT *cx;
assert(saveix == PL_savestack_ix);
- ENTER;
- SAVETMPS;
-
PUSHBLOCK(cx, t, sp);
return cx;
}
=== modified file 'lib/Future/AsyncAwait.xs'
--- lib/Future/AsyncAwait.xs 2019-04-13 19:19:46 +0000
+++ lib/Future/AsyncAwait.xs 2019-04-13 19:35:37 +0000
@@ -1156,11 +1156,20 @@
switch(frame->type) {
case CXt_BLOCK:
+#if !HAVE_PERL_VERSION(5, 24, 0)
+ ENTER_with_name("block");
+ SAVETMPS;
+#endif
cx = cx_pushblock(CXt_BLOCK, frame->gimme, PL_stack_sp, PL_savestack_ix);
/* nothing else special */
break;
case CXt_LOOP_PLAIN:
+#if !HAVE_PERL_VERSION(5, 24, 0)
+ ENTER_with_name("loop1");
+ SAVETMPS;
+ ENTER_with_name("loop2");
+#endif
cx = cx_pushblock(frame->type, frame->gimme, PL_stack_sp, PL_savestack_ix);
/* don't call cx_pushloop_plain() because it will get this wrong */
cx->blk_loop = frame->el.loop;
@@ -1174,6 +1183,11 @@
#endif
case CXt_LOOP_LAZYSV:
case CXt_LOOP_LAZYIV:
+#if !HAVE_PERL_VERSION(5, 24, 0)
+ ENTER_with_name("loop1");
+ SAVETMPS;
+ ENTER_with_name("loop2");
+#endif
cx = cx_pushblock(frame->type, frame->gimme, PL_stack_sp, PL_savestack_ix);
/* don't call cx_pushloop_plain() because it will get this wrong */
cx->blk_loop = frame->el.loop;
@@ -1199,6 +1213,10 @@
if(CATCH_GET)
panic("Too late to docatch()\n");
+#if !HAVE_PERL_VERSION(5, 24, 0)
+ ENTER_with_name("eval_scope");
+ SAVETMPS;
+#endif
cx = cx_pushblock(CXt_EVAL|CXp_TRYBLOCK, frame->gimme,
PL_stack_sp, PL_savestack_ix);
cx_pusheval(cx, frame->el.eval.retop, NULL);