From: Gurusamy Sarathy Date: Wed, 29 Dec 1999 21:04:59 +0000 (+0000) Subject: slurp mode fix in change#2910 wasn't quite right (spotted by Hans X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=684bef36d5078e84d816e42ce6a73ae4452da2d7;p=p5sagit%2Fp5-mst-13.2.git slurp mode fix in change#2910 wasn't quite right (spotted by Hans Mulder) p4raw-link: @2910 on //depot/perl: fbad3eb55c1f8c84d1dfd0e484ecddeffc891e79 p4raw-id: //depot/perl@4736 --- diff --git a/doio.c b/doio.c index c13228a..4571b2c 100644 --- a/doio.c +++ b/doio.c @@ -452,6 +452,7 @@ Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw, } #endif IoIFP(io) = fp; + IoFLAGS(io) &= ~IOf_NOLINE; if (writing) { dTHR; if (IoTYPE(io) == 's' diff --git a/pp_hot.c b/pp_hot.c index a22ad06..aae168f 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1283,12 +1283,11 @@ Perl_do_readline(pTHX) offset = 0; } -/* flip-flop EOF state for a snarfed empty file */ +/* delay EOF state for a snarfed empty file */ #define SNARF_EOF(gimme,rs,io,sv) \ - ((gimme != G_SCALAR || SvCUR(sv) \ - || (IoFLAGS(io) & IOf_NOLINE) || IoLINES(io) || !RsSNARF(rs)) \ - ? ((IoFLAGS(io) &= ~IOf_NOLINE), TRUE) \ - : ((IoFLAGS(io) |= IOf_NOLINE), FALSE)) + (gimme != G_SCALAR || SvCUR(sv) \ + || !RsSNARF(rs) || (IoFLAGS(io) & IOf_NOLINE) \ + || ((IoFLAGS(io) |= IOf_NOLINE), FALSE)) for (;;) { if (!sv_gets(sv, fp, offset) diff --git a/t/io/argv.t b/t/io/argv.t index 3695e8a..d6093f9 100755 --- a/t/io/argv.t +++ b/t/io/argv.t @@ -5,29 +5,29 @@ BEGIN { unshift @INC, '../lib'; } -print "1..14\n"; +print "1..20\n"; use File::Spec; my $devnull = File::Spec->devnull; -open(try, '>Io.argv.tmp') || (die "Can't open temp file: $!"); +open(try, '>Io_argv1.tmp') || (die "Can't open temp file: $!"); print try "a line\n"; close try; if ($^O eq 'MSWin32') { - $x = `.\\perl -e "while (<>) {print \$.,\$_;}" Io.argv.tmp Io.argv.tmp`; + $x = `.\\perl -e "while (<>) {print \$.,\$_;}" Io_argv1.tmp Io_argv1.tmp`; } else { - $x = `./perl -e 'while (<>) {print \$.,\$_;}' Io.argv.tmp Io.argv.tmp`; + $x = `./perl -e 'while (<>) {print \$.,\$_;}' Io_argv1.tmp Io_argv1.tmp`; } if ($x eq "1a line\n2a line\n") {print "ok 1\n";} else {print "not ok 1\n";} if ($^O eq 'MSWin32') { - $x = `.\\perl -le "print 'foo'" | .\\perl -e "while (<>) {print \$_;}" Io.argv.tmp -`; + $x = `.\\perl -le "print 'foo'" | .\\perl -e "while (<>) {print \$_;}" Io_argv1.tmp -`; } else { - $x = `echo foo|./perl -e 'while (<>) {print $_;}' Io.argv.tmp -`; + $x = `echo foo|./perl -e 'while (<>) {print $_;}' Io_argv1.tmp -`; } if ($x eq "a line\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";} @@ -39,7 +39,7 @@ else { } if ($x eq "foo\n") {print "ok 3\n";} else {print "not ok 3 :$x:\n";} -@ARGV = ('Io.argv.tmp', 'Io.argv.tmp', $devnull, 'Io.argv.tmp'); +@ARGV = ('Io_argv1.tmp', 'Io_argv1.tmp', $devnull, 'Io_argv1.tmp'); while (<>) { $y .= $. . $_; if (eof()) { @@ -52,49 +52,74 @@ if ($y eq "1a line\n2a line\n3a line\n") else {print "not ok 5\n";} -open(try, '>Io.argv.tmp') or die "Can't open temp file: $!"; +open(try, '>Io_argv1.tmp') or die "Can't open temp file: $!"; close try; -@ARGV = 'Io.argv.tmp'; +open(try, '>Io_argv2.tmp') or die "Can't open temp file: $!"; +close try; +@ARGV = ('Io_argv1.tmp', 'Io_argv2.tmp'); $^I = '.bak'; $/ = undef; +my $i = 6; while (<>) { - s/^/ok 6\n/; + s/^/ok $i\n/; + ++$i; print; } -open(try, '; +open(try, '; close try; undef $^I; eof try or print 'not '; -print "ok 7\n"; +print "ok 8\n"; eof NEVEROPENED or print 'not '; -print "ok 8\n"; +print "ok 9\n"; -open STDIN, 'Io.argv.tmp' or die $!; +open STDIN, 'Io_argv1.tmp' or die $!; @ARGV = (); !eof() or print 'not '; -print "ok 9\n"; +print "ok 10\n"; <> eq "ok 6\n" or print 'not '; -print "ok 10\n"; +print "ok 11\n"; open STDIN, $devnull or die $!; @ARGV = (); eof() or print 'not '; -print "ok 11\n"; +print "ok 12\n"; -@ARGV = ('Io.argv.tmp'); +@ARGV = ('Io_argv1.tmp'); !eof() or print 'not '; -print "ok 12\n"; +print "ok 13\n"; @ARGV = ($devnull, $devnull); !eof() or print 'not '; -print "ok 13\n"; +print "ok 14\n"; close ARGV or die $!; eof() or print 'not '; -print "ok 14\n"; +print "ok 15\n"; + +{ + local $/; + open F, 'Io_argv1.tmp' or die; + ; # set $. = 1 + open F, $devnull or die; + print "not " unless defined(); + print "ok 16\n"; + print "not " if defined(); + print "ok 17\n"; + print "not " if defined(); + print "ok 18\n"; + open F, $devnull or die; # restart cycle again + print "not " unless defined(); + print "ok 19\n"; + print "not " if defined(); + print "ok 20\n"; + close F; +} -END { unlink 'Io.argv.tmp', 'Io.argv.tmp.bak' } +END { unlink 'Io_argv1.tmp', 'Io_argv1.tmp.bak', 'Io_argv2.tmp', 'Io_argv2.tmp.bak' }