perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: t/perl/ithreads.t revisited
Date Mon, 13 Dec 2004 18:45:17 GMT
Steve Hay wrote:

> I now get this in the stderr.txt file:
> 
> SV = PV(0x31f64d0) at 0x31960b8
>   REFCNT = 1
>   FLAGS = (TEMP,POK,pPOK)
>   PV = 0x31f7ed4 "ModPerl::Util::exit: (120000) exit was called at 
> C:/apache2/perl5/site/lib/Apache/Test.pm line 238"\0
>   CUR = 98
>   LEN = 99
> Attempt to free temp prematurely: SV 0x31960b8, Perl interpreter: 
> 0x2b51784 at 
> C:/Temp/bug-reporting-skeleton-mp2/t/response/TestPerl/ithreads.pm line 56.
> Scalars leaked: 1

Getting back to the exit function itself called from Apache::Test::plan().

This sv thing shouldn't have really happened. How does exit works in mp2:

void modperl_perl_exit(pTHX_ int status)
{
     ENTER;
     SAVESPTR(PL_diehook);
     PL_diehook = Nullsv;
     modperl_croak(aTHX_ MODPERL_RC_EXIT, "ModPerl::Util::exit");
}

so exit calls modperl_croak(), which creates an APR::Error exception 
object and throws it via Perl_croak(aTHX_ Nullch);

Now when the handler returns its status goes through modperl_errsv() which 
has a special case for objects thrown from exit()'s call.

int modperl_errsv(pTHX_ int status, request_rec *r, server_rec *s)
{
     SV *sv = ERRSV;
     STRLEN n_a;

     if (SvTRUE(sv)) {
         if (sv_derived_from(sv, "APR::Error") &&
             SvIVx(sv) == MODPERL_RC_EXIT) {
             /* ModPerl::Util::exit was called */
             return OK;
         }

the actual stringification of the exception object into a string:

"ModPerl::Util::exit: (120000) exit was called at 
C:/apache2/perl5/site/lib/Apache/Test.pm line 238"\0

happens only if something tries to stringify $@ or bool'ify. But this 
stringification is done by a perl code in APR::Error, which overloads:

use overload
     nomethod => \&fatal,
     'bool'   => \&str,
     '=='     => \&num,
     '0+'     => \&num,
     '""'     => \&str;

sub str {
     sprintf "%s: (%d) %s at %s line %d", $_[0]->{func},
         $_[0]->{rc}, APR::Error::strerror($_[0]->{rc}),
         $_[0]->{file}, $_[0]->{line};
}

and this is what your SV's PV string looks like. So there is no really any 
C code here that could get the refcounting wrong.

may be this is something triggered by overload? what happens if you 
comment out the overload part?

(notice that APR::Error is autogenerated, so you may want to modify
blib/lib/Apache2/APR/Error.pm if you don't want to rebuild things)

alternatively try to add CORE::dump() inside str() above to see who has 
called the stringification function.

-- 
__________________________________________________________________
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


Mime
View raw message