You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Ayhan Ulusoy <ay...@drexel.edu> on 2003/09/28 19:54:12 UTC

RE : [mp2] PERLIO_K_RAW in apr_perlio.c

I am worried about this.

Does 'PERLIO_K_RAW' also make the following call "do nothing" ? :

	binmode($apr_f, 'utf8');


Cheers,
Ayhan




-----Message d'origine-----
De : Randy Kobes [mailto:randy@theoryx5.uwinnipeg.ca] 
Envoyé : dimanche 28 septembre 2003 04:45
À : dev@perl.apache.org
Objet : [mp2] PERLIO_K_RAW in apr_perlio.c

This is following up on a change made in
   xs/APR/PerlIO/apr_perlio.c
concerning the addition of PERLIO_K_RAW:
http://marc.theaimsgroup.com/?l=apache-modperl-cvs&m=106264631819673&w=2
At the time there wasn't a test that showed this change was
needed (there are tests that show PERLIO_K_RAW is needed for
src/modules/perl/modperl_io_apache.c). Some tests that do
show this appear below, but they're subtle.

If I understand things correctly, the apr layer opens files
in binary mode (on, eg, Win32, where it makes a difference).
What this means for the Perl glue is that, when
opening a file
   open($fh, ">:APR", ...)
$fh is already in "binmode". For binary files this
is "good", but it also means text files are opened in
binary mode, with \015\012 line endings. For example, in

local $/;
open $apr_fh, "<:APR", $file, $r->pool;
$apr_content = <$fh>;
close $apr_fh;
open $perl_fh, "<", $file;
binmode($perl_fh);
$perl_content = <$fh>;
close $apr_fh;

the lengths of $apr_content and $perl_content are the
same only with the binmode($perl_fh) call, for both
text and binary files.

This test works both with and without the addition of
PERLIO_K_RAW to xs/APR/PerlIO/apr_perlio.c. Where a
difference arises is if one does an explicit
binmode($apr_fh) - if done, then the PERLIO_K_RAW is needed,
as otherwise the filehandle, for example, outputs nothing.
So, what the addition of PERLIO_K_RAW apparently does is
make a Perl binmode($apr_fh) call redundant - it doesn't do
anything, but it doesn't hurt.

I also added in a few tests regarding writing and reading
text files, and testing that things work as expected as far
as \015\012 issues are involved. But as far as testing
whether or not PERLIO_K_RAW is needed, the critical
point in the tests is the presence of binmode($apr_fh).

================================================================
Index: t/response/TestAPR/perlio.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v
retrieving revision 1.25
diff -u -r1.25 perlio.pm
--- t/response/TestAPR/perlio.pm	19 Sep 2003 19:54:37 -0000
1.25
+++ t/response/TestAPR/perlio.pm	28 Sep 2003 02:01:55 -0000
@@ -28,7 +28,7 @@
 sub handler {
     my $r = shift;

-    my $tests = 11;
+    my $tests = 21;
     $tests += 3 unless LARGE_FILES_CONFLICT;
     $tests += 1 unless APR_WIN32_FILE_DUP_BUG;

@@ -221,6 +221,80 @@

     }

