Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PadnameREFCNT_inc() macro #20107

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,13 @@ Perl_cop_file_avn(pTHX_ const COP *cop) {

#endif

PERL_STATIC_INLINE PADNAME *
Perl_padname_refcnt_inc(PADNAME *pn)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sudden wondering whether this should be named S_ instead of Perl_, as it's only here to make one of the macros work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh; most of the rest of them are Perl_... and those seem fine. I'll leave it as is.

{
PadnameREFCNT(pn)++;
return pn;
}

/*
* ex: set ts=8 sts=4 sw=4 et:
*/
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