Author: stas Date: Thu Apr 7 16:32:47 2005 New Revision: 160495 URL: http://svn.apache.org/viewcvs?view=rev&rev=160495 Log: fix a bug when a non-threaded perl is used and anonymous sub is pushed at the server startup (the CV wasn't surviving)
Added: perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm (with props) perl/modperl/trunk/t/hooks/push_handlers_anon.t (with props) Modified: perl/modperl/trunk/Changes perl/modperl/trunk/src/modules/perl/modperl_handler.c Modified: perl/modperl/trunk/Changes URL: http://svn.apache.org/viewcvs/perl/modperl/trunk/Changes?view=diff&r1=160494&r2=160495 ============================================================================== --- perl/modperl/trunk/Changes (original) +++ perl/modperl/trunk/Changes Thu Apr 7 16:32:47 2005 @@ -18,6 +18,9 @@ 1.99_XX. Please read the below changes carefully. *************************************************** +fix a bug when a non-threaded perl is used and anonymous sub is pushed +at the server startup (the CV wasn't surviving) [Stas] + s/Apache::/Apache2::/g and s/mod_perl/mod_perl2/g in all module APIs. so, Apache::RequestRec is now Apache2::RequestRec, Apache::compat is now Apache2::compat, and so on. [joes] Modified: perl/modperl/trunk/src/modules/perl/modperl_handler.c URL: http://svn.apache.org/viewcvs/perl/modperl/trunk/src/modules/perl/modperl_handler.c?view=diff&r1=160494&r2=160495 ============================================================================== --- perl/modperl/trunk/src/modules/perl/modperl_handler.c (original) +++ perl/modperl/trunk/src/modules/perl/modperl_handler.c Thu Apr 7 16:32:47 2005 @@ -49,6 +49,7 @@ * PerlTransHandler 'sub { ... }' * B) run-time perl code * $r->push_handlers(PerlTransHandler => sub { .... }); + * $s->push_handlers(PerlTransHandler => sub { .... }); * * In the case of non-threaded perl, we just compile A or grab B and * store it in the mod_perl struct and call it when it's used. No @@ -169,6 +170,7 @@ #else /* it's safe to cache and later use the cv, since the same perl * interpeter is always used */ + SvREFCNT_inc((SV*)cv); handler->cv = cv; handler->name = NULL; Added: perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm URL: http://svn.apache.org/viewcvs/perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm?view=auto&rev=160495 ============================================================================== --- perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm (added) +++ perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm Thu Apr 7 16:32:47 2005 @@ -0,0 +1,72 @@ +package TestHooks::push_handlers_anon; + +# in addition to other anon sub handler tests in push_handlers*, here +# we test an anon sub added at the server startup. in order not to mess +# with the rest of the test suite, we run it in its own vhost + +use strict; +use warnings FATAL => 'all'; + +use Apache2::RequestRec (); +use Apache2::ServerUtil (); +use APR::Pool (); + +use Apache2::Const -compile => qw(OK DECLINED); + +use Apache::Test; +use Apache::TestUtil; + +sub add_note { + my $r = shift; + + my $count = $r->notes->get("add_note") || 0; + $count++; + $r->notes->set("add_note", $count); + Apache2::Const::DECLINED; +} + +# PerlFixupHandlers added at the server startup should add 3 notes +sub handler { + my $r = shift; + + plan $r, tests => 1; + + my $count = $r->notes->get("add_note") || 0; + ok t_cmp $count, 3, "$count callbacks"; + + Apache2::Const::OK; +} + +1; +__DATA__ +<NoAutoConfig> +# APACHE_TEST_CONFIG_ORDER 1000 +<VirtualHost TestHooks::push_handlers_anon> + PerlModule TestHooks::push_handlers_anon + <Perl > + # want to push a handler for a vhost, via $s, but the only way to + # get $s for vhost is to traverse the vhosts list + use Apache::Test; + use Apache::TestRequest; + Apache::TestRequest::module('TestHooks::push_handlers_anon'); + my $hostport = Apache::TestRequest::hostport(Apache::Test::config()); + my($host, $port) = split ':', $hostport; + my $s = Apache2::ServerUtil->server; + my $vs = $s->next; + for (; $vs; $vs = $vs->next) { + last if $port == $vs->port + } + $vs->push_handlers(PerlFixupHandler => + sub { &TestHooks::push_handlers_anon::add_note }); + $vs->push_handlers(PerlFixupHandler => + \&TestHooks::push_handlers_anon::add_note ); + $vs->push_handlers(PerlFixupHandler => + "TestHooks::push_handlers_anon::add_note" ); + </Perl> + + <Location /TestHooks__push_handlers_anon> + SetHandler modperl + PerlResponseHandler TestHooks::push_handlers_anon + </Location> +</VirtualHost> +</NoAutoConfig> Propchange: perl/modperl/trunk/t/hooks/TestHooks/push_handlers_anon.pm ------------------------------------------------------------------------------ svn:eol-style = native Added: perl/modperl/trunk/t/hooks/push_handlers_anon.t URL: http://svn.apache.org/viewcvs/perl/modperl/trunk/t/hooks/push_handlers_anon.t?view=auto&rev=160495 ============================================================================== --- perl/modperl/trunk/t/hooks/push_handlers_anon.t (added) +++ perl/modperl/trunk/t/hooks/push_handlers_anon.t Thu Apr 7 16:32:47 2005 @@ -0,0 +1,11 @@ +# the handler is configured in modperl_extra.pl via +# Apache2::ServerUtil->server->add_config + +use Apache::TestUtil; +use Apache::TestRequest 'GET_BODY_ASSERT'; + +my $module = 'TestHooks::push_handlers_anon'; +my $url = Apache::TestRequest::module2url($module); + +t_debug("connecting to $url"); +print GET_BODY_ASSERT $url; Propchange: perl/modperl/trunk/t/hooks/push_handlers_anon.t ------------------------------------------------------------------------------ svn:eol-style = native