summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/XS-APItest/t/svpv_magic.t3
-rw-r--r--sv.c3
-rw-r--r--sv.h7
3 files changed, 9 insertions, 4 deletions
diff --git a/ext/XS-APItest/t/svpv_magic.t b/ext/XS-APItest/t/svpv_magic.t
index dd2af8c419..8be18d4020 100644
--- a/ext/XS-APItest/t/svpv_magic.t
+++ b/ext/XS-APItest/t/svpv_magic.t
@@ -25,8 +25,5 @@ is(XS::APItest::first_byte("$1"), 0303,
$a =~ s/(.)/$1/; # $1 now has the utf8 flag set too
$b =~ /(.)/; # $1 shouldn't have the utf8 flag anymore
-TODO: {
-local $TODO = "SvPVbyte should handle get magic before checking the utf8 flag";
is(eval { XS::APItest::first_byte($1) } || $@, 0303,
"utf8 flag fetched correctly without stringification");
-}
diff --git a/sv.c b/sv.c
index fa6b8fb1e8..14b8b3997d 100644
--- a/sv.c
+++ b/sv.c
@@ -3028,8 +3028,9 @@ Perl_sv_2pvbyte(pTHX_ register SV *const sv, STRLEN *const lp)
{
PERL_ARGS_ASSERT_SV_2PVBYTE;
+ SvGETMAGIC(sv);
sv_utf8_downgrade(sv,0);
- return lp ? SvPV(sv,*lp) : SvPV_nolen(sv);
+ return lp ? SvPV_nomg(sv,*lp) : SvPV_nomg_nolen(sv);
}
/*
diff --git a/sv.h b/sv.h
index 3be9559242..92f5edd74a 100644
--- a/sv.h
+++ b/sv.h
@@ -1421,6 +1421,9 @@ Returns a pointer to the string in the SV, or a stringified form of
the SV if the SV does not contain a string. The SV may cache the
stringified form becoming C<SvPOK>. Handles 'get' magic.
+=for apidoc Am|char*|SvPV_nomg_nolen|SV* sv
+Like C<SvPV_nolen> but doesn't process magic.
+
=for apidoc Am|IV|SvIV|SV* sv
Coerces the given SV to an integer and returns it. See C<SvIVx> for a
version which guarantees to evaluate sv only once.
@@ -1586,6 +1589,10 @@ Like sv_utf8_upgrade, but doesn't do magic on C<sv>
((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
? SvPVX(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC))
+#define SvPV_nomg_nolen(sv) \
+ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
+ ? SvPVX(sv) : sv_2pv_flags(sv, 0, 0))
+
#define SvPV_nolen_const(sv) \
((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
? SvPVX_const(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC|SV_CONST_RETURN))