develooper Front page | perl.perl5.porters | Postings from February 2003

Re: New SV Flag

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
February 6, 2003 06:10
Subject:
Re: New SV Flag
Message ID:
20030206145338.ED30.H.M.BRAND@hccnet.nl
On Thu 06 Feb 2003 13:15, Tim Bunce <Tim.Bunce@pobox.com> wrote:
> On Thu, Feb 06, 2003 at 08:26:49AM +0100, Arthur Bergman wrote:
> > 
> > On onsdag, feb 5, 2003, at 23:09 Europe/Stockholm, Nicholas Clark wrote:
> > 
> > >On Mon, Feb 03, 2003 at 01:14:59AM +0100, Arthur Bergman wrote:
> > >>Hi,
> > >>
> > >>I would like a new SV flag, or SV flag combination that means, this SV
> > >>does not live on the arenas and should not be PL_sv_counted, a hint to
> > >>sv_free not to plant this sv again.
> > >
> > >What do you mean plant? particularly with respect to sv_free?
> > >
> > 
> > When a sv is freed, a macro called plant_SV is called.
> > 
> > #define plant_SV(p) \
> >     STMT_START {                                        \
> >         SvANY(p) = (void *)PL_sv_root;                  \
> >         SvFLAGS(p) = SVTYPEMASK;                        \
> >         PL_sv_root = (p);                               \
> >         --PL_sv_count;                                  \
> >     } STMT_END
> > 
> > Now, if the SV is allocated by an external malloc, I don't want the 
> > pointer to go into PL_sv_root, and I don't want PL_sv_count to be 
> > killed off.
> > 
> > I wonder if there is a way to do this with magic but I think no matter 
> > what is done in the magic destructor, perl will continue to go on. 
> > Basically I want a flag that says, sv_free, don't free this SV, call 
> > the magic destructor and then don't do anything more.
> 
> sv_free does:
> 
>     ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));

I did propose a patch to the magicians to weed out ATOMIC_INC and
ATOMIC_DEC_AND_TEST as by Arthur and Nick's request. Where did it go?

>     if (!refcount_is_zero)
>         return;
>     sv_clear(sv);
>     if (! SvREFCNT(sv))
>         del_SV(sv);
> 
> I can't remember why the last SvREFCNT(sv) test is there
> but perhaps it could be useful for you... sv_clear calls
> mg_free, your magic destructor could test for SvREFCNT(sv)==0
> to know that the sv was about to be freed and set SvREFCNT
> to a non-zero value to prevent the final del_SV.
> 
> Alternatively, mg_free currently always returns zero.
> Perhaps it could return some flags based on some magic flags.
> Thus magic flags could be used as an extension of sv flags
> for the purpose of influencing the death of an sv.
> 
> Tim.

-- 
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using perl-5.6.1, 5.8.0 & 633 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
  WinNT 4, Win2K pro & WinCE 2.11.  Smoking perl CORE: smokers@perl.org
http://archives.develooper.com/daily-build@perl.org/   perl-qa@perl.org
send smoke reports to: smokers-reports@perl.org, QA: http://qa.perl.org



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About