perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Define a `CvREFCOUNTED_ANYSV` flag

Open leonerd opened this issue 3 years ago • 1 comments

If this flag is set, then the CvXSUBANY(cv).any_sv pointer will have its reference count decremented when the CV itself is freed. This is useful for XS extensions that wish to store extra data in here. Without this flag, such extensions have to resort to using magic with a 'free' function to perform this work.

As discussed in https://www.nntp.perl.org/group/perl.perl5.porters/2022/08/msg264572.html

leonerd avatar Aug 09 '22 11:08 leonerd

One small doc nit.

Wording fixed.

Otherwise, it'd be nice to have tests...

Yeeeah. Hrm. A test could be written but that's basically going to be a lot of lines added in probably XS-APItest. We don't have much existing framework for testing this kind of thing - even no equivalent of Test::Refcount in core until I recently added it.

leonerd avatar Aug 10 '22 19:08 leonerd

There is the awkward bit where you can either use this or aliases, but not both. I'm wondering if ParseXS should do something slightly smarter with that.

Related to that, this should also update the CvXSUB method in ext/B/B.xs, Perl_do_sv_dump and Perl_dump_sub_perl in dump.c; for better debuggability of CvXSUBANY.

Leont avatar Aug 16 '22 11:08 Leont

I've added an entry to perldelta.pod as well, before merge.

leonerd avatar Aug 16 '22 12:08 leonerd

Thanks for the tests!

wolfsage avatar Aug 16 '22 17:08 wolfsage