develooper Front page | perl.perl5.porters | Postings from August 2022

Re: CV flag for refcounted CvXSUBANY.any_sv

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
August 8, 2022 19:51
Subject:
Re: CV flag for refcounted CvXSUBANY.any_sv
Message ID:
CAHhgV8gOZ8TQJ=452_V4222FuB4+nXWXx2bKEHgOffd4iqY11Q@mail.gmail.com
On Mon, Aug 8, 2022 at 7:52 PM Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
wrote:

> XSUBs provide an ANY union that code can store whatever it wants, to be
> later accessed within the CV body. Being an ANY union, one of the
> possibilities is to store an SV pointer in there. This is fairly common
> (at least, in my code).
>
> Since it stores an SV pointer, you need to arrange for it to be
> SvREFCNT_dec'ed when the CV itself is destroyed (e.g. perhaps the CV is
> an anonymous closure).
>
> Perl doesn't currently provide a facility for this, meaning I end up
> having to do annoying magic on the CV just to make it happen at the
> right time.
>
> I'm thinking of adding a CV flag to tell Perl to do that automatically.
> When clearing an SV it can then use
>
>   if(FLAG)
>     SvREFCNT_dec(CvXSUBANY(cv).any_sv);
>
>
> Thoughts anyone?
>

Makes sense, and there is prior art of doing such things (e.g. with the
mg_ptr field of struct magic)

Leon

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