FAQ
It looks like I forgot to send this old patch of mine:

my_popen() "prepares" filehandles directly, and not via PerlIO
layer; its logic was not following the semantic of PerlIO text
stream (that CRLF conversion is done by perl, and not by CRTL).

Test suite included.

Enjoy,
Ilya

diff -pru perl-5.8.7-min-patched/util.c perl-5.8.7-patched/util.c
--- perl-5.8.7-min-patched/util.c Mon May 30 05:44:14 2005
+++ perl-5.8.7-patched/util.c Mon Nov 27 20:59:12 2006
@@ -2161,6 +2166,14 @@ Perl_my_popen(pTHX_ char *cmd, char *mod
PerlProc__exit(1);
}
#endif /* defined OS2 */
+
+#ifdef PERLIO_USING_CRLF
+ /* Since we circumvent IO layers when we manipulate low-level
+ filedescriptors directly, need to manually switch to the
+ default, binary, low-level mode; see PerlIOBuf_open(). */
+ PerlLIO_setmode((*mode == 'r'), O_BINARY);
+#endif
+
if ((tmpgv = gv_fetchpv("$",TRUE, SVt_PV))) {
SvREADONLY_off(GvSV(tmpgv));
sv_setiv(GvSV(tmpgv), PerlProc_getpid());
diff -pru perl-5.8.7-min-patched/t/io/pipe.t perl-5.8.7-patched/t/io/pipe.t
--- perl-5.8.7-min-patched/t/io/pipe.t Sat Dec 8 08:25:18 2001
+++ perl-5.8.7-patched/t/io/pipe.t Mon Nov 27 20:59:12 2006
@@ -10,7 +10,7 @@ BEGIN {
skip_all("fork required to pipe");
}
else {
- plan(tests => 22);
+ plan(tests => 24);
}
}

@@ -30,7 +30,7 @@ close PIPE;
SKIP: {
# Technically this should be TODO. Someone try it if you happen to
# have a vmesa machine.
- skip "Doesn't work here yet", 4 if $^O eq 'vmesa';
+ skip "Doesn't work here yet", 6 if $^O eq 'vmesa';

if (open(PIPE, "-|")) {
while(<PIPE>) {
@@ -49,6 +49,49 @@ SKIP: {

# This has to be *outside* the fork
next_test() for 1..2;
+
+ my $raw = "abc\nrst\rxyz\r\nfoo\n";
+ if (open(PIPE, "-|")) {
+ $_ = join '', <PIPE>;
+ (my $raw1 = $_) =~ s/not ok \d+ - //;
+ my @r = map ord, split //, $raw;
+ my @r1 = map ord, split //, $raw1;
+ if ($raw1 eq $raw) {
+ s/^not (ok \d+ -) .*/$1 '@r1' passes through '-|'\n/s;
+ } else {
+ s/^(not ok \d+ -) .*/$1 expect '@r', got '@r1'\n/s;
+ }
+ print;
+ close PIPE; # avoid zombies
+ }
+ else {
+ printf STDOUT "not ok %d - $raw", curr_test();
+ exec $Perl, '-e0'; # Do not run END()...
+ }
+
+ # This has to be *outside* the fork
+ next_test();
+
+ if (open(PIPE, "|-")) {
+ printf PIPE "not ok %d - $raw", curr_test();
+ close PIPE; # avoid zombies
+ }
+ else {
+ $_ = join '', <STDIN>;
+ (my $raw1 = $_) =~ s/not ok \d+ - //;
+ my @r = map ord, split //, $raw;
+ my @r1 = map ord, split //, $raw1;
+ if ($raw1 eq $raw) {
+ s/^not (ok \d+ -) .*/$1 '@r1' passes through '|-'\n/s;
+ } else {
+ s/^(not ok \d+ -) .*/$1 expect '@r', got '@r1'\n/s;
+ }
+ print;
+ exec $Perl, '-e0'; # Do not run END()...
+ }
+
+ # This has to be *outside* the fork
+ next_test();

SKIP: {
skip "fork required", 2 unless $Config{d_fork};

Search Discussions

  • Steve Peters at Dec 13, 2006 at 8:02 pm

    On Tue, Dec 12, 2006 at 11:28:25PM -0800, Ilya Zakharevich wrote:
    It looks like I forgot to send this old patch of mine:

    my_popen() "prepares" filehandles directly, and not via PerlIO
    layer; its logic was not following the semantic of PerlIO text
    stream (that CRLF conversion is done by perl, and not by CRTL).

    Test suite included.
    Thanks! I've applied this patch to blead as change #29550.

    Steve Peters
    steve@fisharerojo.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedDec 13, '06 at 7:28a
activeDec 13, '06 at 8:02p
posts2
users2
websiteperl.org

2 users in discussion

Steve Peters: 1 post Ilya Zakharevich: 1 post

People

Translate

site design / logo © 2022 Grokbase