develooper Front page | perl.perl5.porters | Postings from May 2003

Tie::File test failures on windows

From:
Gurusamy Sarathy
Date:
May 11, 2003 20:05
Subject:
Tie::File test failures on windows
Message ID:
200305120305.h4C35JXj005026@smtp3.ActiveState.com
In fixing the Tie::File test failures on windows, I seem to have run
into a strange problem that might be a bug in localizing globs.

The change entry explains it, so I've attached it.  Making the
following change to Tie/File.pm:

-    $fh = \do { local *FH };    # only works in 5.005 and later
+    $fh = \do { local *F1 };    # only works in 5.005 and later

makes the problem go away, so I suspect it has something to do
with how *FH is being used in the rest of Tie/File.pm and perhaps
in 09_gen_rs.t.


Sarathy
gsar@ActiveState.com
-----------------------------------8<-----------------------------------
Change 19498 by gsar@moonru on 2003/05/12 01:40:46

	fix for Tie::File test failures on windows: the problem was
	that Tie::File did not close any file handles it opens internally,
	leading to file handle leaks and t/tf* temporary file littering;
	we now close the handle iff Tie::File opened it
	
	this fix unearths what appears to be a perl bug in localizing globs:
	09_gen_rs.t fails due to a prematurely closed filehandle, although
	it wasn't explicitly closed anywhere by the code (renaming the
	*FH at line 97 to *FH1 makes it work, but I haven't done this
	to allow the bug to be tracked down)

Affected files ...

... //depot/perl/lib/Tie/File.pm#21 edit

Differences ...

==== //depot/perl/lib/Tie/File.pm#21 (text) ====
Index: perl/lib/Tie/File.pm
--- perl/lib/Tie/File.pm.~1~	Sun May 11 19:59:18 2003
+++ perl/lib/Tie/File.pm	Sun May 11 19:59:18 2003
@@ -97,6 +97,7 @@
     $fh = \do { local *FH };   # only works in 5.005 and later
     sysopen $fh, $file, $opts{mode}, 0666 or return;
     binmode $fh;
+    ++$opts{ourfh};
   }
   { my $ofh = select $fh; $| = 1; select $ofh } # autoflush on write
   if (defined $opts{discipline} && $] >= 5.006) {
@@ -407,6 +408,10 @@
   my $self = shift;
   $self->flush if $self->_is_deferring;
   $self->{cache}->delink if defined $self->{cache}; # break circular link
+  if ($self->{fh} and $self->{ourfh}) {
+      delete $self->{ourfh};
+      close delete $self->{fh};
+  }
 }
 
 sub _splice {
@@ -2289,6 +2294,11 @@
 supplied a non-seekable handle, the C<tie> call will throw an
 exception.  (On Unix systems, it can detect this.)
 
+Note that Tie::File will only close any filehandles that it opened
+internally.  If you passed it a filehandle as above, you "own" the
+filehandle, and are responsible for closing it after you have untied
+the @array.
+
 =head1 Deferred Writing
 
 (This is an advanced feature.  Skip this section on first reading.)
End of Patch.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About