First victim, er SV type
[email protected] (Nicholas Clark) Fri, 7 May 2004 13:50:32 +0100
| Newsgroups | perl.ponie.dev |
|---|---|
| Message-ID | <[email protected]> |
After an epic battle with Perl_sv_unglob, CVS ponie now hides all perl SV
types behind PMCs. This is good.
What it's actually doing currently is just adding a PMC between the SV
head and the SV body, so instead of conventional perl SVs
head
|
`-> body
we now have
head
|
`-> PMC
|
`-> body
and all the Sv... Cv... Gv... etc accessor macros now running through
functions. (and all tests pass, except the ones that we have to skip)
So in effect now our SvPMC() flag is irrelevant, as we've made the
completed transition it was facilitating.
The logical next step seems to be to take one of the perl SV types an
eliminate the body, storing the data directly in the PMC, so that we have
head
|
`-> PMC
and convert the relevant accessor macros so that it all works smoothly
with this. Arthur and I were thinking do RVs first, as the RV's body
structure is very simple:
struct xrv {
SV * xrv_rv; /* pointer to another SV */
};
However, two things start to worry me. One is that there's code like this:
SvRV(sv) = (SV*)gv;
SvROK_on(sv);
SvSETMAGIC(sv);
(pp_rv2gv)
which means people start setting SV fields before announcing that the SV
is to be an RV. (It could have been, say, a PVNV body at this point)
I think we can work round that currently by having SvROK_on() be a function
that changes the SV from
head
|
`-> PMC
|
`-> XPVNV body
to
head
|
`-> PMC RV
but it starts to feel messy.
My second concern is that it's possible to make references which need to be
larger scalars
$ perl -MDevel::Peek -lwe '$a = \$b; $c = \$a; bless $c; Dump $c'
Name "main::b" used only once: possible typo at -e line 1.
SV = RV(0x81123c) at 0x809884
REFCNT = 1
FLAGS = (ROK)
RV = 0x80980c
SV = PVMG(0x81033c) at 0x80980c
REFCNT = 2
FLAGS = (OBJECT,ROK)
IV = 8427556
NV = 8427556
RV = 0x809824
SV = NULL(0x0) at 0x809824
REFCNT = 2
FLAGS = ()
PV = 0x809824 ""
CUR = 0
LEN = 0
STASH = 0x800290 "main"
So we're need to have SvRV now calling a Perl_macro_SvRV that makes a choice
of where to return based on body type.
But then again, currently we have all the macros making this decision based
on the SvPMC() flag, so it's not that evil. And it will go away once
everything is done.
Maybe it would be better to start with IV and NV, as they don't have problems
with being upgraded, and can't be downgraded to.
Or maybe we should start at the most complex end of the PMC inheritance tree?
Nicholas Clark
PS I'm not sure how clear it is - to get ponie from cvs:
cvs -d :pserver:[email protected]:/cvs/public co ponie
cd ponie
cvs -d :pserver:[email protected]:/cvs/public co parrot