summaryrefslogtreecommitdiff
path: root/sv_inline.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-06-28 12:52:03 -0600
committerKarl Williamson <khw@cpan.org>2022-06-10 06:33:20 -0600
commit7ea9c672a4791a12f1bc5dd551f676234519016c (patch)
tree6e5c889958255aed69aed6bd401d7653e167c3d5 /sv_inline.h
parent8b710bfebf042f93a1048920ce9b0710d86cd46c (diff)
downloadperl-7ea9c672a4791a12f1bc5dd551f676234519016c.tar.gz
SvGETMAGIC: evaluate its argument just once
This required making it into an inline function. I tried using STMT_START{ ... } STMT_END, which should work since it has a void return, but there were places where it was used in a comma operator, and those did not compile.
Diffstat (limited to 'sv_inline.h')
-rw-r--r--sv_inline.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/sv_inline.h b/sv_inline.h
index c495d3cea0..2c2eff27df 100644
--- a/sv_inline.h
+++ b/sv_inline.h
@@ -565,6 +565,25 @@ Perl_SvPVXtrue(pTHX_ SV *sv)
return *sv->sv_u.svu_pv != '0';
}
+/*
+=for apidoc SvGETMAGIC
+Invokes C<L</mg_get>> on an SV if it has 'get' magic. For example, this
+will call C<FETCH> on a tied variable. As of 5.37.1, this function is
+guaranteed to evaluate its argument exactly once.
+
+=cut
+*/
+
+PERL_STATIC_INLINE void
+Perl_SvGETMAGIC(pTHX_ SV *sv)
+{
+ PERL_ARGS_ASSERT_SVGETMAGIC;
+
+ if (UNLIKELY(SvGMAGICAL(sv))) {
+ mg_get(sv);
+ }
+}
+
PERL_STATIC_INLINE bool
Perl_SvTRUE(pTHX_ SV *sv)
{