summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-08-17 14:10:39 +0100
committerPaul Evans <leonerd@leonerd.org.uk>2022-08-17 15:59:15 +0100
commit79277e97f5c8cedf24a2686ea15b74abbc4b643a (patch)
treef9c7b194b404087d0118fe82ff95db50b32d749b
parent22887b5bfa220f1de2e85d93f5387a8870cc1ae7 (diff)
downloadperl-79277e97f5c8cedf24a2686ea15b74abbc4b643a.tar.gz
Add a PadnameREFCNT_inc() macro
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.
-rw-r--r--inline.h7
-rw-r--r--pad.c6
-rw-r--r--pad.h4
3 files changed, 14 insertions, 3 deletions
diff --git a/inline.h b/inline.h
index 3c9ef61fc5..76d52bee14 100644
--- a/inline.h
+++ b/inline.h
@@ -3430,6 +3430,13 @@ Perl_cop_file_avn(pTHX_ const COP *cop) {
#endif
+PERL_STATIC_INLINE PADNAME *
+Perl_padname_refcnt_inc(PADNAME *pn)
+{
+ PadnameREFCNT(pn)++;
+ return pn;
+}
+
/*
* ex: set ts=8 sts=4 sw=4 et:
*/
diff --git a/pad.c b/pad.c
index 61bacc2376..9c97f253a9 100644
--- a/pad.c
+++ b/pad.c
@@ -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;
}
@@ -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;
@@ -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;
diff --git a/pad.h b/pad.h
index 4b6c96ec75..6d3f3ff482 100644
--- a/pad.h
+++ b/pad.h
@@ -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.
@@ -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))