From b234f9dcb641654e4ddd801437d93f1ef78dd587 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 9 Aug 2022 12:55:04 +0100 Subject: Define a CvREFCOUNTED_ANYSV flag 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. --- pad.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pad.c') diff --git a/pad.c b/pad.c index f999cb324a..61bacc2376 100644 --- a/pad.c +++ b/pad.c @@ -457,8 +457,11 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 flags) Safefree(padlist); CvPADLIST_set(&cvbody, NULL); } - else if (CvISXSUB(&cvbody)) + else if (CvISXSUB(&cvbody)) { + if (CvREFCOUNTED_ANYSV(&cvbody)) + SvREFCNT_dec(CvXSUBANY(&cvbody).any_sv); CvHSCXT(&cvbody) = NULL; + } /* else is (!CvISXSUB(&cvbody) && !CvPADLIST(&cvbody)) {do nothing;} */ @@ -2201,6 +2204,8 @@ S_cv_clone(pTHX_ CV *proto, CV *cv, CV *outside, HV *cloned) if (UNLIKELY(CvISXSUB(proto))) { CvXSUB(cv) = CvXSUB(proto); CvXSUBANY(cv) = CvXSUBANY(proto); + if (CvREFCOUNTED_ANYSV(cv)) + SvREFCNT_inc(CvXSUBANY(cv).any_sv); } else { OP_REFCNT_LOCK; -- cgit v1.2.1