Skip to content

Commit

Permalink
STDOUT is already taken in Bytecode, fix PerlIO_fdopen "w"
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Jan 29, 2012
1 parent 3740451 commit 0f0223c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/B/Bytecode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ use ByteLoader '$ByteLoader::VERSION';
my $thatfile = $1;
*B::COP::file = sub { $thatfile };
}
# Use -m instead for modules
elsif (/^-u(.*)/ and $PERL56) {
my $arg ||= $1;
push @packages, $arg;
Expand Down
5 changes: 3 additions & 2 deletions lib/B/C.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,8 @@ sub B::IO::save {
if (!$PERL56 and $fullname ne 'main::DATA') { # PerlIO
# deal with $x = *STDIN/STDOUT/STDERR{IO} and aliases
my $perlio_func;
# Note: all single-direction fp use IFP, just bi-directional pipes and sockets use OFP also.
# Note: all single-direction fp use IFP, just bi-directional pipes and
# sockets use OFP also.
# But we need to set both.
my $o = $io->object_2svref();
my $fd = $o->fileno() if $o->can('fileno');
Expand Down Expand Up @@ -3787,7 +3788,7 @@ sub B::IO::save {
#$init->add( sprintf("IoIFP($sym) = IoOFP($sym) = PerlIO_openn(aTHX_ NULL,%s,%d,0,0,NULL,0,NULL);",
# cstring($mode), $fd));
$init->add(sprintf( "%sIoIFP($sym) = IoOFP($sym) = PerlIO_fdopen(%d, %s);%s",
$fd<3?'':'/*',$fd,$mode,$fd<3?'':'*/'));
$fd<3?'':'/*',$fd,cstring($mode),$fd<3?'':'*/'));
}
elsif ($iotype =~ /[<#\+]/) {
warn "Warning: Read BEGIN-block $fullname from FileHandle $iotype \&$fd\n"
Expand Down
6 changes: 3 additions & 3 deletions t/issue93.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ my ($pid, $out, $in);
BEGIN {
local(*FPID);
$pid = open(FPID, 'echo <<EOF |'); #impossible
open($out, '>&STDOUT'); #easy
open($out, '>&STDERR'); #easy
open(my $tmp, '>', 'pcc.tmp'); #hard to gather filename
print $tmp "test\n";
close $tmp; #ok closed, easy
Expand All @@ -31,10 +31,10 @@ unlink 'pcc.tmp';
EOF

my $ok = <<'EOF';
my $out;open($out,'>&STDOUT');print $out 'ok';
my $out;open($out,'>&STDERR');print $out 'ok';
EOF
my $work = <<'EOF';
my $out;BEGIN{open($out,'>&STDOUT');}print $out 'ok';
my $out;BEGIN{open($out,'>&STDERR');}print $out 'ok';
EOF

sub test3 {
Expand Down
3 changes: 2 additions & 1 deletion t/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ sub plctest {
close F;

my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
my $b = $] > 5.008 ? "-qq,Bytecode" : "Bytecode";
my $nostdoutclobber = $base !~ /^ccode91i/;
my $b = ($] > 5.008 and $nostdoutclobber) ? "-qq,Bytecode" : "Bytecode";
system "$runperl -Iblib/arch -Iblib/lib -MO=$b,-o$name.plc $base.pl";
unless (-e "$name.plc") {
print "not ok $num #B::Bytecode failed\n";
Expand Down
4 changes: 2 additions & 2 deletions t/testc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ my ($pid, $out, $in);
BEGIN {
local(*FPID);
$pid = open(FPID, "echo <<EOF |"); # DIE
open($out, ">&STDOUT"); # EASY
open($out, ">&STDERR"); # EASY
open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
print $tmp "test\n";
close $tmp; # OK closed
Expand All @@ -422,7 +422,7 @@ unlink "pcc.tmp";
result[93]='ok'
tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
result[931]='ok'
tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
tests[932]='my $f;BEGIN{open($f,">&STDERR");}print $f "ok"'
result[932]='ok'

# from here on we test CC specifics only
Expand Down
4 changes: 2 additions & 2 deletions t/testplc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ my ($pid, $out, $in);
BEGIN {
local(*FPID);
$pid = open(FPID, "echo <<EOF |"); # DIE
open($out, ">&STDOUT"); # EASY
open($out, ">&STDERR"); # EASY
open(my $tmp, ">", "pcc.tmp"); # HARD to get filename, WARN
print $tmp "test\n";
close $tmp; # OK closed
Expand All @@ -361,7 +361,7 @@ unlink "pcc.tmp";
result[93]='ok'
tests[931]='my $f;BEGIN{open($f,"<README");}read $f,my $in, 2; print "ok"'
result[931]='ok'
tests[932]='my $f;BEGIN{open($f,">&STDOUT");}print $f "ok"'
tests[932]='my $f;BEGIN{open($f,">&STDERR");}print $f "ok"'
result[932]='ok'

init
Expand Down

0 comments on commit 0f0223c

Please sign in to comment.