Skip to content

Commit c79fe2b

Browse files
committedJun 12, 2024
S_new_SV: args unused, static inline & defined, rename with Perl_ prefix
When sv_inline.h was created in 75acd14 and a number of things moved into it, the S_new_SV debugging function should have been made PERL_STATIC_INLINE and given the Perl_ prefix. This commit now does those things. It also marks the arguments to Perl_new_SV as PERL_UNUSED_ARG, reducing warnings on some builds. Additionally, now that we can use inline functions, the new_SV() macro is now just a call to this inline function, rather than being that only on DEBUG_LEAKING_SCALARS builds and a multi-line macro the rest of the time.
1 parent 864b129 commit c79fe2b

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed
 

‎embed.fnc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,10 @@ AMbdp |CV * |newSUB |I32 floor \
22482248
|NULLOK OP *proto \
22492249
|NULLOK OP *block
22502250
ARdp |SV * |newSV |const STRLEN len
2251+
: Perl_new_sv is inline, so needs to be visible outside of sv.c
2252+
Ciop |SV * |new_sv |NN const char *file \
2253+
|int line \
2254+
|NN const char *func
22512255
Rp |SV * |newSVavdefelem |NN AV *av \
22522256
|SSize_t ix \
22532257
|bool extendible

‎proto.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ typedef enum {
193193
# define HVAUX_ARENA_ROOT_IX SVt_IV
194194
#endif
195195
#ifdef PERL_IN_SV_C
196-
# define SVt_FIRST SVt_NULL /* the type of SV that new_SV() in sv.c returns */
196+
# define SVt_FIRST SVt_NULL /* the type of SV that new_SV() in sv_inline.h returns */
197197
#endif
198198

199199
#define PERL_ARENA_ROOTS_SIZE (SVt_LAST)

‎sv_inline.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@
6868
SV* Perl_more_sv(pTHX);
6969

7070
/* new_SV(): return a new, empty SV head */
71-
72-
#ifdef DEBUG_LEAKING_SCALARS
73-
/* provide a real function for a debugger to play with */
74-
STATIC SV*
75-
S_new_SV(pTHX_ const char *file, int line, const char *func)
71+
PERL_STATIC_INLINE SV*
72+
Perl_new_sv(pTHX_ const char *file, int line, const char *func)
7673
{
7774
SV* sv;
75+
#ifndef DEBUG_LEAKING_SCALARS
76+
PERL_UNUSED_ARG(file);
77+
PERL_UNUSED_ARG(line);
78+
PERL_UNUSED_ARG(func);
79+
#endif
7880

7981
if (PL_sv_root)
8082
uproot_SV(sv);
@@ -83,6 +85,7 @@ S_new_SV(pTHX_ const char *file, int line, const char *func)
8385
SvANY(sv) = 0;
8486
SvREFCNT(sv) = 1;
8587
SvFLAGS(sv) = 0;
88+
#ifdef DEBUG_LEAKING_SCALARS
8689
sv->sv_debug_optype = PL_op ? PL_op->op_type : 0;
8790
sv->sv_debug_line = (U16) (PL_parser && PL_parser->copline != NOLINE
8891
? PL_parser->copline
@@ -99,25 +102,10 @@ S_new_SV(pTHX_ const char *file, int line, const char *func)
99102
MEM_LOG_NEW_SV(sv, file, line, func);
100103
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) new_SV (from %s:%d [%s])\n",
101104
PTR2UV(sv), (long)sv->sv_debug_serial, file, line, func));
102-
105+
#endif
103106
return sv;
104107
}
105-
# define new_SV(p) (p)=S_new_SV(aTHX_ __FILE__, __LINE__, FUNCTION__)
106-
107-
#else
108-
# define new_SV(p) \
109-
STMT_START { \
110-
if (PL_sv_root) \
111-
uproot_SV(p); \
112-
else \
113-
(p) = Perl_more_sv(aTHX); \
114-
SvANY(p) = 0; \
115-
SvREFCNT(p) = 1; \
116-
SvFLAGS(p) = 0; \
117-
MEM_LOG_NEW_SV(p, __FILE__, __LINE__, FUNCTION__); \
118-
} STMT_END
119-
#endif
120-
108+
# define new_SV(p) (p)=Perl_new_sv(aTHX_ __FILE__, __LINE__, FUNCTION__)
121109

122110
typedef struct xpvhv_with_aux XPVHV_WITH_AUX;
123111

0 commit comments

Comments
 (0)
Please sign in to comment.