Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First attempt at making pipe() work
Alas, this doesn't compile on OS X because of:

  moar(11870,0x7fff7bf29310) malloc: *** error for object 0x7fc8bbfaeae0: pointer being freed was not allocated

during stage parse.
  • Loading branch information
lizmat committed Nov 27, 2014
1 parent 131874f commit 86fb968
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/core/IO.pm
Expand Up @@ -462,3 +462,5 @@ sub MAKE-DIR-LIST(Str $abspath, Mu $test) {
}
}
#?endif

# vim: ft=perl6 expandtab sw=4
10 changes: 9 additions & 1 deletion src/core/IO/Pipe.pm
@@ -1,5 +1,13 @@
class IO::Pipe does IO does PIO {

has Str $.command;

method BUILD (:$command,Mu :$PIO,:$chomp,:$bin,:$encoding,:$nl) {
$!command = $command;
$!PIO := nqp::decont($PIO);
$!chomp = $chomp // True;
self.encoding($bin ?? 'binary' !! $encoding // 'utf8');
self.nl($nl // "\n");
}


}
Expand Down
7 changes: 7 additions & 0 deletions src/core/PIO.pm
@@ -1,6 +1,7 @@
my role PIO {
has $.PIO;
has $.chomp;
has $.nl;
has int $.ins;

method close(PIO:D:) {
Expand Down Expand Up @@ -399,6 +400,12 @@ my role PIO {
multi method encoding(PIO:D: $encoding) {
nqp::setencoding($!PIO, NORMALIZE_ENCODING($encoding));
}

proto method nl(|) { * }
multi method nl() { $!nl }
multi method nl($nl) {
nqp::setinputlinesep($!PIO, nqp::unbox_s($!nl = $nl));
}
}

# vim: ft=perl6 expandtab sw=4
17 changes: 4 additions & 13 deletions src/core/io_operators.pm
Expand Up @@ -138,14 +138,7 @@ multi sub open(
}

proto sub pipe(|) { * }
multi sub pipe(
$path as Str,
:$bin,
:$enc = 'utf8',
:$chomp = True,
:$nl = "\n",
|c
) {
multi sub pipe( $command as Str, :$bin, :$enc, :$encoding, :$chomp, :$nl, |c) {

my Mu $hash-with-containers := nqp::getattr(%*ENV, EnumMap, '$!storage');
my Mu $hash-without := nqp::hash();
Expand All @@ -163,16 +156,14 @@ multi sub pipe(

my str $errpath; # what is this good for?
# TODO: catch error, and fail()
my Mu $PIO := nqp::openpipe(
nqp::unbox_s($path),
my $PIO := nqp::openpipe(
nqp::unbox_s($command),
nqp::unbox_s($*CWD.chop),
$hash-without,
$errpath,
);

nqp::setencoding($PIO,NORMALIZE_ENCODING($enc)) if !$bin && $enc;
nqp::setinputlinesep($PIO,nqp::unbox_s($nl));
IO::Handle.new(:$path,:$PIO,:$chomp,:$nl,|c);
IO::Pipe.new(:$command,:$PIO,:$bin,:$encoding,:$chomp,:$nl,|c);
}

proto sub lines(|) { * }
Expand Down

0 comments on commit 86fb968

Please sign in to comment.