Don’t give unavailability warnings about our vars
authorFather Chrysostomos <sprout@cpan.org>
Sat, 24 Aug 2013 12:54:23 +0000 (05:54 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 24 Aug 2013 13:28:56 +0000 (06:28 -0700)
Commit ce0d59fdd1c started using NULL to indicate nonexistent array
elements.  Since pads are AVs, they are filled with NULLs initially,
rather than &PL_sv_undef.

For ‘our’ vars, the pad entry is never actually touched.  Only one
piece of code was inspecting it, namely S_cv_clone_pad.  &PL_sv_undef
just happens to pass the checks that make sure the var is not stale.
However, we really should not be checking that at all if this is an
‘our’ var.

Even if we change ‘our’ vars back to having a &PL_sv_undef pad
entry, this fix should stay, as it makes the code clearer and makes
S_cv_clone_pad more robust.

pad.c
t/lib/warnings/pad

diff --git a/pad.c b/pad.c
index 92765f0..a034d09 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -2073,6 +2073,10 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside, bool newcv)
        SV* const namesv = (ix <= fname) ? pname[ix] : NULL;
        SV *sv = NULL;
        if (namesv && PadnameLEN(namesv)) { /* lexical */
+         if (PadnameIsOUR(namesv)) { /* or maybe not so lexical */
+               NOOP;
+         }
+         else {
            if (SvFAKE(namesv)) {   /* lexical from outside? */
                /* formats may have an inactive, or even undefined, parent;
                   but state vars are always available. */
@@ -2126,6 +2130,7 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside, bool newcv)
                if (sigil != '&' && SvPAD_STATE(namesv))
                    SvPADSTALE_on(sv);
            }
+         }
        }
        else if (IS_PADGV(ppad[ix]) || (namesv && PadnamePV(namesv))) {
            sv = SvREFCNT_inc_NN(ppad[ix]);
index 03c4ddb..4e31fe3 100644 (file)
@@ -227,6 +227,13 @@ sub x {
 EXPECT
 
 ########
+# pad.c
+use warnings 'closure';
+my $x;
+our $y;
+sub { $x = $y }->();  # should not warn about $y being unavailable
+EXPECT
+########
 use warnings 'misc' ;
 my $x;
 {