You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stephen Clouse <st...@theiqgroup.com> on 2002/10/01 21:52:08 UTC
[PATCH] mp2: $r->print($scalarref)
This patch allows $r->print($scalarref) to work in mod_perl 2, as it does
currently in mod_perl 1.
--
Stephen Clouse <st...@theiqgroup.com>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>
[Patch] $r->print($scalarref) in Apache::compat
Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Wed, 2002-10-02 at 21:11, Geoffrey Young wrote:
> I thought that Doug had mentioned a few times that this functionality
> was a mistake in 1.0 and deprecated in 2.0. in fact, I thought it was
> in the 2.0 docs someplace, but I couldn't find it.
I remember myself that it was mentionned and couldn't find it either.
> it doesn't matter to me, but in the case that it doesn't belong in 2.0
> proper it should probably make it to the compat layer.
Something like this would do the trick I believe
Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.66
diff -u -b -B -r1.66 compat.pm
--- lib/Apache/compat.pm 24 Aug 2002 16:26:22 -0000 1.66
+++ lib/Apache/compat.pm 2 Oct 2002 15:35:44 -0000
@@ -218,6 +218,18 @@
} split /[=&;]/, $string, -1;
}
+{
+my $old_print;
+sub compat_print {
+ &$old_print( shift, map { (ref($_) eq 'SCALAR') ? $$_ : $_ } @_ );
+}
+if (not $old_print) {
+ no warnings;
+ $old_print = \&Apache::RequestRec::print;
+ *Apache::RequestRec::print = \&compat_print;
+}
+}
+
#sorry, have to use $r->Apache::args at the moment
#for list context splitting
Index: t/response/TestCompat/request.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/response/TestCompat/request.pm,v
retrieving revision 1.1
diff -u -b -B -r1.1 request.pm
--- t/response/TestCompat/request.pm 15 Aug 2002 09:35:11 -0000 1.1
+++ t/response/TestCompat/request.pm 2 Oct 2002 15:35:45 -0000
@@ -16,7 +16,7 @@
sub handler {
my $r = shift;
- plan $r, tests => 15;
+ plan $r, tests => 16;
$r->send_http_header('text/plain');
@@ -80,6 +80,7 @@
$r->post_connection(sub { OK });
ok 1;
+ $r->print(\"ok 16\n");
OK;
}
:
> --Geoff
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
>
>
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Stephen Clouse <st...@theiqgroup.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Oct 03, 2002 at 07:45:56AM +0100, Matt Sergeant wrote:
> IIRC it's because the print function is implemented in XS, so if you
> pass a large string there's no copying occurring like there would be if
> it was implemented in perl space naively. (i.e. my $string = shift).
And that's bad because....?
If we're worrying about Perl reusing the SV later, modperl_wbucket_write is
doing a memcpy of the PV anyway. So why copy it twice?
- --
Stephen Clouse <st...@theiqgroup.com>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9ngxoA4aoazQ9p2cRAu+5AKCPuT/lITBRl7viFsz3pCdbyU5H+wCfX28q
MOqdGMJ3ATk22rySjCjobpk=
=9F4M
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 2 Oct 2002, Stephen Clouse wrote:
> Hmmm...may I make a plea otherwise :) Being able to pass a reference is much
> preferred when outputting large strings (as we tend to do). I suppose I'd have
> to hear why it was considered a mistake, since I really don't see it as anything
> but useful.
because the arguments passed to the print xsub are not copied.
unlike a perl sub:
sub print {
my(@args) = @_;
}
where @_ is copied into @args.
so there's no advantage for the xsub to accept a scalar ref.
suggestion is to keep refs in perl land, but dereference before passing to
xsub land, like so:
my $html = <<EOF;
...
EOF
output($r, \$html);
sub output {
my($r, $data) = @_;
$r->print($$data);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Matt Sergeant <ma...@sergeant.org>.
On Wednesday, Oct 2, 2002, at 18:39 Europe/London, Stephen Clouse wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Wed, Oct 02, 2002 at 09:11:54AM -0400, Geoffrey Young wrote:
>> I thought that Doug had mentioned a few times that this functionality
>> was a mistake in 1.0 and deprecated in 2.0. in fact, I thought it was
>> in the 2.0 docs someplace, but I couldn't find it.
>
> Hmmm...may I make a plea otherwise :) Being able to pass a reference
> is much
> preferred when outputting large strings (as we tend to do). I suppose
> I'd have
> to hear why it was considered a mistake, since I really don't see it
> as anything
> but useful.
IIRC it's because the print function is implemented in XS, so if you
pass a large string there's no copying occurring like there would be if
it was implemented in perl space naively. (i.e. my $string = shift).
Matt.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Stephen Clouse <st...@theiqgroup.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Oct 02, 2002 at 09:11:54AM -0400, Geoffrey Young wrote:
> I thought that Doug had mentioned a few times that this functionality
> was a mistake in 1.0 and deprecated in 2.0. in fact, I thought it was
> in the 2.0 docs someplace, but I couldn't find it.
Hmmm...may I make a plea otherwise :) Being able to pass a reference is much
preferred when outputting large strings (as we tend to do). I suppose I'd have
to hear why it was considered a mistake, since I really don't see it as anything
but useful.
- --
Stephen Clouse <st...@theiqgroup.com>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9my9rA4aoazQ9p2cRAmb6AJ43/oZkIwDJBt15tqBL1cfK5NDnQwCg+5gR
qT9/wtVB94Vv6H4cnNEHAc4=
=DgKv
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
I thought that Doug had mentioned a few times that this functionality
was a mistake in 1.0 and deprecated in 2.0. in fact, I thought it was
in the 2.0 docs someplace, but I couldn't find it.
it doesn't matter to me, but in the case that it doesn't belong in 2.0
proper it should probably make it to the compat layer.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [PATCH] mp2: $r->print($scalarref)
Posted by Stephen Clouse <st...@theiqgroup.com>.
Here's the fully factorized version. I was in a hurry to mail this off :)
--
Stephen Clouse <st...@theiqgroup.com>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>