This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make POPSUB and POPFORMAT re-entrant safe
authorDavid Mitchell <davem@iabyn.com>
Mon, 19 Oct 2015 15:12:33 +0000 (16:12 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 09:18:30 +0000 (09:18 +0000)
commit656457d0493edca22133d31ca3c6ddbaa987e06c
treeb9c8d2bce03bc692e62dfd40ec17e56180cfea08
parentf284fecd86b66528552854be16564b432fd1480c
make POPSUB and POPFORMAT re-entrant safe

In code like

    sub DESTROY { exit }
    sub f { push @_, bless [] }
    f()

While leaving f, POPSUB will attempt to clear @_. This triggers the
destructor, which calls exit, which unwinds the context stack, calling
POPSUB again on thr same context stack entry.

Thus we need to to be careful that POPSUB can be called multiple times
on the same CX stack entry.

The general way of doing this is to NULL or update pointers *before*
calling SvREFCNT_dec() on the old value.

This commit also removes the old CxPOPSUB_DONE mechanism which was a poor
bandaid added at the last minute to 5.22 to try and achieve the basics
of what this commit does comprehensively (hopefully). Also, CxPOPSUB_DONE
was mainly a protection against re-entrantly calling LEAVE_SCOPE(). Since
that's now done before POPSUB rather than in the middle of it, it has
become reentrant-safe by default.
cop.h
pp_hot.c
pp_sys.c