This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make XS::APItest::establish_cleanup protect existing stacks
authorFather Chrysostomos <sprout@cpan.org>
Mon, 6 Jan 2014 00:09:35 +0000 (16:09 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 17 Jan 2014 01:58:37 +0000 (17:58 -0800)
It causes pp_entersub to be called in odd places, which can cause the
context stack to be reallocated when an outer function call (like
pp_leavesub) has a pointer into the context stack in a C auto.

cleanup.t was failing for me under PERL_DEBUG_READONLY_COW +
STRESS_REALLOC + threads, because the context stack was reallocated
and the old address then freed and reused for something else, being
zeroed in the mean time.  So pp_leavesub returned NULL (trying to
read retop from the context stack), causing the program to exit.
During global destruction, subs that had not be exited properly were
undefined, leading to:

1..3
Can't undef active subroutine during global destruction.

ext/XS-APItest/APItest.xs

index 181b1f6..1b8ec3f 100644 (file)
@@ -533,12 +533,14 @@ STATIC void
 THX_run_cleanup(pTHX_ void *cleanup_code_ref)
 {
     dSP;
+    PUSHSTACK;
     ENTER;
     SAVETMPS;
     PUSHMARK(SP);
     call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD);
     FREETMPS;
     LEAVE;
+    POPSTACK;
 }
 
 STATIC OP *