diff options
author | Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> | 2017-06-02 17:30:22 +0100 |
---|---|---|
committer | Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> | 2017-06-05 16:06:41 +0100 |
commit | 489c16bfa14d460701bd76a4a4f0658f1200509a (patch) | |
tree | 949129fa1a01b8e7762f81215537c94d6658351a | |
parent | 9de35bb263b4599827a76615d5e6ef08fb7e32c6 (diff) | |
download | perl-489c16bfa14d460701bd76a4a4f0658f1200509a.tar.gz |
Disallow opening the same symbol as both a file and directory handle
This has been deprecated since Perl 5.10
-rw-r--r-- | pod/perldelta.pod | 5 | ||||
-rw-r--r-- | pod/perldiag.pod | 20 | ||||
-rw-r--r-- | pp_sys.c | 8 | ||||
-rw-r--r-- | t/lib/croak/pp_sys | 59 | ||||
-rw-r--r-- | t/lib/warnings/pp_sys | 59 | ||||
-rw-r--r-- | t/op/chdir.t | 23 | ||||
-rw-r--r-- | t/op/stat.t | 29 |
7 files changed, 80 insertions, 123 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 9024a270dd..ffd2c5f2f6 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -65,6 +65,11 @@ respectively. This has been deprecated since Perl 5.24. +=head2 Opening the same symbol as both a file and directory handle is no longer allowed + +Using open() and opendir() to associate both a filehandle and a dirhandle +to the same symbol (glob or scalar) has been deprecated since Perl 5.10. + =head1 Deprecations XXX Any deprecated features, syntax, modules etc. should be listed here. diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 31ace36725..8853d459ce 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4275,21 +4275,21 @@ that isn't open. Check your control flow. See also L<perlfunc/-X>. (S internal) An internal warning that the grammar is screwed up. -=item Opening dirhandle %s also as a file. This will be a fatal error in Perl 5.28 +=item Cannot open %s as a filehandle: it is already open as a dirhandle -(D io, deprecated) You used open() to associate a filehandle to +(F) You tried to use 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 this was deprecated in Perl 5.10. In Perl 5.28, this -will be a fatal error. +This idiom might render your code confusing +and this was deprecated in Perl 5.10. As of Perl 5.28, this +is a fatal error. -=item Opening filehandle %s also as a directory. This will be a fatal error in Perl 5.28 +=item Cannot open %s as a dirhandle: it is already open as a filehandle -(D io, deprecated) You used opendir() to associate a dirhandle to +(F) You tried to use 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 this was deprecated in Perl 5.10. In Perl 5.28, this -will be a fatal error. +This idiom might render your code confusing +and this was deprecated in Perl 5.10. As of Perl 5.28, this +is a fatal error. =item Operand with no preceding operator in regex; marked by S<<-- HERE> in m/%s/ @@ -629,8 +629,7 @@ PP(pp_open) IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT; if (IoDIRP(io)) - Perl_ck_warner_d(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED), - "Opening dirhandle %" HEKf " also as a file. This will be a fatal error in Perl 5.28", + Perl_croak(aTHX_ "Cannot open %" HEKf " as a filehandle: it is already open as a dirhandle", HEKfARG(GvENAME_HEK(gv))); mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar); @@ -4021,9 +4020,8 @@ PP(pp_open_dir) IO * const io = GvIOn(gv); if ((IoIFP(io) || IoOFP(io))) - Perl_ck_warner_d(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED), - "Opening filehandle %" HEKf " also as a directory. This will be a fatal error in Perl 5.28", - HEKfARG(GvENAME_HEK(gv)) ); + Perl_croak(aTHX_ "Cannot open %" HEKf " as a dirhandle: it is already open as a filehandle", + HEKfARG(GvENAME_HEK(gv))); if (IoDIRP(io)) PerlDir_close(IoDIRP(io)); if (!(IoDIRP(io) = PerlDir_open(dirname))) diff --git a/t/lib/croak/pp_sys b/t/lib/croak/pp_sys index 739b7e95af..8b7dc9d53d 100644 --- a/t/lib/croak/pp_sys +++ b/t/lib/croak/pp_sys @@ -14,3 +14,62 @@ pipe($fh, $$5) EXPECT Bad symbol for filehandle at - line 2. ######## +# NAME open on global dirhandle +opendir FOO, "."; +open FOO, "../harness"; +EXPECT +Cannot open FOO as a filehandle: it is already open as a dirhandle at - line 2. +######## +# NAME open on lexical dirhandle +opendir my $foo, "."; +open $foo, "../harness"; +EXPECT +Cannot open $foo as a filehandle: it is already open as a dirhandle at - line 2. +######## +# NAME open on global utf8 dirhandle +use utf8; +use open qw( :utf8 :std ); +use warnings; +opendir FOO, "."; +open FOO, "../harness"; +EXPECT +Cannot open FOO as a filehandle: it is already open as a dirhandle at - line 5. +######## +# NAME open on lexical utf8 dirhandle +use utf8; +use open qw( :utf8 :std ); +use warnings; +opendir my $foo, "."; +open $foo, "../harness"; +EXPECT +Cannot open $foo as a filehandle: it is already open as a dirhandle at - line 5. +######## +# NAME opendir on global filehandle +open FOO, "../harness"; +opendir FOO, "."; +EXPECT +Cannot open FOO as a dirhandle: it is already open as a filehandle at - line 2. +######## +# NAME opendir on lexical filehandle +open my $foo, "../harness"; +opendir $foo, "."; +EXPECT +Cannot open $foo as a dirhandle: it is already open as a filehandle at - line 2. +######## +# NAME opendir on global utf8 filehandle +use utf8; +use open qw( :utf8 :std ); +use warnings; +open FOO, "../harness"; +opendir FOO, "."; +EXPECT +Cannot open FOO as a dirhandle: it is already open as a filehandle at - line 5. +######## +# NAME opendir on lexical utf8 filehandle +use utf8; +use open qw( :utf8 :std ); +use warnings; +open my $foo, "../harness"; +opendir $foo, "."; +EXPECT +Cannot open $foo as a dirhandle: it is already open as a filehandle at - line 5. diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys index 9c544e088b..337defdb5e 100644 --- a/t/lib/warnings/pp_sys +++ b/t/lib/warnings/pp_sys @@ -761,65 +761,6 @@ 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, "../harness"; -open $foo, "../harness"; -no warnings qw(io deprecated); -open FOO, "../harness"; -open $foo, "../harness"; -EXPECT -Opening dirhandle FOO also as a file. This will be a fatal error in Perl 5.28 at - line 5. -Opening dirhandle $foo also as a file. This will be a fatal error in Perl 5.28 at - line 6. -######## - -# pp_sys.c [pp_open] -use utf8; -use open qw( :utf8 :std ); -use warnings; -opendir FOO, "."; -opendir $foo, "."; -open FOO, "../harness"; -open $foo, "../harness"; -no warnings qw(io deprecated); -open FOO, "../harness"; -open $foo, "../harness"; -EXPECT -Opening dirhandle FOO also as a file. This will be a fatal error in Perl 5.28 at - line 8. -Opening dirhandle $foo also as a file. This will be a fatal error in Perl 5.28 at - line 9. -######## -# pp_sys.c [pp_open_dir] -use warnings; -open FOO, "../harness"; -open my $foo, "../harness"; -opendir FOO, "."; -opendir $foo, "."; -no warnings qw(io deprecated); -opendir FOO, "."; -opendir $foo, "."; -EXPECT -Opening filehandle FOO also as a directory. This will be a fatal error in Perl 5.28 at - line 5. -Opening filehandle $foo also as a directory. This will be a fatal error in Perl 5.28 at - line 6. -######## - -# pp_sys.c [pp_open_dir] -use utf8; -use open qw( :utf8 :std ); -use warnings; -use warnings; -open FOO, "../harness"; -open $foo, "../harness"; -opendir FOO, "."; -opendir $foo, "."; -no warnings qw(io deprecated); -opendir FOO, "."; -opendir $foo, "."; -EXPECT -Opening filehandle FOO also as a directory. This will be a fatal error in Perl 5.28 at - line 9. -Opening filehandle $foo also as a directory. This will be a fatal error in Perl 5.28 at - line 10. -######## # pp_sys.c [pp_*dir] use Config ; BEGIN { diff --git a/t/op/chdir.t b/t/op/chdir.t index 38cbbe92bd..0ce83d0673 100644 --- a/t/op/chdir.t +++ b/t/op/chdir.t @@ -12,7 +12,7 @@ BEGIN { set_up_inc(qw(t . lib ../lib)); } -plan(tests => 48); +plan(tests => 44); use Config; use Errno qw(ENOENT EBADF EINVAL); @@ -86,26 +86,7 @@ SKIP: { } ok(-d "op", "verify that we are back"); - # And now the ambiguous case - { - no warnings qw<io deprecated>; - ok(opendir(H, "op"), "opendir op") or diag $!; - ok(open(H, "<", "base"), "open base") or diag $!; - } - if ($has_dirfd) { - ok(chdir(H), "fchdir to op"); - ok(-f "chdir.t", "verify that we are in 'op'"); - chdir ".." or die $!; - } - else { - eval { chdir(H); }; - like($@, qr/^The dirfd function is unimplemented at/, - "dirfd is unimplemented"); - SKIP: { - skip("dirfd is unimplemented"); - } - } - ok(closedir(H), "closedir"); + ok(open(H, "<", "base"), "open base") or diag $!; ok(chdir(H), "fchdir to base"); ok(-f "cond.t", "verify that we are in 'base'"); ok(close(H), "close"); diff --git a/t/op/stat.t b/t/op/stat.t index 323c4982fc..a5bb018f62 100644 --- a/t/op/stat.t +++ b/t/op/stat.t @@ -25,7 +25,7 @@ if ($^O eq 'MSWin32') { ${^WIN32_SLOPPY_STAT} = 0; } -plan tests => 118; +plan tests => 108; my $Perl = which_perl(); @@ -561,20 +561,7 @@ SKIP: { ok(stat(DIR), "stat() on dirhandle works"); ok(-d -r _ , "chained -x's on dirhandle"); ok(-d DIR, "-d on a dirhandle works"); - - # And now for the ambiguous bareword case - { - no warnings 'deprecated'; - ok(open(DIR, "TEST"), 'Can open "TEST" dir') - || diag "Can't open 'TEST': $!"; - } - my $size = (stat(DIR))[7]; - ok(defined $size, "stat() on bareword works"); - is($size, -s "TEST", "size returned by stat of bareword is for the file"); - ok(-f _, "ambiguous bareword uses file handle, not dir handle"); - ok(-f DIR); closedir DIR or die $!; - close DIR or die $!; } { @@ -594,21 +581,7 @@ SKIP: { ok(stat(*DIR{IO}), "stat() on *DIR{IO} works"); ok(-d _ , "The special file handle _ is set correctly"); ok(-d -r *DIR{IO} , "chained -x's on *DIR{IO}"); - - # And now for the ambiguous bareword case - { - no warnings 'deprecated'; - ok(open(DIR, "TEST"), 'Can open "TEST" dir') - || diag "Can't open 'TEST': $!"; - } - my $size = (stat(*DIR{IO}))[7]; - ok(defined $size, "stat() on *THINGY{IO} works"); - is($size, -s "TEST", - "size returned by stat of *THINGY{IO} is for the file"); - ok(-f _, "ambiguous *THINGY{IO} uses file handle, not dir handle"); - ok(-f *DIR{IO}); closedir DIR or die $!; - close DIR or die $!; } } |