New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH _63] Slurping empty files #1002
Comments
From hansmu@xs4all.nlSlurping an empty file should produce a defined empty string. In current perls (_03 and _63), this only happens if $. == 0, undef $/; prints: not ok A comment in pp_hot.c suggests that the IOf_NOLINE flag The patch below clears the IOf_NOLINE flag when a handle is -- HansM --- doio.c.orig Wed Dec 8 07:23:10 1999 -/* flip-flop EOF state for a snarfed empty file */ for (;;) { Site configuration information for perl 5.00563: Configured by hansm at Mon Dec 13 02:03:09 MET 1999. Summary of my perl5 (revision 5.0 version 5 subversion 63) configuration: Locally applied patches: @INC for perl 5.00563: Environment for perl 5.00563: |
From @gsarOn Wed, 29 Dec 1999 03:38:04 +0100, Hans Mulder wrote:
The comment is certainly misleading. As I recall, the IoLINES()
The reason the flag was set/cleared in SNARF_EOF() was to avoid I think your patch effectively does: - || (IoFLAGS(io) & IOf_NOLINE) || IoLINES(io) || !RsSNARF(rs)) \ apart from making it an once-only thing rather than a flip-flop. Thanks. Sarathy |
From @gsarOn Wed, 29 Dec 1999 11:28:50 PST, I wrote:
This here is what I'm talking about. Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4736 by gsar@auger on 1999/12/29 21:04:59
slurp mode fix in change#2910 wasn't quite right (spotted by Hans
Mulder)
Affected files ...
... //depot/perl/doio.c#89 edit
... //depot/perl/pp_hot.c#151 edit
... //depot/perl/t/io/argv.t#10 edit
Differences ...
==== //depot/perl/doio.c#89 (text) ====
Index: perl/doio.c
--- perl/doio.c.~1~ Wed Dec 29 13:05:03 1999
+++ perl/doio.c Wed Dec 29 13:05:03 1999
@@ -452,6 +452,7 @@
}
#endif
IoIFP(io) = fp;
+ IoFLAGS(io) &= ~IOf_NOLINE;
if (writing) {
dTHR;
if (IoTYPE(io) == 's'
==== //depot/perl/pp_hot.c#151 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c.~1~ Wed Dec 29 13:05:03 1999
+++ perl/pp_hot.c Wed Dec 29 13:05:03 1999
@@ -1283,12 +1283,11 @@
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)
==== //depot/perl/t/io/argv.t#10 (xtext) ====
Index: perl/t/io/argv.t
--- perl/t/io/argv.t.~1~ Wed Dec 29 13:05:03 1999
+++ perl/t/io/argv.t Wed Dec 29 13:05:03 1999
@@ -5,29 +5,29 @@
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 @@
}
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 @@
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;
+open(try, '>Io_argv2.tmp') or die "Can't open temp file: $!";
close try;
-@ARGV = 'Io.argv.tmp';
+@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, '<Io.argv.tmp') or die "Can't open temp file: $!";
+open(try, '<Io_argv1.tmp') or die "Can't open temp file: $!";
+print while <try>;
+open(try, '<Io_argv2.tmp') or die "Can't open temp file: $!";
print while <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;
+ <F>; # set $. = 1
+ open F, $devnull or die;
+ print "not " unless defined(<F>);
+ print "ok 16\n";
+ print "not " if defined(<F>);
+ print "ok 17\n";
+ print "not " if defined(<F>);
+ print "ok 18\n";
+ open F, $devnull or die; # restart cycle again
+ print "not " unless defined(<F>);
+ print "ok 19\n";
+ print "not " if defined(<F>);
+ 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' }
End of Patch. |
From [Unknown Contact. See original ticket]Gurusamy Sarathy wrote:
That would change behaviour: in _03, if you read a number I think that this would be an improvement as it would be more And I think we also want to do + IoFLAGS(io) &= ~IOf_NOLINE; somewhere near the end of Perl_do_open9(). -- HansM |
Migrated from rt.perl.org#1952 (status was 'resolved')
Searchable as RT1952$
The text was updated successfully, but these errors were encountered: