Skip Menu |

This queue is for tickets about the IO-stringy CPAN distribution.

Report information
The Basics
Id: 12719
Status: new
Priority: 0/
Queue: IO-stringy

People
Owner: Nobody in particular
Requestors: murray [...] minty.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.110
Fixed in: (no value)



Subject: broken seek implementation, patch included
IO::Scalar functionality differs from basic file IO with respect to the seek() method. Bug can be reproduced with use IO::Scalar; my $fh; open($fh, '>/var/tmp/test.dat'); &test($fh); close($fh); $fh = new IO::Scalar; &test($fh); sub test { my $fh = shift; $fh->print('test'); print(tell($fh)); seek($fh, 0,0); print(tell($fh)); $fh->print('test'); print(tell($fh) . "\n"); } It will print 404 408 Patch attached fixes this, however it causes unit tests to break.
421c421,442 < *$self->{Pos} = length(${*$self->{SR}} .= join('', @_) . (defined($\) ? $\ : "")); --- > > my $curpos = *$self->{Pos}; > my $data = join('', @_) . (defined($\) ? $\ : ""); > my $datlen = length($data); > my $curlen = length(${*$self->{SR}}); > > if ($curpos == $curlen) { > ${*$self->{SR}} .= $data; > *$self->{Pos} = $curpos + $datlen; > return(1); > } > > my $sum = $curpos + $datlen; > if ($sum > $curlen) { > ${*$self->{SR}} = substr(${*$self->{SR}}, 0, $curpos) . $data; > *$self->{Pos} = $sum; > } > else { > substr(${*$self->{SR}}, $curpos, $datlen) = $data; > *$self->{Pos} = $sum; > } >
From: adamk [...] cpan.org
[guest - Sat May 7 15:52:43 2005]: Show quoted text
> IO::Scalar functionality differs from basic file IO with respect to > the seek() method. Bug can be reproduced with > > use IO::Scalar; > my $fh; > open($fh, '>/var/tmp/test.dat'); > &test($fh); > close($fh); > $fh = new IO::Scalar; > &test($fh); > > sub test { > my $fh = shift; > $fh->print('test'); print(tell($fh)); > seek($fh, 0,0); print(tell($fh)); > $fh->print('test'); print(tell($fh) . "\n"); > } > > It will print > > 404 > 408 > > Patch attached fixes this, however it causes unit tests to break.
Generally bug reports of this nature work better if you can express the demonstration code in the form of a unit test script (or fragment). If you can't that's fine, but it gives the guy a more concrete way of proving your patch does the right thing, doesn't cause harm, and working out if it breaks later. Find attached the unit test form of what you just said.
#!/usr/bin/perl -w # Holds regression tests use strict; use Test::More tests => 16; # Load the modules to be tested during this file use_ok( 'IO::Scalar' ); ##################################################################### # CPAN Bug #12719 diag("CPAN #12719 - broken seek/tell implementation"); diag("Testing against IO::Scalar $IO::Scalar::VERSION"); # Reconfirm that seek for read works SCOPE: { my $string = "foo\nbar\n"; my $fh = IO::Scalar->new( \$string ); isa_ok( $fh, 'IO::Scalar' ); is( scalar(<$fh>), "foo\n", '<$fh> reads one line' ); ok( $fh->seek(0,0), '->seek(0,0) returns true' ); is( scalar(<$fh>), "foo\n", '<$fh> returns the same value' ); is( scalar(<$fh>), "bar\n", '<$fh> returns the next value' ); } SCOPE: { # Create an empty IO::Scalar my $string = ''; my $fh = IO::Scalar->new( \$string ); isa_ok( $fh, 'IO::Scalar' ); # Write to it ok( $fh->print('four'), '->print(four) returns true' ); is( $fh->tell, 4, '->tell returns 4' ); is( $string, 'four', 'String is set correctly' ); # Seek back to the start ok( $fh->seek( 0, 0 ), '->seek(0,0) returns true' ); is( $fh->tell, 0, '->tell returns 0' ); is( $string, 'four', 'String is unchanged' ); # Overwrite the first 3 chars ok( $fh->print('bar'), '->print(bar) returns true' ); is( $fh->tell, 3, '->tell back to 3 again' ); is( $string, 'barr', 'First three chars are changed' ); } 1;