+    # test reading and writing text and binary files
+    {
+        my $data_dir = 'docs/user/handlers';
+        local $/;
+        my ($rfh, $wfh, $pfh);
+        for my $file ('general.pod', 'filter_logic.png') {
+            my $in = catfile $vars->{top_dir}, $data_dir, $file;
+            my $out = catfile $dir, $file;
+            open $rfh, "<:APR", $in, $r->pool
+                or die "Cannot open $in for reading: $!";
+            my $apr_content = <$rfh>;
+            close $rfh;
+            open $pfh, "<", $in
+                or die "Cannot open $in for reading: $!";
+            binmode($pfh);
+            my $perl_content = <$pfh>;
+            close $pfh;
+            ok t_cmp(length $perl_content,
+                     length $apr_content,
+                     "testing data size of $file");
+
+            open $wfh, ">:APR", $out, $r->pool
+                or die "Cannot open $out for writing: $!";
+            binmode($wfh);
+            print $wfh $apr_content;
+            close $wfh;
+            ok t_cmp(-s $in,
+                     -s $out,
+                     "testing file size of $file");
+        }
+
+        my $crlf = catfile $dir, "crlf$$.dat";
+        my $text;
+        open $wfh, ">:crlf", $crlf
+            or die "Cannot open $crlf for writing: $!";
+        print $wfh 'a'.((('a' x 14).qq{\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $crlf, $r->pool
+            or die "Cannot open $crlf for reading: $!";
+        binmode($rfh);
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        open $wfh, ">:APR", $crlf, $r->pool
+            or die "Cannot open $crlf for writing: $!";
+        print $wfh 'a'.((('a' x 14).qq{\r\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $crlf, $r->pool
+            or die "Cannot open $crlf for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+        open $rfh, "<:crlf", $crlf
+            or die "Cannot open $crlf for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(0,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+    }

     # XXX: need tests
     # - for stdin/out/err as they are handled specially
@@ -232,6 +306,13 @@
     # cleanup: t_mkdir will remove the whole tree including the file

     Apache::OK;
+}
+
+sub count_chars {
+    my($text, $chars) = @_;
+    my $seen = 0;
+    $seen++ while $text =~ /$chars/g;
+    return $seen;
 }

 1;

==============================================================

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 1 Oct 2003, Stas Bekman wrote:

> Randy Kobes wrote:
> > On Wed, 1 Oct 2003, Geoffrey Young wrote:
> >
> >>or, I could just commit it now and Randy can decide which
> >>route to go.  I think I'll just do that...
> >
> > Here's a revised set of tests, using Geoff's implementation
> > of Apache::CRLF. This also addresses a couple of earlier
> > comments of Stas - the files used for comparison are now
> > assumed to be found as t/htdocs/perlio/http.pod and
> > t/htdocs/perlio/http_cycle.png, and also a constant
> > data file name is used (and then cleaned up after the
> > tests are done).
>
> tested OK on linux, +1 to commit with my other comments if
> possible, or commit it as is and we will polish it later.

Thanks very much Stas, and also for the earlier comments on
where to declare things, etc. - much appreciated! I'll
polish this up over the weekend and commit.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 1 Oct 2003, Geoffrey Young wrote:
> 
> 
>>or, I could just commit it now and Randy can decide which
>>route to go.  I think I'll just do that...
> 
> 
> Here's a revised set of tests, using Geoff's implementation
> of Apache::CRLF. This also addresses a couple of earlier
> comments of Stas - the files used for comparison are now
> assumed to be found as t/htdocs/perlio/http.pod and
> t/htdocs/perlio/http_cycle.png, and also a constant
> data file name is used (and then cleaned up after the
> tests are done).

tested OK on linux, +1 to commit with my other comments if possible, or commit 
it as is and we will polish it later.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 1 Oct 2003, Stas Bekman wrote:

> Randy Kobes wrote:
[ .. ]
> Cool. The following are just style comments.
>
> > +    # test reading and writing text and binary files
> > +    {
> > +        local $/;
>
> Randy, can you please put local $/; just before it's
> needed? Otherwise it's too far away from its usage and it
> may affect other things if the test is expanded in the
> future. The best practice IMHO is:
>
>             {
>                local $/;
>                ... <$fh>
>             }
>
> in every place you need it. this makes the code easier to read.

Good idea - I'll do that ...

>
> > +        my ($rfh, $wfh, $pfh);
>
> why these are defined outside and not where they are opened?
>
>     open my $rfh, "<:APR", $in, $r->pool
>
> etc.

Done ...

>
> > +        for my $file ('http.pod', 'http_cycle.png') {
> > +            my $in = catfile $dir, $file;
> > +            my $out = catfile $dir, "$file.out";
> > +            open $rfh, "<:APR", $in, $r->pool
> > +                or die "Cannot open $in for reading: $!";
> > +            binmode($rfh);  # not necessary
>
> if it's not necessary, why do we need it?

I'll drop the comment - it is too cryptic. But basically,
putting in a binmode($apr_fh) doesn't affect anything - you
can put it in, or leave it out, both for binary and text
files (even on Win32). Where having it in makes a difference
(but this doesn't matter to a user) is if PERLIO_K_RAW
was left out of apr_perlio.c. If it was, then all the
tests would pass without the binmode($apr_fh) calls, but
some will fail with a binmode($apr_fh).

[ .. ]
> I'd enclose the following code of its own block showing
> that it's an independent sub-test. you won't need to
> predeclare lexicals vars above. This practice makes easier
> to debug subtests where you can comment out blocks without
> affecting the rest of the test. see apr/pool.pm for such
> an example.
>
> > +        my $scratch = catfile $dir, 'scratch.dat';
[ .. ]
I'll do that.

Thanks again, Stas.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Wed, 1 Oct 2003, Geoffrey Young wrote:
> 
> 
>>or, I could just commit it now and Randy can decide which
>>route to go.  I think I'll just do that...
> 
> 
> Here's a revised set of tests, using Geoff's implementation
> of Apache::CRLF. This also addresses a couple of earlier
> comments of Stas - the files used for comparison are now
> assumed to be found as t/htdocs/perlio/http.pod and
> t/htdocs/perlio/http_cycle.png, and also a constant
> data file name is used (and then cleaned up after the
> tests are done).

Cool. The following are just style comments.

> +    # test reading and writing text and binary files
> +    {
> +        local $/;

Randy, can you please put local $/; just before it's needed? Otherwise it's 
too far away from its usage and it may affect other things if the test is 
expanded in the future. The best practice IMHO is:

            {
               local $/;
               ... <$fh>
            }

in every place you need it. this makes the code easier to read.

> +        my ($rfh, $wfh, $pfh);

why these are defined outside and not where they are opened?

    open my $rfh, "<:APR", $in, $r->pool

etc.

> +        for my $file ('http.pod', 'http_cycle.png') {
> +            my $in = catfile $dir, $file;
> +            my $out = catfile $dir, "$file.out";
> +            open $rfh, "<:APR", $in, $r->pool
> +                or die "Cannot open $in for reading: $!";
> +            binmode($rfh);  # not necessary

if it's not necessary, why do we need it?

> +            my $apr_content = <$rfh>;
> +            close $rfh;
> +            open $pfh, "<", $in
> +                or die "Cannot open $in for reading: $!";
> +            binmode($pfh);
> +            my $perl_content = <$pfh>;
> +            close $pfh;
> +            ok t_cmp(length $perl_content,
> +                     length $apr_content,
> +                     "testing data size of $file");
> +
> +            open $wfh, ">:APR", $out, $r->pool
> +                or die "Cannot open $out for writing: $!";
> +            print $wfh $apr_content;
> +            close $wfh;
> +            ok t_cmp(-s $in,
> +                     -s $out,
> +                     "testing file size of $file");
> +            unlink $out;
> +        }

I'd enclose the following code of its own block showing that it's an 
independent sub-test. you won't need to predeclare lexicals vars above. This 
practice makes easier to debug subtests where you can comment out blocks 
without affecting the rest of the test. see apr/pool.pm for such an example.

> +        my $scratch = catfile $dir, 'scratch.dat';
> +        my $text;
> +        my $count = 2000;
> +        open $wfh, ">:crlf", $scratch
> +            or die "Cannot open $scratch for writing: $!";
> +        print $wfh 'a' . ((('a' x 14) . "\n") x $count);
> +        close $wfh;
> +        open $rfh, "<:APR", $scratch, $r->pool
> +            or die "Cannot open $scratch for reading: $!";
> +        $text = <$rfh>;
> +        close $rfh;
> +        ok t_cmp($count,
> +                 count_chars($text, Apache::CRLF),
> +                 'testing for presence of \015\012');
> +        ok t_cmp($count,
> +                 count_chars($text, "\n"),
> +                 'testing for presence of \n');
> +
> +        open $wfh, ">:APR", $scratch, $r->pool
> +            or die "Cannot open $scratch for writing: $!";
> +        binmode($wfh);  # not necessary
> +        print $wfh 'a' . ((('a' x 14) . Apache::CRLF) x $count);
> +        close $wfh;
> +        open $rfh, "<:APR", $scratch, $r->pool
> +            or die "Cannot open $scratch for reading: $!";
> +        $text = <$rfh>;
> +        close $rfh;
> +        ok t_cmp($count,
> +                 count_chars($text, Apache::CRLF),
> +                 'testing for presence of \015\012');
> +        ok t_cmp($count,
> +                 count_chars($text, "\n"),
> +                 'testing for presence of \n');
> +        open $rfh, "<:crlf", $scratch
> +            or die "Cannot open $scratch for reading: $!";
> +        $text = <$rfh>;
> +        close $rfh;
> +        ok t_cmp(0,
> +                 count_chars($text, Apache::CRLF),
> +                 'testing for presence of \015\012');
> +        ok t_cmp($count,
> +                 count_chars($text, "\n"),
> +                 'testing for presence of \n');
> +
> +        my $utf8 = "\x{042F} \x{0432}\x{0430}\x{0441} \x{043B}\x{044E}";
> +        open $wfh, ">:APR", $scratch, $r->pool
> +            or die "Cannot open $scratch for writing: $!";
> +        binmode($wfh, ':utf8');
> +        print $wfh $utf8;
> +        close $wfh;
> +        open $rfh, "<:APR", $scratch, $r->pool
> +            or die "Cannot open $scratch for reading: $!";
> +        binmode($rfh, ':utf8');
> +        $text = <$rfh>;
> +        close $rfh;
> +        ok t_cmp($utf8,
> +                 $text,
> +                 'utf8 binmode test');
> +        unlink $scratch;
> +    }
> 
>      # XXX: need tests
>      # - for stdin/out/err as they are handled specially
> @@ -232,6 +323,13 @@
>      # cleanup: t_mkdir will remove the whole tree including the file
> 
>      Apache::OK;
> +}
> +
> +sub count_chars {
> +    my($text, $chars) = @_;
> +    my $seen = 0;
> +    $seen++ while $text =~ /$chars/g;
> +    return $seen;
>  }
> 
>  1;
> 
> ===============================================================
> 


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 1 Oct 2003, Stas Bekman wrote:

> Randy Kobes wrote:
> > On Thu, 2 Oct 2003, Randy Kobes wrote:
> >
> >
> >>Here's a revised set of tests, using Geoff's implementation
> >>of Apache::CRLF. This also addresses a couple of earlier
> >>comments of Stas - the files used for comparison are now
> >>assumed to be found as t/htdocs/perlio/http.pod and
> >>t/htdocs/perlio/http_cycle.png.
> >
> > [ ... ]
> > Sorry - I forgot - httpd.pod and http_cycle.png are in
> > the mp2 cvs sources under docs/user/handlers/. If these
> > files are OK to use, I'll add them to t/htdocs/perlio/
> > in cvs. This will mean adding perlio/ to cvs, if that's
> > an issue?
>
> adding t/htdocs/perlio to cvs is fine.
>
> adding http.pod and http_cycle.png is not such a good
> idea. The problem is that someone will try to read/use
> them for other reasons and chances are that both will be
> very out of date 6 months from now. Therefore if you can
> use a file with your favorite poetry or prose for .pod
> (call it .txt then) and small png of a flower that would
> be much much better. Also it'd be nice to add not too big
> files, as the source distribution is already quite big and
> growing. Of course this is different if a big input is
> needed for the test. You can use
> http://www.google.ca/imghp to find images if you don't
> have your own ;)

Hi Stas,
   That's a good idea - thanks, I'll do that ... I don't
think large files add anything to the tests, so I'll go
with the small ones.

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Thu, 2 Oct 2003, Randy Kobes wrote:
> 
> 
>>Here's a revised set of tests, using Geoff's implementation
>>of Apache::CRLF. This also addresses a couple of earlier
>>comments of Stas - the files used for comparison are now
>>assumed to be found as t/htdocs/perlio/http.pod and
>>t/htdocs/perlio/http_cycle.png.
> 
> [ ... ]
> Sorry - I forgot - httpd.pod and http_cycle.png are in
> the mp2 cvs sources under docs/user/handlers/. If these
> files are OK to use, I'll add them to t/htdocs/perlio/
> in cvs. This will mean adding perlio/ to cvs, if that's
> an issue?

adding t/htdocs/perlio to cvs is fine.

adding http.pod and http_cycle.png is not such a good idea. The problem is 
that someone will try to read/use them for other reasons and chances are that 
both will be very out of date 6 months from now. Therefore if you can use a 
file with your favorite poetry or prose for .pod (call it .txt then) and small 
png of a flower that would be much much better. Also it'd be nice to add not 
too big files, as the source distribution is already quite big and growing. Of 
course this is different if a big input is needed for the test. You can use 
http://www.google.ca/imghp to find images if you don't have your own ;)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Thu, 2 Oct 2003, Randy Kobes wrote:

> Here's a revised set of tests, using Geoff's implementation
> of Apache::CRLF. This also addresses a couple of earlier
> comments of Stas - the files used for comparison are now
> assumed to be found as t/htdocs/perlio/http.pod and
> t/htdocs/perlio/http_cycle.png.
[ ... ]
Sorry - I forgot - httpd.pod and http_cycle.png are in
the mp2 cvs sources under docs/user/handlers/. If these
files are OK to use, I'll add them to t/htdocs/perlio/
in cvs. This will mean adding perlio/ to cvs, if that's
an issue?

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 1 Oct 2003, Geoffrey Young wrote:

> or, I could just commit it now and Randy can decide which
> route to go.  I think I'll just do that...

Here's a revised set of tests, using Geoff's implementation
of Apache::CRLF. This also addresses a couple of earlier
comments of Stas - the files used for comparison are now
assumed to be found as t/htdocs/perlio/http.pod and
t/htdocs/perlio/http_cycle.png, and also a constant
data file name is used (and then cleaned up after the
tests are done).
========================================================
Index: t/response/TestAPR/perlio.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v
retrieving revision 1.25
diff -u -r1.25 perlio.pm
--- t/response/TestAPR/perlio.pm	19 Sep 2003 19:54:37 -0000	1.25
+++ t/response/TestAPR/perlio.pm	2 Oct 2003 05:17:07 -0000
@@ -13,7 +13,7 @@
 use Fcntl ();
 use File::Spec::Functions qw(catfile);

-use Apache::Const -compile => 'OK';
+use Apache::Const -compile => qw(OK CRLF);

 #XXX: APR::LARGE_FILES_CONFLICT constant?
 #XXX: you can set to zero if largefile support is not enabled in Perl
@@ -28,7 +28,7 @@
 sub handler {
     my $r = shift;

-    my $tests = 11;
+    my $tests = 22;
     $tests += 3 unless LARGE_FILES_CONFLICT;
     $tests += 1 unless APR_WIN32_FILE_DUP_BUG;

@@ -221,6 +221,97 @@

     }

+    # test reading and writing text and binary files
+    {
+        local $/;
+        my ($rfh, $wfh, $pfh);
+        for my $file ('http.pod', 'http_cycle.png') {
+            my $in = catfile $dir, $file;
+            my $out = catfile $dir, "$file.out";
+            open $rfh, "<:APR", $in, $r->pool
+                or die "Cannot open $in for reading: $!";
+            binmode($rfh);  # not necessary
+            my $apr_content = <$rfh>;
+            close $rfh;
+            open $pfh, "<", $in
+                or die "Cannot open $in for reading: $!";
+            binmode($pfh);
+            my $perl_content = <$pfh>;
+            close $pfh;
+            ok t_cmp(length $perl_content,
+                     length $apr_content,
+                     "testing data size of $file");
+
+            open $wfh, ">:APR", $out, $r->pool
+                or die "Cannot open $out for writing: $!";
+            print $wfh $apr_content;
+            close $wfh;
+            ok t_cmp(-s $in,
+                     -s $out,
+                     "testing file size of $file");
+            unlink $out;
+        }
+
+        my $scratch = catfile $dir, 'scratch.dat';
+        my $text;
+        my $count = 2000;
+        open $wfh, ">:crlf", $scratch
+            or die "Cannot open $scratch for writing: $!";
+        print $wfh 'a' . ((('a' x 14) . "\n") x $count);
+        close $wfh;
+        open $rfh, "<:APR", $scratch, $r->pool
+            or die "Cannot open $scratch for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp($count,
+                 count_chars($text, Apache::CRLF),
+                 'testing for presence of \015\012');
+        ok t_cmp($count,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        open $wfh, ">:APR", $scratch, $r->pool
+            or die "Cannot open $scratch for writing: $!";
+        binmode($wfh);  # not necessary
+        print $wfh 'a' . ((('a' x 14) . Apache::CRLF) x $count);
+        close $wfh;
+        open $rfh, "<:APR", $scratch, $r->pool
+            or die "Cannot open $scratch for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp($count,
+                 count_chars($text, Apache::CRLF),
+                 'testing for presence of \015\012');
+        ok t_cmp($count,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+        open $rfh, "<:crlf", $scratch
+            or die "Cannot open $scratch for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(0,
+                 count_chars($text, Apache::CRLF),
+                 'testing for presence of \015\012');
+        ok t_cmp($count,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        my $utf8 = "\x{042F} \x{0432}\x{0430}\x{0441} \x{043B}\x{044E}";
+        open $wfh, ">:APR", $scratch, $r->pool
+            or die "Cannot open $scratch for writing: $!";
+        binmode($wfh, ':utf8');
+        print $wfh $utf8;
+        close $wfh;
+        open $rfh, "<:APR", $scratch, $r->pool
+            or die "Cannot open $scratch for reading: $!";
+        binmode($rfh, ':utf8');
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp($utf8,
+                 $text,
+                 'utf8 binmode test');
+        unlink $scratch;
+    }

     # XXX: need tests
     # - for stdin/out/err as they are handled specially
@@ -232,6 +323,13 @@
     # cleanup: t_mkdir will remove the whole tree including the file

     Apache::OK;
+}
+
+sub count_chars {
+    my($text, $chars) = @_;
+    my $seen = 0;
+    $seen++ while $text =~ /$chars/g;
+    return $seen;
 }

 1;

===============================================================

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 1 Oct 2003, Geoffrey Young wrote:

>
> >
> > +1. also please update modperl-docs/src/docs/2.0/api/Apache/Const.pod.
>
> of course.
>
> >
> > Will you please suggest a patch against Randy's patch to use that constant?
>
> it would probably be easier to patch that after it's accepted into core in
> it's final form.  that way Randy keeps ownership of the bulk of it and can
> tweak it until everyone is satisfied.
>
> or, I could just commit it now and Randy can decide which route to go.  I
> think I'll just do that...
>
> --Geoff

That sounds good - the availability of those constants
will make things easier ...

-- 
best regards,
randy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> 
> +1. also please update modperl-docs/src/docs/2.0/api/Apache/Const.pod.

of course.

> 
> Will you please suggest a patch against Randy's patch to use that constant?

it would probably be easier to patch that after it's accepted into core in 
it's final form.  that way Randy keeps ownership of the bulk of it and can 
tweak it until everyone is satisfied.

or, I could just commit it now and Randy can decide which route to go.  I 
think I'll just do that...

--Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
>> # Define the CRLF sequence.  I can't use a simple "\r\n" because the
>> meaning
>> # of "\n" is different on different OS's (sometimes it generates CRLF,
>> sometimes LF
>> # and sometimes CR).  The most popular VMS web server
>> # doesn't accept CRLF -- instead it wants a LR.  EBCDIC machines don't
>> # use ASCII, so \015\012 means something different.  I find this all # 
>> really annoying.
> 
> 
> randy and I have discussed this before, IIRC...
> 
> while apache itself makes the distinction between ascii and ebcdic, it 
> does not distinguish between vms and the rest of ascii land.
> 
> I say we punt just follow the lead of httpd, exporting their constants.
> 
> patch attached.  I'll clean up the test tomorrow if people like the idea.

+1. also please update modperl-docs/src/docs/2.0/api/Apache/Const.pod.

Will you please suggest a patch against Randy's patch to use that constant?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


RE : RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Ayhan Ulusoy <ay...@drexel.edu>.
Yupp. It is probably better to stick close to the way httpd does things.

Besides, that VMS behaviour must be a real buggy one if it is the way
that snippet suggests  :)

Cheers,

Ayhan


-----Message d'origine-----
De : Geoffrey Young [mailto:geoff@modperlcookbook.org] 
Envoyé : mercredi 1 octobre 2003 00:59
À : Ayhan Ulusoy
Cc : dev@perl.apache.org
Objet : Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c


> # Define the CRLF sequence.  I can't use a simple "\r\n" because the
> meaning
> # of "\n" is different on different OS's (sometimes it generates CRLF,
> sometimes LF
> # and sometimes CR).  The most popular VMS web server
> # doesn't accept CRLF -- instead it wants a LR.  EBCDIC machines don't
> # use ASCII, so \015\012 means something different.  I find this all 
> # really annoying.

randy and I have discussed this before, IIRC...

while apache itself makes the distinction between ascii and ebcdic, it
does 
not distinguish between vms and the rest of ascii land.

I say we punt just follow the lead of httpd, exporting their constants.

patch attached.  I'll clean up the test tomorrow if people like the
idea.
--Geoff



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> # Define the CRLF sequence.  I can't use a simple "\r\n" because the
> meaning
> # of "\n" is different on different OS's (sometimes it generates CRLF,
> sometimes LF
> # and sometimes CR).  The most popular VMS web server
> # doesn't accept CRLF -- instead it wants a LR.  EBCDIC machines don't
> # use ASCII, so \015\012 means something different.  I find this all 
> # really annoying.

randy and I have discussed this before, IIRC...

while apache itself makes the distinction between ascii and ebcdic, it does 
not distinguish between vms and the rest of ascii land.

I say we punt just follow the lead of httpd, exporting their constants.

patch attached.  I'll clean up the test tomorrow if people like the idea.
--Geoff

RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Ayhan Ulusoy <ay...@drexel.edu>.
It is normal that the "\015\012" stuff works on linux, precisely because
of what the ":crlf" filter does. 

But the way the test is written, it is bound to fail on EBCDIC machines
(if that matters at all for mod_perl), because CR LF doesn't spell out
that way in EBCDIC.

When the perl code writes out a single "\n" (LF) on a handle that has
"crlf" translation on, it becomes CR LF which spells out as "\015\012"
in ASCII.

Reading the same data back from a handle that does not have that
translation (the apr handle in this case), we read back the two
characters.

But when there is a translation on the handle that is being read
(further down in the test code), we don't see the CR, but just the LF.


For the test to work in EBCDIC machines as well, take a look at the hack
at the top of CGI.pm. Here is the snippet :



# Define the CRLF sequence.  I can't use a simple "\r\n" because the
meaning
# of "\n" is different on different OS's (sometimes it generates CRLF,
sometimes LF
# and sometimes CR).  The most popular VMS web server
# doesn't accept CRLF -- instead it wants a LR.  EBCDIC machines don't
# use ASCII, so \015\012 means something different.  I find this all 
# really annoying.
$EBCDIC = "\t" ne "\011";
if ($OS eq 'VMS') {
  $CRLF = "\n";
} elsif ($EBCDIC) {
  $CRLF= "\r\n";
} else {
  $CRLF = "\015\012";
}









-----Message d'origine-----
De : Stas Bekman [mailto:stas@stason.org] 
Envoyé : mardi 30 septembre 2003 21:20
À : Randy Kobes
Cc : Ayhan Ulusoy; dev@perl.apache.org
Objet : Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Randy Kobes wrote:
> On Sun, 28 Sep 2003, Ayhan Ulusoy wrote:
> 
> 
>>I am worried about this.
>>Does 'PERLIO_K_RAW' also make the following call "do nothing" ? :
>>	binmode($apr_f, 'utf8');
> 
> 
> That's a good point ... The binmode($apr_f) call (without a
> layer) seems to "do nothing", in the sense of not being
> needed as far as apr goes, but PERLIO_K_RAW is necessary in
> order to be able to put in a binmode($apr_f). However, with
> utf8 data the binmode($apr_f, ':utf8') call is necessary on
> the perl side. I added a test for this below - without the
> binmode($apr_f, ':utf8') calls, the utf8 test fails for me,
> but with these calls, they pass.

Great job, Randy! The test passes on linux.

I have a few comments

 > +        my $data_dir = 'docs/user/handlers';
 > +        local $/;
 > +        my ($rfh, $wfh, $pfh);
 > +        for my $file ('general.pod', 'filter_logic.png') {
 > +            my $in = catfile $vars->{top_dir}, $data_dir, $file;

We can't rely on having docs/ dir, since it's not a part of the
modperl-2.0 
repository, it's just a magical checkout. Besides any of the above two
files 
could be renamed in the future, so relying on these is not a good idea. 
Instead please create dedicated files under t/htdocs/perlio.

 > +        my $dat = catfile $dir, "dat$$.dat";

why do we need $$? we will need to cleanup after ourselves, so having a 
constant filename will help. The cleanup process is now sort of
semi-working. 
Hopefully will fix it at some point.

 > +        open $wfh, ">:crlf", $dat

 From 5.8.1's perldelta.pod:

   The "CR CR LF" problem of has been fixed, binmode(FH, ":crlf")
   is now effectively a no-op.

You need to tell me, what is it about ;) but should we we run that only
if 
perl < 5.8.1. at the very list would be nice to put a comment that it's
a noop 
on 5.8.1+ as a reminder.

 > +        ok t_cmp(2000,
 > +                 count_chars($text, "\015\012"),
 > +                 'testing for presence of \015\012');

I wonder how this works on linux then. After all you did write "\n", not

"\r\n". Also why do you use "\015\012" and "\n"? and not "\r\n"/"\n" or 
"\015\012"/"\012" everywhere? just to make different tests?

Finally what happens on Mac where we have only "\r" (\015)?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Sun, 28 Sep 2003, Ayhan Ulusoy wrote:
> 
> 
>>I am worried about this.
>>Does 'PERLIO_K_RAW' also make the following call "do nothing" ? :
>>	binmode($apr_f, 'utf8');
> 
> 
> That's a good point ... The binmode($apr_f) call (without a
> layer) seems to "do nothing", in the sense of not being
> needed as far as apr goes, but PERLIO_K_RAW is necessary in
> order to be able to put in a binmode($apr_f). However, with
> utf8 data the binmode($apr_f, ':utf8') call is necessary on
> the perl side. I added a test for this below - without the
> binmode($apr_f, ':utf8') calls, the utf8 test fails for me,
> but with these calls, they pass.

Great job, Randy! The test passes on linux.

I have a few comments

 > +        my $data_dir = 'docs/user/handlers';
 > +        local $/;
 > +        my ($rfh, $wfh, $pfh);
 > +        for my $file ('general.pod', 'filter_logic.png') {
 > +            my $in = catfile $vars->{top_dir}, $data_dir, $file;

We can't rely on having docs/ dir, since it's not a part of the modperl-2.0 
repository, it's just a magical checkout. Besides any of the above two files 
could be renamed in the future, so relying on these is not a good idea. 
Instead please create dedicated files under t/htdocs/perlio.

 > +        my $dat = catfile $dir, "dat$$.dat";

why do we need $$? we will need to cleanup after ourselves, so having a 
constant filename will help. The cleanup process is now sort of semi-working. 
Hopefully will fix it at some point.

 > +        open $wfh, ">:crlf", $dat

 From 5.8.1's perldelta.pod:

   The "CR CR LF" problem of has been fixed, binmode(FH, ":crlf")
   is now effectively a no-op.

You need to tell me, what is it about ;) but should we we run that only if 
perl < 5.8.1. at the very list would be nice to put a comment that it's a noop 
on 5.8.1+ as a reminder.

 > +        ok t_cmp(2000,
 > +                 count_chars($text, "\015\012"),
 > +                 'testing for presence of \015\012');

I wonder how this works on linux then. After all you did write "\n", not 
"\r\n". Also why do you use "\015\012" and "\n"? and not "\r\n"/"\n" or 
"\015\012"/"\012" everywhere? just to make different tests?

Finally what happens on Mac where we have only "\r" (\015)?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


RE : RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Ayhan Ulusoy <ay...@drexel.edu>.
Sounds gooood. 

Thanks Randy.



-----Message d'origine-----
De : Randy Kobes [mailto:randy@theoryx5.uwinnipeg.ca] 
Envoyé : lundi 29 septembre 2003 02:12
À : Ayhan Ulusoy
Cc : dev@perl.apache.org
Objet : Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

On Sun, 28 Sep 2003, Ayhan Ulusoy wrote:

> I am worried about this.
> Does 'PERLIO_K_RAW' also make the following call "do nothing" ? :
> 	binmode($apr_f, 'utf8');

That's a good point ... The binmode($apr_f) call (without a
layer) seems to "do nothing", in the sense of not being
needed as far as apr goes, but PERLIO_K_RAW is necessary in
order to be able to put in a binmode($apr_f). However, with
utf8 data the binmode($apr_f, ':utf8') call is necessary on
the perl side. I added a test for this below - without the
binmode($apr_f, ':utf8') calls, the utf8 test fails for me,
but with these calls, they pass.

============================================================
Index: t/response/TestAPR/perlio.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v
retrieving revision 1.25
diff -u -r1.25 perlio.pm
--- t/response/TestAPR/perlio.pm	19 Sep 2003 19:54:37 -0000
1.25
+++ t/response/TestAPR/perlio.pm	28 Sep 2003 23:49:37 -0000
@@ -28,7 +28,7 @@
 sub handler {
     my $r = shift;

-    my $tests = 11;
+    my $tests = 22;
     $tests += 3 unless LARGE_FILES_CONFLICT;
     $tests += 1 unless APR_WIN32_FILE_DUP_BUG;

@@ -221,6 +221,96 @@

     }

+    # test reading and writing text and binary files
+    {
+        my $data_dir = 'docs/user/handlers';
+        local $/;
+        my ($rfh, $wfh, $pfh);
+        for my $file ('general.pod', 'filter_logic.png') {
+            my $in = catfile $vars->{top_dir}, $data_dir, $file;
+            my $out = catfile $dir, $file;
+            open $rfh, "<:APR", $in, $r->pool
+                or die "Cannot open $in for reading: $!";
+            binmode($rfh);  # not necessary
+            my $apr_content = <$rfh>;
+            close $rfh;
+            open $pfh, "<", $in
+                or die "Cannot open $in for reading: $!";
+            binmode($pfh);
+            my $perl_content = <$pfh>;
+            close $pfh;
+            ok t_cmp(length $perl_content,
+                     length $apr_content,
+                     "testing data size of $file");
+
+            open $wfh, ">:APR", $out, $r->pool
+                or die "Cannot open $out for writing: $!";
+            print $wfh $apr_content;
+            close $wfh;
+            ok t_cmp(-s $in,
+                     -s $out,
+                     "testing file size of $file");
+        }
+
+        my $dat = catfile $dir, "dat$$.dat";
+        my $text;
+        open $wfh, ">:crlf", $dat
+            or die "Cannot open $dat for writing: $!";
+        print $wfh 'a'.((('a' x 14).qq{\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        open $wfh, ">:APR", $dat, $r->pool
+            or die "Cannot open $dat for writing: $!";
+        binmode($wfh);  # not necessary
+        print $wfh 'a'.((('a' x 14).qq{\r\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+        open $rfh, "<:crlf", $dat
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(0,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        my $utf8 = "\x{042F} \x{0432}\x{0430}\x{0441}
\x{043B}\x{044E}";
+        open $wfh, ">:APR", $dat, $r->pool
+            or die "Cannot open $dat for writing: $!";
+        binmode($wfh, ':utf8');
+        print $wfh $utf8;
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        binmode($rfh, ':utf8');
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp($utf8,
+                 $text,
+                 'utf8 binmode test');
+
+    }

     # XXX: need tests
     # - for stdin/out/err as they are handled specially
@@ -232,6 +322,13 @@
     # cleanup: t_mkdir will remove the whole tree including the file

     Apache::OK;
+}
+
+sub count_chars {
+    my($text, $chars) = @_;
+    my $seen = 0;
+    $seen++ while $text =~ /$chars/g;
+    return $seen;
 }

 1;

===============================================================
-- 
best regards,
randy



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: RE : [mp2] PERLIO_K_RAW in apr_perlio.c

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Sun, 28 Sep 2003, Ayhan Ulusoy wrote:

> I am worried about this.
> Does 'PERLIO_K_RAW' also make the following call "do nothing" ? :
> 	binmode($apr_f, 'utf8');

That's a good point ... The binmode($apr_f) call (without a
layer) seems to "do nothing", in the sense of not being
needed as far as apr goes, but PERLIO_K_RAW is necessary in
order to be able to put in a binmode($apr_f). However, with
utf8 data the binmode($apr_f, ':utf8') call is necessary on
the perl side. I added a test for this below - without the
binmode($apr_f, ':utf8') calls, the utf8 test fails for me,
but with these calls, they pass.

============================================================
Index: t/response/TestAPR/perlio.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v
retrieving revision 1.25
diff -u -r1.25 perlio.pm
--- t/response/TestAPR/perlio.pm	19 Sep 2003 19:54:37 -0000	1.25
+++ t/response/TestAPR/perlio.pm	28 Sep 2003 23:49:37 -0000
@@ -28,7 +28,7 @@
 sub handler {
     my $r = shift;

-    my $tests = 11;
+    my $tests = 22;
     $tests += 3 unless LARGE_FILES_CONFLICT;
     $tests += 1 unless APR_WIN32_FILE_DUP_BUG;

@@ -221,6 +221,96 @@

     }

+    # test reading and writing text and binary files
+    {
+        my $data_dir = 'docs/user/handlers';
+        local $/;
+        my ($rfh, $wfh, $pfh);
+        for my $file ('general.pod', 'filter_logic.png') {
+            my $in = catfile $vars->{top_dir}, $data_dir, $file;
+            my $out = catfile $dir, $file;
+            open $rfh, "<:APR", $in, $r->pool
+                or die "Cannot open $in for reading: $!";
+            binmode($rfh);  # not necessary
+            my $apr_content = <$rfh>;
+            close $rfh;
+            open $pfh, "<", $in
+                or die "Cannot open $in for reading: $!";
+            binmode($pfh);
+            my $perl_content = <$pfh>;
+            close $pfh;
+            ok t_cmp(length $perl_content,
+                     length $apr_content,
+                     "testing data size of $file");
+
+            open $wfh, ">:APR", $out, $r->pool
+                or die "Cannot open $out for writing: $!";
+            print $wfh $apr_content;
+            close $wfh;
+            ok t_cmp(-s $in,
+                     -s $out,
+                     "testing file size of $file");
+        }
+
+        my $dat = catfile $dir, "dat$$.dat";
+        my $text;
+        open $wfh, ">:crlf", $dat
+            or die "Cannot open $dat for writing: $!";
+        print $wfh 'a'.((('a' x 14).qq{\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        open $wfh, ">:APR", $dat, $r->pool
+            or die "Cannot open $dat for writing: $!";
+        binmode($wfh);  # not necessary
+        print $wfh 'a'.((('a' x 14).qq{\r\n}) x 2000);
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(2000,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+        open $rfh, "<:crlf", $dat
+            or die "Cannot open $dat for reading: $!";
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp(0,
+                 count_chars($text, "\015\012"),
+                 'testing for presence of \015\012');
+        ok t_cmp(2000,
+                 count_chars($text, "\n"),
+                 'testing for presence of \n');
+
+        my $utf8 = "\x{042F} \x{0432}\x{0430}\x{0441} \x{043B}\x{044E}";
+        open $wfh, ">:APR", $dat, $r->pool
+            or die "Cannot open $dat for writing: $!";
+        binmode($wfh, ':utf8');
+        print $wfh $utf8;
+        close $wfh;
+        open $rfh, "<:APR", $dat, $r->pool
+            or die "Cannot open $dat for reading: $!";
+        binmode($rfh, ':utf8');
+        $text = <$rfh>;
+        close $rfh;
+        ok t_cmp($utf8,
+                 $text,
+                 'utf8 binmode test');
+
+    }

     # XXX: need tests
     # - for stdin/out/err as they are handled specially
@@ -232,6 +322,13 @@
     # cleanup: t_mkdir will remove the whole tree including the file

     Apache::OK;
+}
+
+sub count_chars {
+    my($text, $chars) = @_;
+    my $seen = 0;
+    $seen++ while $text =~ /$chars/g;
+    return $seen;
 }

 1;

===============================================================
-- 
best regards,
randy


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org