Change 33280 by [EMAIL PROTECTED] on 2008/02/11 15:39:16

        Subject: [PATCH] Re: Unwanted warnings from "PerlIO::scalar"
        From: Ben Morrow <[EMAIL PROTECTED]>
        Date: Fri, 8 Feb 2008 13:50:09 +0000
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/ext/PerlIO/scalar/scalar.xs#18 edit
... //depot/perl/ext/PerlIO/t/scalar.t#14 edit

Differences ...

==== //depot/perl/ext/PerlIO/scalar/scalar.xs#18 (text) ====
Index: perl/ext/PerlIO/scalar/scalar.xs
--- perl/ext/PerlIO/scalar/scalar.xs#17~33052~  2008-01-23 01:51:35.000000000 
-0800
+++ perl/ext/PerlIO/scalar/scalar.xs    2008-02-11 07:39:16.000000000 -0800
@@ -31,8 +31,9 @@
                return -1;
            }
            s->var = SvREFCNT_inc(SvRV(arg));
-           if (!SvPOK(s->var) && SvTYPE(SvRV(arg)) > SVt_NULL)
-               (void)SvPV_nolen(s->var);
+           SvGETMAGIC(s->var);
+           if (!SvPOK(s->var) && SvOK(s->var))
+               (void)SvPV_nomg_const_nolen(s->var);
        }
        else {
            s->var =

==== //depot/perl/ext/PerlIO/t/scalar.t#14 (text) ====
Index: perl/ext/PerlIO/t/scalar.t
--- perl/ext/PerlIO/t/scalar.t#13~28903~        2006-09-29 08:10:41.000000000 
-0700
+++ perl/ext/PerlIO/t/scalar.t  2008-02-11 07:39:16.000000000 -0800
@@ -18,7 +18,7 @@
 
 $| = 1;
 
-use Test::More tests => 51;
+use Test::More tests => 55;
 
 my $fh;
 my $var = "aaa\n";
@@ -113,6 +113,47 @@
     is($warn, 0, "no warnings when writing to an undefined scalar");
 }
 
+{
+    use warnings;
+    my $warn = 0;
+    local $SIG{__WARN__} = sub { $warn++ };
+    for (1..2) {
+        open my $fh, '>', \my $scalar;
+        close $fh;
+    }
+    is($warn, 0, "no warnings when reusing a lexical");
+}
+
+{
+    use warnings;
+    my $warn = 0;
+    local $SIG{__WARN__} = sub { $warn++ };
+
+    my $fetch = 0;
+    {
+        package MgUndef;
+        sub TIESCALAR { bless [] }
+        sub FETCH { $fetch++; return undef }
+    }
+    tie my $scalar, MgUndef;
+
+    open my $fh, '<', \$scalar;
+    close $fh;
+    is($warn, 0, "no warnings reading a magical undef scalar");
+    is($fetch, 1, "FETCH only called once");
+}
+
+{
+    use warnings;
+    my $warn = 0;
+    local $SIG{__WARN__} = sub { $warn++ };
+    my $scalar = 3;
+    undef $scalar;
+    open my $fh, '<', \$scalar;
+    close $fh;
+    is($warn, 0, "no warnings reading an undef, allocated scalar");
+}
+
 my $data = "a non-empty PV";
 $data = undef;
 open(MEM, '<', \$data) or die "Fail: $!\n";
End of Patch.

Reply via email to