Skip to content

Commit 79277e9

Browse files
committed
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.
1 parent 22887b5 commit 79277e9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

inline.h

+7
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,13 @@ Perl_cop_file_avn(pTHX_ const COP *cop) {
34303430

34313431
#endif
34323432

3433+
PERL_STATIC_INLINE PADNAME *
3434+
Perl_padname_refcnt_inc(PADNAME *pn)
3435+
{
3436+
PadnameREFCNT(pn)++;
3437+
return pn;
3438+
}
3439+
34333440
/*
34343441
* ex: set ts=8 sts=4 sw=4 et:
34353442
*/

pad.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ Perl_pad_add_name_pvn(pTHX_ const char *namepv, STRLEN namelen,
613613
SAVEFREEPADNAME(name); /* in case of fatal warnings */
614614
/* check for duplicate declaration */
615615
pad_check_dup(name, flags & padadd_OUR, ourstash);
616-
PadnameREFCNT(name)++;
616+
PadnameREFCNT_inc(name);
617617
LEAVE;
618618
}
619619

@@ -2714,7 +2714,7 @@ Perl_padnamelist_dup(pTHX_ PADNAMELIST *srcpad, CLONE_PARAMS *param)
27142714
if (PadnamelistARRAY(srcpad)[max]) {
27152715
PadnamelistARRAY(dstpad)[max] =
27162716
padname_dup(PadnamelistARRAY(srcpad)[max], param);
2717-
PadnameREFCNT(PadnamelistARRAY(dstpad)[max])++;
2717+
PadnameREFCNT_inc(PadnamelistARRAY(dstpad)[max]);
27182718
}
27192719

27202720
return dstpad;
@@ -2775,7 +2775,7 @@ Perl_newPADNAMEouter(PADNAME *outer)
27752775
PadnamePV(pn) = PadnamePV(outer);
27762776
/* Not PadnameREFCNT(outer), because ‘outer’ may itself close over
27772777
another entry. The original pad name owns the buffer. */
2778-
PadnameREFCNT(PADNAME_FROM_PV(PadnamePV(outer)))++;
2778+
PadnameREFCNT_inc(PADNAME_FROM_PV(PadnamePV(outer)));
27792779
PadnameFLAGS(pn) = PADNAMEf_OUTER;
27802780
PadnameLEN(pn) = PadnameLEN(outer);
27812781
return pn;

pad.h

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ for C<my Foo $bar>.
249249
=for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn
250250
The reference count of the pad name.
251251
252+
=for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn
253+
Increases the reference count of the pad name. Returns the pad name itself.
254+
252255
=for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn
253256
Lowers the reference count of the pad name.
254257
@@ -321,6 +324,7 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
321324
#define PadnameHasTYPE(pn) cBOOL(PadnameTYPE(pn))
322325
#define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv
323326
#define PadnameREFCNT(pn) (pn)->xpadn_refcnt
327+
#define PadnameREFCNT_inc(pn) Perl_padname_refcnt_inc(pn)
324328
#define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn)
325329
#define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
326330
#define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s))

0 commit comments

Comments
 (0)