Skip to content

Commit

Permalink
Define and use CvREFCNT_inc*() macro family
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jul 19, 2024
1 parent 25517e5 commit 401432a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
18 changes: 18 additions & 0 deletions cv.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ struct xpvcv {
_XPVCV_COMMON;
};

/*
=for apidoc_section $CV
=for apidoc Am|CV *|CvREFCNT_inc|CV *cv
=for apidoc_item |CV *|CvREFCNT_inc_simple|CV *cv
=for apidoc_item |CV *|CvREFCNT_inc_simple_NN|CV *cv
These all increment the reference count of the given SV, which must be a CV.
They are useful when assigning the result into a typed pointer as they avoid
the need to cast the result to the appropriate type.
=cut
*/

#define CvREFCNT_inc(cv) ((CV *)SvREFCNT_inc((SV *)cv))
#define CvREFCNT_inc_simple(cv) ((CV *)SvREFCNT_inc_simple((SV *)cv))
#define CvREFCNT_inc_simple_NN(cv) ((CV *)SvREFCNT_inc_simple_NN((SV *)cv))

/*
=for apidoc Ayh||CV
Expand Down
2 changes: 1 addition & 1 deletion gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3293,7 +3293,7 @@ Perl_Gv_AMupdate(pTHX_ HV *stash, bool destructing)
cv = MUTABLE_CV(gv);
filled = 1;
}
amt.table[i]=MUTABLE_CV(SvREFCNT_inc_simple(cv));
amt.table[i] = CvREFCNT_inc_simple(cv);

if (gv) {
switch (i) {
Expand Down
2 changes: 1 addition & 1 deletion pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,7 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside, HV *cloned,
PL_compcv = cv;
if (newcv) SAVEFREESV(cv); /* in case of fatal warnings */

CvOUTSIDE(cv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
CvOUTSIDE(cv) = CvREFCNT_inc_simple(outside);

SAVESPTR(PL_comppad_name);
PL_comppad_name = protopad_name;
Expand Down
2 changes: 1 addition & 1 deletion pp_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,7 @@ S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh)
CX_CUR()->blk_gimme = gimme;

CvOUTSIDE_SEQ(evalcv) = seq;
CvOUTSIDE(evalcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
CvOUTSIDE(evalcv) = CvREFCNT_inc_simple(outside);

/* set up a scratch pad */

Expand Down
2 changes: 1 addition & 1 deletion toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -12860,7 +12860,7 @@ Perl_start_subparse(pTHX_ I32 is_format, U32 flags)

PL_subline = CopLINE(PL_curcop);
CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
CvOUTSIDE(PL_compcv) = CvREFCNT_inc_simple(outsidecv);
CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
if (outsidecv && CvPADLIST(outsidecv))
CvPADLIST(PL_compcv)->xpadl_outid = CvPADLIST(outsidecv)->xpadl_id;
Expand Down

0 comments on commit 401432a

Please sign in to comment.