develooper Front page | perl.perl5.porters | Postings from April 2007

[PATCH] Blocking Tie::File test under Sunos

Thread Next
From:
Heiko
Date:
April 17, 2007 16:34
Subject:
[PATCH] Blocking Tie::File test under Sunos
Message ID:
46255988.5080109@hexco.de
Hello,

Andy Dougherty wrote in perlsolaris:

 >Running the test suite in SunOS 4.1 is a bit tricky since the 
*/>lib/Tie/File/t/09_gen_rs/* test hangs (subtest #51, FWIW) for some 
unknown >reason. Just stop the test and kill that particular Perl process.

The subtest #51 is correct, although the reason is not unknown anymore :-)

It was an endless loop in file lib/Tie/File.pm, sub _fill_offsets():
  while ( defined $self->_read_record()) {
    # int() saves us memory here
    push @OFF, int(tell $fh);
  }

_read_record()
1. reads upto EOF
2. appends the missing newline
in the next invocation
3. reads again and expects EOF, but gets the appended newline.
  So the current file position was not incremented for reading :-(

Later invocations of _read_record():
Now it gets scary, since <$fh> happily returns more and
more content from memory without reaching EOF. It is
probably beyond it.

My patch adds a call of
seek $fh, 0, SEEK_END
after the newline has been appended. The effect is that
eof($fh) is true after that. Proper libc implementations
wont need this, but Sun did not sync the file pointers during
read, modify, read.

Mark-Jason, I have also traced the reduced testcase
under Linux and SunOS, if you want more details for
the failure. Its in the appendix.

It would be interesting to hear your opinion.

Greetings,
Heiko

*** perl-5.9.4/lib/Tie/File.pm    Tue Aug 15 14:37:41 2006
--- perl-5.9.4-patched/lib/Tie/File.pm    Wed Apr 18 01:22:51 2007
***************
*** 2,8 ****
  package Tie::File;
  require 5.005;
  use Carp ':DEFAULT', 'confess';
! use POSIX 'SEEK_SET';
  use Fcntl 'O_CREAT', 'O_RDWR', 'LOCK_EX', 'LOCK_SH', 'O_WRONLY', 
'O_RDONLY';
  sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY }
 
--- 2,8 ----
  package Tie::File;
  require 5.005;
  use Carp ':DEFAULT', 'confess';
! use POSIX 'SEEK_SET', 'SEEK_END';
  use Fcntl 'O_CREAT', 'O_RDWR', 'LOCK_EX', 'LOCK_SH', 'O_WRONLY', 
'O_RDONLY';
  sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY }
 
***************
*** 926,931 ****
--- 926,932 ----
        local $\ = "";
        my $fh = $self->{fh};
        print $fh $self->{recsep};
+       seek $fh, 0, SEEK_END;
      }
      $rec .= $self->{recsep};
    }


Thread Next


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