Skip to content

Commit

Permalink
Define and use GvREFCNT_inc*() macro family
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jul 19, 2024
1 parent 401432a commit 6fe12e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
18 changes: 18 additions & 0 deletions gv.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ struct gp {
HEK * gp_file_hek; /* file first declared in (for -w) */
};

/*
=for apidoc_section $GV
=for apidoc Am|GV *|GvREFCNT_inc|GV *gv
=for apidoc_item |GV *|GvREFCNT_inc_simple|GV *gv
=for apidoc_item |GV *|GvREFCNT_inc_simple_NN|GV *gv
These all increment the reference count of the given SV, which must be a GV.
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 GvREFCNT_inc(gv) ((GV *)SvREFCNT_inc((SV *)gv))
#define GvREFCNT_inc_simple(gv) ((GV *)SvREFCNT_inc_simple((SV *)gv))
#define GvREFCNT_inc_simple_NN(gv) ((GV *)SvREFCNT_inc_simple_NN((SV *)gv))

#define GvXPVGV(gv) ((XPVGV*)SvANY(gv))


Expand Down
12 changes: 3 additions & 9 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4475,15 +4475,9 @@ Perl_init_debugger(pTHX)
PL_curstash = (HV *)SvREFCNT_inc_simple(PL_debstash);

Perl_init_dbargs(aTHX);
PL_DBgv = MUTABLE_GV(
SvREFCNT_inc(gv_fetchpvs("DB::DB", GV_ADDMULTI, SVt_PVGV))
);
PL_DBline = MUTABLE_GV(
SvREFCNT_inc(gv_fetchpvs("DB::dbline", GV_ADDMULTI, SVt_PVAV))
);
PL_DBsub = MUTABLE_GV(SvREFCNT_inc(
gv_HVadd(gv_fetchpvs("DB::sub", GV_ADDMULTI, SVt_PVHV))
));
PL_DBgv = GvREFCNT_inc(gv_fetchpvs("DB::DB", GV_ADDMULTI, SVt_PVGV));
PL_DBline = GvREFCNT_inc(gv_fetchpvs("DB::dbline", GV_ADDMULTI, SVt_PVAV));
PL_DBsub = GvREFCNT_inc(gv_HVadd(gv_fetchpvs("DB::sub", GV_ADDMULTI, SVt_PVHV)));
PL_DBsingle = GvSV((gv_fetchpvs("DB::single", GV_ADDMULTI, SVt_PV)));
if (!SvIOK(PL_DBsingle))
sv_setiv(PL_DBsingle, 0);
Expand Down
8 changes: 4 additions & 4 deletions pp_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,12 @@ PP(pp_sort)
/* standard perl sub with values passed as $a and $b */
SAVEGENERICSV(PL_firstgv);
SAVEGENERICSV(PL_secondgv);
PL_firstgv = MUTABLE_GV(SvREFCNT_inc(
PL_firstgv = GvREFCNT_inc(
gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV)
));
PL_secondgv = MUTABLE_GV(SvREFCNT_inc(
);
PL_secondgv = GvREFCNT_inc(
gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV)
));
);
/* make sure the GP isn't removed out from under us for
* the SAVESPTR() */
save_gp(PL_firstgv, 0);
Expand Down
2 changes: 1 addition & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6687,7 +6687,7 @@ S_anonymise_cv_maybe(pTHX_ GV *gv, CV* cv)

CvANON_on(cv);
CvCVGV_RC_on(cv);
SvANY(cv)->xcv_gv_u.xcv_gv = MUTABLE_GV(SvREFCNT_inc(anongv));
SvANY(cv)->xcv_gv_u.xcv_gv = GvREFCNT_inc_simple(anongv);
}


Expand Down

0 comments on commit 6fe12e9

Please sign in to comment.