Fix infinite loop with $tied =~ s/non-utf8/utf8/
Commit
3e462cdc208 fixed bug #41530 (s/non-utf8/utf8/ was not working
properly at all) by upgrading the target and redoing the substitution
if the replacement was utf8 and the target was not.
Commit
c95ca9b8cd1 fixed one problem with it calling get-magic too
many times, by checking whether the upgrade caused a string realloca-
tion and only then redoing the substitution. But it only fixed it
when magic returns a pure ASCII string.
Redoing the substitution meant going back to where the target was
initially stringified and starting again. That meant calling get-
magic again.
So in those cases where magic returned something other than a UTF8 or
pure ASCII string the substitution restarted and magic would be trig-
gered again, possibly resulting in infinite loops (because it would
have to be upgraded again, resulting a reallocation, and a restart).
This happens with:
• Latin-1 strings
• Copy-on-write non-UTF8 strings
• References that stringify without UTF8
c95ca9b8cd1 also added SvPVX without checking first that it is SvPVX-
able, so a typeglob causes an assertion failure.
It turned out that there were also two other places in pp_subst that
were calling FETCH a second time (the tests I added for the looping/
assertion bugs found this), so I changed them, too.