Make it possible to have read-only glob copies
(aka Fun with Hash::Util)
This script gives ‘Modification of a read-only value’:
use Hash::Util lock_value;
*foo::; # autovivify
lock_value %::, foo::::;
*foo:: = [];
So far so good. That’s to be expected. But this one crashes:
use Hash::Util lock_value;
$a{h} = *foo;
lock_value %a, h;
$a{h} = [];
Under debugging builds, it gives assertion failures.
Anyone who knows how the flags work will see immediately what’s wrong,
but for the sake of those who don’t:
The SVf_FAKE flag is set on a copy of a typeglob, meaning that assign-
ing something other than a glob to it will overwrite the glob, instead
of writing to one of its slots.
The SVf_FAKE flag on a read-only (SVf_READONLY-flagged) string means
that it’s not actually read-only, but a copy-on-write string.
SVf_READONLY on a glob means that you can’t even assign *through* it.
See the first Hash::Util example above.
The crashing occurs when the two flags are combined.
sv_force_normal_flags assumes that anything marked fake AND read-only
is a copy-on-write string, so it proceeds to gut it, even if it’s
actually just corrupting a glob.
So this commit changes that check to take typeglobs into account.