Skip to content

Commit

Permalink
Merge pull request #2081 from rakudo/handle-6.d
Browse files Browse the repository at this point in the history
Rename IO::Handle's generic methods to .READ/.WRITE/.EOF
  • Loading branch information
zoffixznet committed Jul 16, 2018
2 parents 4766536 + 9246b03 commit 49363d6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
6 changes: 6 additions & 0 deletions src/core/IO/CatHandle.pm6
Expand Up @@ -422,6 +422,12 @@ my class IO::CatHandle is IO::Handle {
multi method say (|) { die X::NYI.new: :feature<say> }
proto method write (|) {*}
multi method write (|) { die X::NYI.new: :feature<write> }
proto method WRITE (|) {*}
multi method WRITE (|) { die X::NYI.new: :feature<WRITE> }
proto method READ (|) {*}
multi method READ (|) { die X::NYI.new: :feature<READ> }
proto method EOF (|) {*}
multi method EOF (|) { die X::NYI.new: :feature<EOF> }
# /|\

# Don't die on this one, as doing so breaks .Capture
Expand Down
47 changes: 24 additions & 23 deletions src/core/IO/Handle.pm6
Expand Up @@ -230,15 +230,15 @@ my class IO::Handle {

method eof(IO::Handle:D:) {
nqp::p6bool($!decoder
?? $!decoder.is-empty && self.eof-internal
!! self.eof-internal)
?? $!decoder.is-empty && self.EOF
!! self.EOF)
}

method eof-internal() {
method EOF() {
nqp::eoffh($!PIO)
}

method read-internal(Int:D $bytes) {
method READ(Int:D $bytes) {
nqp::readfh($!PIO,buf8.new,nqp::unbox_i($bytes))
}

Expand All @@ -249,17 +249,17 @@ my class IO::Handle {

method !get-line-slow-path() {
my $line := Nil;
unless self.eof-internal && $!decoder.is-empty {
unless self.EOF && $!decoder.is-empty {
loop {
my $buf := self.read-internal(0x100000);
my $buf := self.READ(0x100000);
if $buf.elems {
$!decoder.add-bytes($buf);
$line := $!decoder.consume-line-chars(:$!chomp);
last if nqp::isconcrete($line);
}
else {
$line := $!decoder.consume-line-chars(:$!chomp, :eof)
unless self.eof-internal && $!decoder.is-empty;
unless self.EOF && $!decoder.is-empty;
last;
}
}
Expand Down Expand Up @@ -468,15 +468,15 @@ my class IO::Handle {
# If we have one, read bytes via. the decoder to support mixed-mode I/O.
$!decoder
?? ($!decoder.consume-exactly-bytes($bytes) // self!read-slow-path($bytes))
!! self.read-internal($bytes)
!! self.READ($bytes)
}

method !read-slow-path($bytes) {
if self.eof-internal && $!decoder.is-empty {
if self.EOF && $!decoder.is-empty {
buf8.new
}
else {
$!decoder.add-bytes(self.read-internal($bytes max 0x100000));
$!decoder.add-bytes(self.READ($bytes max 0x100000));
$!decoder.consume-exactly-bytes($bytes)
// $!decoder.consume-exactly-bytes($!decoder.bytes-available)
// buf8.new
Expand All @@ -490,16 +490,17 @@ my class IO::Handle {

method !readchars-slow-path($chars) {
my $result := '';
unless self.eof-internal && $!decoder.is-empty {
unless self.EOF && $!decoder.is-empty {
loop {
my $buf := self.read-internal(0x100000);
my $buf := self.READ(0x100000);
if $buf.elems {
$!decoder.add-bytes($buf);
$result := $!decoder.consume-exactly-chars($chars);
last if nqp::isconcrete($result);
}
else {
$result := $!decoder.consume-exactly-chars($chars, :eof);
$result := $!decoder.consume-exactly-chars($chars, :eof)
unless self.EOF && $!decoder.is-empty;
last;
}
}
Expand Down Expand Up @@ -558,10 +559,10 @@ my class IO::Handle {
}

method write(IO::Handle:D: Blob:D $buf --> True) {
self.write-internal($buf)
self.WRITE($buf)
}

method write-internal(IO::Handle:D: Blob:D $buf --> True) {
method WRITE(IO::Handle:D: Blob:D $buf --> True) {
nqp::writefh($!PIO, nqp::decont($buf));
}

Expand Down Expand Up @@ -604,7 +605,7 @@ my class IO::Handle {
proto method print(|) {*}
multi method print(IO::Handle:D: Str:D \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<print>);
self.write-internal($!encoder.encode-chars(x));
self.WRITE($!encoder.encode-chars(x));
}
multi method print(IO::Handle:D: **@list is raw --> True) { # is raw gives List, which is cheaper
self.print(@list.join);
Expand All @@ -614,7 +615,7 @@ my class IO::Handle {
proto method put(|) {*}
multi method put(IO::Handle:D: Str:D \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<put>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s(x), nqp::unbox_s($!nl-out))))
}
multi method put(IO::Handle:D: **@list is raw --> True) { # is raw gives List, which is cheaper
Expand All @@ -624,12 +625,12 @@ my class IO::Handle {

multi method say(IO::Handle:D: Str:D $x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<say>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s($x), nqp::unbox_s($!nl-out))));
}
multi method say(IO::Handle:D: \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<say>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s(x.gist), nqp::unbox_s($!nl-out))))
}
multi method say(IO::Handle:D: |) {
Expand All @@ -643,7 +644,7 @@ my class IO::Handle {

method print-nl(IO::Handle:D: --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<print-nl>);
self.write-internal($!encoder.encode-chars($!nl-out));
self.WRITE($!encoder.encode-chars($!nl-out));
}

proto method slurp-rest(|) {*}
Expand Down Expand Up @@ -688,15 +689,15 @@ my class IO::Handle {
nqp::if(
nqp::isfalse($!decoder) || $bin,
nqp::while(
nqp::elems(my $buf := self.read-internal(0x100000)),
nqp::elems(my $buf := self.READ(0x100000)),
$res.append($buf))),
# don't sink result of .close; it might be a failed Proc
nqp::if($close, my $ = self.close),
$res)
}

method !slurp-all-chars() {
while nqp::elems(my $buf := self.read-internal(0x100000)) {
while nqp::elems(my $buf := self.READ(0x100000)) {
$!decoder.add-bytes($buf);
}
$!decoder.consume-all-chars()
Expand All @@ -705,7 +706,7 @@ my class IO::Handle {
proto method spurt(|) {*}
multi method spurt(IO::Handle:D: Blob $data, :$close) {
LEAVE self.close if $close;
self.write-internal($data);
self.WRITE($data);
}
multi method spurt(IO::Handle:D: Cool $data, :$close) {
LEAVE self.close if $close;
Expand Down
6 changes: 3 additions & 3 deletions src/core/IO/Pipe.pm6
Expand Up @@ -22,7 +22,7 @@ my class IO::Pipe is IO::Handle {
}
}

method read-internal($) {
method READ($) {
if $!on-read {
loop {
my \result = $!on-read();
Expand All @@ -40,11 +40,11 @@ my class IO::Pipe is IO::Handle {
}
}

method eof-internal() {
method EOF() {
$!eof
}

method write-internal($data) {
method WRITE($data) {
$!on-write
?? $!on-write($data)
!! die "This pipe was opened for reading, not writing"
Expand Down
17 changes: 0 additions & 17 deletions t/02-rakudo/07-io-cathandle.t

This file was deleted.

1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -21,6 +21,7 @@
# build/Makefile.in for examples of use.

APPENDICES/A01-limits/overflow.t
APPENDICES/A02-some-day-maybe/io-cathandle.t
MISC/bug-coverage.t
MISC/bug-coverage-6.d.t
MISC/bug-coverage-stress.t # stress
Expand Down

0 comments on commit 49363d6

Please sign in to comment.