From: Rafael Garcia-Suarez Date: Fri, 30 Mar 2007 07:48:59 +0000 (+0000) Subject: Add two deprecation warnings: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=abc718f2ca5cfe66c838e1324c1c153a085fea8b;p=p5sagit%2Fp5-mst-13.2.git Add two deprecation warnings: Opening dirhandle %s also as a file Opening filehandle %s also as a directory p4raw-id: //depot/perl@30780 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index b80331d..eeef207 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -2836,6 +2836,20 @@ that isn't open. Check your control flow. See also L. (S internal) An internal warning that the grammar is screwed up. +=item Opening dirhandle %s also as a file + +(W io deprecated) You used open() to associate a filehandle to +a symbol (glob or scalar) that already holds a dirhandle. +Although legal, this idiom might render your code confusing +and is deprecated. + +=item Opening filehandle %s also as a directory + +(W io deprecated) You used opendir() to associate a dirhandle to +a symbol (glob or scalar) that already holds a filehandle. +Although legal, this idiom might render your code confusing +and is deprecated. + =item Operation "%s": no method found, %s (F) An attempt was made to perform an overloaded operation for which no diff --git a/pp_sys.c b/pp_sys.c index 5693d50..aa36bef 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -538,10 +538,15 @@ PP(pp_open) if (!isGV(gv)) DIE(aTHX_ PL_no_usym, "filehandle"); + if ((io = GvIOp(gv))) { MAGIC *mg; IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT; + if (IoDIRP(io) && ckWARN2(WARN_IO, WARN_DEPRECATED)) + Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED), + "Opening dirhandle %s also as a file", GvENAME(gv)); + mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar); if (mg) { /* Method's args are same as ours ... */ @@ -3769,6 +3774,9 @@ PP(pp_open_dir) if (!io) goto nope; + if ((IoIFP(io) || IoOFP(io)) && ckWARN2(WARN_IO, WARN_DEPRECATED)) + Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED), + "Opening filehandle %s also as a directory", GvENAME(gv)); if (IoDIRP(io)) PerlDir_close(IoDIRP(io)); if (!(IoDIRP(io) = PerlDir_open(dirname))) diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys index 0dd3efe..2e9c613 100644 --- a/t/lib/warnings/pp_sys +++ b/t/lib/warnings/pp_sys @@ -494,3 +494,29 @@ chdir() on unopened filehandle FOO at - line 20. chdir() on closed filehandle BAR at - line 21. chdir() on unopened filehandle $dh at - line 22. chdir() on closed filehandle $fh at - line 23. +######## +# pp_sys.c [pp_open] +use warnings; +opendir FOO, "."; +opendir my $foo, "."; +open FOO, "TEST"; +open $foo, "TEST"; +no warnings qw(io deprecated); +open FOO, "TEST"; +open $foo, "TEST"; +EXPECT +Opening dirhandle FOO also as a file at - line 5. +Opening dirhandle $foo also as a file at - line 6. +######## +# pp_sys.c [pp_open_dir] +use warnings; +open FOO, "TEST"; +open my $foo, "TEST"; +opendir FOO, "."; +opendir $foo, "."; +no warnings qw(io deprecated); +opendir FOO, "."; +opendir $foo, "."; +EXPECT +Opening filehandle FOO also as a directory at - line 5. +Opening filehandle $foo also as a directory at - line 6. diff --git a/t/op/chdir.t b/t/op/chdir.t index 79b91ff..db58e12 100644 --- a/t/op/chdir.t +++ b/t/op/chdir.t @@ -78,8 +78,11 @@ SKIP: { ok(-d "op", "verify that we are back"); # And now the ambiguous case - ok(opendir(H, "op"), "opendir op") or diag $!; - ok(open(H, "<", "base"), "open base") or diag $!; + { + no warnings qw; + ok(opendir(H, "op"), "opendir op") or diag $!; + ok(open(H, "<", "base"), "open base") or diag $!; + } if (($Config{d_dirfd} || "") eq "define") { ok(chdir(H), "fchdir to op"); ok(-f "chdir.t", "verify that we are in 'op'");