Torsten Foertsch wrote:
> Hi,
>
> the a pointer to current interpreter is somehow written
to the Perl
> interpreter itself by this macro:
>
> #ifndef HvPMROOT
> # if MP_PERL_VERSION_AT_LEAST(5, 9, 5)
> #define MP_THX_INTERP_SET(thx, interp)
>
((XPVMG*)SvANY(*Perl_Imodglobal_ptr(thx)))->xmg_u.xmg_mag
ic =
> (MAGIC*)interp
> # else
> #define MP_THX_INTERP_SET(thx, interp)
>
((XPVMG*)SvANY(*Perl_Imodglobal_ptr(thx)))->xmg_magic =
(MAGIC*)interp
> # endif
> #else
> #define MP_THX_INTERP_SET(thx, interp)
> HvPMROOT(*Perl_Imodglobal_ptr(thx)) =
(PMOP*)interp
> #endif
That's right, its so we can get to the modperl_interp_t from
a good perl THX.
It's seriously a hack, but it does the job quite nicely, and
there doesn't
seem to be a much better way to do it. It just uses an
unused magic field
to stash that pointer.
> What is HvPMROOT and what is Perl_Imodglobal_ptr?
Not even sure what HvPMROOT was, but it was just a
semi-arbitrairly chosen
field of the modglobal HV that wasn't likely to be used,
ever.
> Are these normal Perl
> variables that can also be accessed from Perl level?
Nope, they are deep inside the guts of Perl. modglobal is
documented somewhere
in perlguts, and it's just a general purpose HV* in the
interp structure for
this kind of magic.
> If not why are here
> special variables used?
Basic idea if I remember correctly was to be able to get
back to the modperl_interp_t
from a Perl interp. To make matters trickier, you need to be
able to retrieve it out
of there without actually entering Perl-land. That's why
instead of sticking it
in the modglobal hash, it's hagning off one of it's unused
struct member.
> Can that not be something like
> $Modperl::CurrentInterpreter or so?
Seems the original idea was to avoid going thru the perl
runtime to figure it out.
Hope this helps a little.
------------------------------------------------------------
------------
Philippe M. Chiasson GPG: F9BFE0C2480E7680
1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.or
g/ m/gozer (apache|cpan|ectoplasm).org/
|