From 71eb6d8cfb246d23c05d58a2404b8e67ca3e8968 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 25 Oct 2010 22:59:59 +1100 Subject: [PATCH] rt #72398 - get magic before downgrading in SvPVbyte() --- ext/XS-APItest/t/svpv_magic.t | 3 --- sv.c | 3 ++- sv.h | 7 +++++++ 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 dd2af8c..8be18d4 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 fa6b8fb..14b8b39 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 3be9559..92f5edd 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. Handles 'get' magic. +=for apidoc Am|char*|SvPV_nomg_nolen|SV* sv +Like C but doesn't process magic. + =for apidoc Am|IV|SvIV|SV* sv Coerces the given SV to an integer and returns it. See C 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 ((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)) -- 2.7.4