The magic check came too late. sv_utf8_downgrade does nothing if the
argument is not a PV.
So in the test added to svpv.t the returned string was in utf8,
not bytes.
-use Test::More tests => 18;
+use Test::More tests => 19;
package r { use overload '""' => sub { substr "\x{100}\xff", -1 } }
is SvPVbyte(bless [], r::), "\xff",
'SvPVbyte on ref returning downgradable utf8 string';
package r { use overload '""' => sub { substr "\x{100}\xff", -1 } }
is SvPVbyte(bless [], r::), "\xff",
'SvPVbyte on ref returning downgradable utf8 string';
+
+sub TIESCALAR { bless \(my $thing = pop), shift }
+sub FETCH { ${ +shift } }
+tie $tyre, main => bless [], r::;
+is SvPVbyte($tyre), "\xff",
+ 'SvPVbyte on tie returning ref that returns downgradable utf8 string';
{
PERL_ARGS_ASSERT_SV_2PVBYTE;
{
PERL_ARGS_ASSERT_SV_2PVBYTE;
if (((SvREADONLY(sv) || SvFAKE(sv)) && !SvIsCOW(sv))
|| isGV_with_GP(sv) || SvROK(sv)) {
SV *sv2 = sv_newmortal();
if (((SvREADONLY(sv) || SvFAKE(sv)) && !SvIsCOW(sv))
|| isGV_with_GP(sv) || SvROK(sv)) {
SV *sv2 = sv_newmortal();
+ sv_copypv_nomg(sv2,sv);
sv_utf8_downgrade(sv,0);
return lp ? SvPV_nomg(sv,*lp) : SvPV_nomg_nolen(sv);
}
sv_utf8_downgrade(sv,0);
return lp ? SvPV_nomg(sv,*lp) : SvPV_nomg_nolen(sv);
}