You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2007/09/26 19:08:23 UTC

What is PERL_SET_CONTEXT for?

Hi,

in modperl_callback.c I have found this piece of code:

    if (r || c) {
        interp = modperl_interp_select(r, c, s);
        aTHX = interp->perl;
    }
    else {
        /* Child{Init,Exit}, OpenLogs */
        aTHX = scfg->mip->parent->perl;
        PERL_SET_CONTEXT(aTHX);
    }

"man perlembed" says:

       Note the calls to PERL_SET_CONTEXT().  These are necessary to initial‐
       ize the global state that tracks which interpreter is the "current" one
       on the particular process or thread that may be running it.  It should
       always be used if you have more than one interpreter and are making
       perl API calls on both interpreters in an interleaved fashion.

       PERL_SET_CONTEXT(interp) should also be called whenever "interp" is
       used by a thread that did not create it (using either perl_alloc(), or
       the more esoteric perl_clone()).

So, is it an error not to call PERL_SET_CONTEXT in the if-branch?

Shouldn't PERL_SET_CONTEXT be called every time an interpreter is selected?

Thanks,
Torsten

Re: What is PERL_SET_CONTEXT for?

Posted by Torsten Foertsch <to...@gmx.net>.
On Thursday 27 September 2007 00:54, Philippe M. Chiasson wrote:
> Pretty much, yes. I personally think all this SET_CONTEXT stuff belongs
> in modperl_interp_* and not sprinkled all over the place.

That's what I meant to say next. So, I'll include it in the patch.

Torsten

Re: What is PERL_SET_CONTEXT for?

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.

Torsten Foertsch wrote:
> Hi,
> 
> in modperl_callback.c I have found this piece of code:
> 
>     if (r || c) {
>         interp = modperl_interp_select(r, c, s);
>         aTHX = interp->perl;
>     }
>     else {
>         /* Child{Init,Exit}, OpenLogs */
>         aTHX = scfg->mip->parent->perl;
>         PERL_SET_CONTEXT(aTHX);
>     }
> 
> "man perlembed" says:
> 
>        Note the calls to PERL_SET_CONTEXT().  These are necessary to initial‐
>        ize the global state that tracks which interpreter is the "current" one
>        on the particular process or thread that may be running it.  It should
>        always be used if you have more than one interpreter and are making
>        perl API calls on both interpreters in an interleaved fashion.
> 
>        PERL_SET_CONTEXT(interp) should also be called whenever "interp" is
>        used by a thread that did not create it (using either perl_alloc(), or
>        the more esoteric perl_clone()).
> 
> So, is it an error not to call PERL_SET_CONTEXT in the if-branch?

I would say yes, it's a bug.

> Shouldn't PERL_SET_CONTEXT be called every time an interpreter is selected?

Pretty much, yes. I personally think all this SET_CONTEXT stuff belongs
in modperl_interp_* and not sprinkled all over the place.

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/