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

Re: New SV Flag

Thread Previous | Thread Next
Tim Bunce
February 6, 2003 05:47
Re: New SV Flag
Message ID:
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));
    if (!refcount_is_zero)
    if (! SvREFCNT(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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About