PerlIO_teardown() calls PerlIO_debug(), which doesn't take an aTHX
argument, but assumes the TLS still points to a valid interpreter (it
contains a dTHX macro call). This seems like a bad assumption to me;
calling PERL_SYS_TERM before all interpreters have been destroyed is
a bug. Therefore I think PERL_SYS_TERM shouldn't require an aTHX,
and PerlIO_teardown either shouldn't call PerlIO_debug, or
PerlIO_debug needs to be written to work without having an
interpreter still being alive.

Cheers,
-Jan

On Fri, 02 Nov 2007, Dave Mitchell wrote:
> [ snip description of problems compiling mod_perl now that PERL_SYS_TERM
> expects a my_perl in scope ]
> 
> It appears that PERL_SYS_TERM first started needing a context with
> 
>     Change 29060 by [EMAIL PROTECTED] on 2006/10/20 10:20:18
> 
>           More leak fixes, by Jarkko
> 
>     ...
> 
>     -#define PERL_SYS_TERM()          HINTS_REFCNT_TERM; OP_REFCNT_TERM; 
> MALLOC_TERM
>     +#  define PERL_SYS_TERM()                HINTS_REFCNT_TERM; 
> OP_REFCNT_TERM; PERLIO_TERM; MALLOC_TERM
> 
>     ...
> 
>     +#  define PERLIO_TERM    PerlIO_teardown(aTHX)
> 
>     ...
> 
>     +void PerlIO_teardown(pTHX) /* Call only from PERL_SYS_TERM(). */
>     +{
>     +#ifdef DEBUGGING
>     +    {
>     + /* By now all filehandles should have been closed, so any
>     +  * stray (non-STD-)filehandles indicate *possible* (PerlIO)
>     +  * errors. */
>     + int i;
>     + for (i = 3; i < PL_perlio_fd_refcnt_size; i++) {
>     +     if (PL_perlio_fd_refcnt[i])
>     +         PerlIO_debug("PerlIO_cleanup: fd %d refcnt=%d\n",
>     +                      i, PL_perlio_fd_refcnt[i]);
>     + }
>     +    }
>     +#endif
> 
> perlembed.pod is silent about whether PERL_SYS_TERM needs a context,
> but at least one example shows it used in a function where there isn't a
> my_perl variable defined, so I think requiring a context is a bug.
> 
> Jarkko, is there any reason why PerlIO_teardown needs an aTHX?
> As far as I can see none of its body uses my_perl.
> 
> 
> --
> In England there is a special word which means the last sunshine
> of the summer. That word is "spring".

Reply via email to