pp_substr contains this comment, which was added in perl 5.0 alpha 2
(commit
79072805bf63):
PUSHs(TARG); /* avoid SvSETMAGIC here */
Calling set-magic when substr returns an lvalue will cause its argu-
ment to be stringified even if the lvalue is not assigned to. That’s
why set-magic has to be avoided.
But the result is that utf8 caches (stored in magic) on TARG are not
reset properly.
Since substr lvalues now follow a different code path (and do not use
TARG at all), it’s perfectly safe to call set-magic at this point.
It’s also the right thing to do in case of other types of magic that
might get attached to TARG.
}
}
SPAGAIN;
- PUSHs(TARG); /* avoid SvSETMAGIC here */
+ SvSETMAGIC(TARG);
+ PUSHs(TARG);
RETURN;
bound_fail:
}
};
-require './test.pl';
+BEGIN { require './test.pl'; }
-plan(361);
+plan(362);
run_tests() unless caller;
$x = bless({}, 'Class');
}
is($destroyed, 1, 'Timely scalar destruction with lvalue substr');
+
+# [perl #77692] UTF8 cache not being reset when TARG is reused
+ok eval {
+ local ${^UTF8CACHE} = -1;
+ for my $i (0..1)
+ {
+ my $dummy = length(substr("\x{100}",0,$i));
+ }
+ 1
+}, 'UTF8 cache is reset when TARG is reused [perl #77692]';