develooper Front page | perl.perl5.porters | Postings from September 2005

Re: [BUG 5.8.7] Another major bug in PerlIO layer

Thread Previous | Thread Next
From:
Ilya Zakharevich
Date:
September 25, 2005 03:46
Subject:
Re: [BUG 5.8.7] Another major bug in PerlIO layer
Message ID:
20050924072440.GA2849@math.berkeley.edu
On Fri, Sep 23, 2005 at 10:40:27PM -0700, Ilya Zakharevich wrote:
> Let me repeat it yet again: it should be easier to rewrite PerlIO
> stuff from scratch than try to fix bugs in it.
> 
> Example (on unix):
> 
>  unix2dos .tcshrc | perl -we 'binmode STDIN, ":crlf" or die; print while read STDIN, $_, 32000'

...

> (Yes, it makes a seek() in the process of conversion "\r\n" to "\n".
> This is why the call works - accidentally - with plain files.)

One can better understand how it works now by makeing a file (as in
  perl -wle 'binmode STDOUT, ":crlf"; $c = shift;
	     print "0123456789" while $c--' 4e5 > /tmp/l
) and running
  truss perl -we 'binmode STDIN, ":crlf" or die;
		  1 while read STDIN, $_, 32000' < /tmp/l

on it.  It goes like this:

  fstat64(0, 0xFFBFEB08)                          = 0
  read(0, " 0 1 2 3 4 5 6 7 8 9\r\n".., 8192)     = 8192
  llseek(0, 12, SEEK_SET)                         = 12
  llseek(0, 0, SEEK_CUR)                          = 12
  read(0, " 0 1 2 3 4 5 6 7 8 9\r\n".., 8192)     = 8192
  llseek(0, 24, SEEK_SET)                         = 24
  llseek(0, 0, SEEK_CUR)                          = 24
  read(0, " 0 1 2 3 4 5 6 7 8 9\r\n".., 8192)     = 8192
  llseek(0, 36, SEEK_SET)                         = 36
  llseek(0, 0, SEEK_CUR)                          = 36
  read(0, " 0 1 2 3 4 5 6 7 8 9\r\n".., 8192)     = 8192
  llseek(0, 48, SEEK_SET)                         = 48
  llseek(0, 0, SEEK_CUR)                          = 48

etc.  2 (sic!) seek()s and one read() (of 8K!) on each CR converted.
No wonder it goes as quick as 64KB/sec here...

Hope this helps,
Ilya

Thread Previous | 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