This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c:S_fold_constants: Add assertion
authorFather Chrysostomos <sprout@cpan.org>
Sun, 16 Jun 2013 06:17:59 +0000 (23:17 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 26 Jul 2013 06:47:59 +0000 (23:47 -0700)
This code correctly handles a value returned by a folded constant that
is a target or a mortal.

If it is neither, then it takes ownership of a reference count (with-
out doing SvREFCNT_inc), so it ends up sharing a reference count with
whatever owned it before.  That is only safe to do with immortals,
which is (afaict) the only other type of scalar that can get through
this code, so it is actually correct.

Changes elsewhere could easily break this, though, so add an
assertion.

op.c

diff --git a/op.c b/op.c
index a9ee2d1..65d3955 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3311,6 +3311,7 @@ S_fold_constants(pTHX_ OP *o)
            SvREFCNT_inc_simple_void(sv);
            SvTEMP_off(sv);
        }
+       else { assert(SvIMMORTAL(sv)); }
        break;
     case 3:
        /* Something tried to die.  Abandon constant folding.  */