Skip to content

Commit

Permalink
Add a PadnameREFCNT_inc() macro
Browse files Browse the repository at this point in the history
Implemented as a static inline function call, so that it can return the
padname pointer itself.  This would allow use in expressions such as

  ptr->field = PadnameREFCNT_inc(pn);

That makes it similar to the familiar SvREFCNT_inc() macro.
  • Loading branch information
leonerd committed Aug 17, 2022
1 parent 9fdd7fc commit afddd67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ Perl_pad_add_name_pvn(pTHX_ const char *namepv, STRLEN namelen,
SAVEFREEPADNAME(name); /* in case of fatal warnings */
/* check for duplicate declaration */
pad_check_dup(name, flags & padadd_OUR, ourstash);
PadnameREFCNT(name)++;
PadnameREFCNT_inc(name);
LEAVE;
}

Expand Down Expand Up @@ -2714,7 +2714,7 @@ Perl_padnamelist_dup(pTHX_ PADNAMELIST *srcpad, CLONE_PARAMS *param)
if (PadnamelistARRAY(srcpad)[max]) {
PadnamelistARRAY(dstpad)[max] =
padname_dup(PadnamelistARRAY(srcpad)[max], param);
PadnameREFCNT(PadnamelistARRAY(dstpad)[max])++;
PadnameREFCNT_inc(PadnamelistARRAY(dstpad)[max]);
}

return dstpad;
Expand Down Expand Up @@ -2775,7 +2775,7 @@ Perl_newPADNAMEouter(PADNAME *outer)
PadnamePV(pn) = PadnamePV(outer);
/* Not PadnameREFCNT(outer), because ‘outer’ may itself close over
another entry. The original pad name owns the buffer. */
PadnameREFCNT(PADNAME_FROM_PV(PadnamePV(outer)))++;
PadnameREFCNT_inc(PADNAME_FROM_PV(PadnamePV(outer)));
PadnameFLAGS(pn) = PADNAMEf_OUTER;
PadnameLEN(pn) = PadnameLEN(outer);
return pn;
Expand Down
4 changes: 4 additions & 0 deletions pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ for C<my Foo $bar>.
=for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn
The reference count of the pad name.
=for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn
Increases the reference count of the pad name. Returns the pad name itself.
=for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn
Lowers the reference count of the pad name.
Expand Down Expand Up @@ -321,6 +324,7 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
#define PadnameHasTYPE(pn) cBOOL(PadnameTYPE(pn))
#define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv
#define PadnameREFCNT(pn) (pn)->xpadn_refcnt
#define PadnameREFCNT_inc(pn) Perl_padname_refcnt_inc(pn)
#define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn)
#define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
#define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s))
Expand Down
7 changes: 7 additions & 0 deletions sv_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,13 @@ Perl_newRV_noinc(pTHX_ SV *const tmpRef)
return sv;
}

PERL_STATIC_INLINE PADNAME *
Perl_padname_refcnt_inc(PADNAME *pn)
{
PadnameREFCNT(pn)++;
return pn;
}

/*
* ex: set ts=8 sts=4 sw=4 et:
*/

0 comments on commit afddd67

Please sign in to comment.