op.c:ck_svconst: Don’t allow ro COWs under old COW

Under PERL_OLD_COPY_ON_WRITE, allowing COWs to become read-only will
complicate things elsewhere.  It uses the IV slot of an SV to point
to a loop of SVs sharing the same buffer.  sv_2iv cannot cache the IV
without running the SV through sv_force_normal, but that will croak on
read-only values.  I could change it to S_sv_uncow, but there are more
cases elsewhere that would have to be audited, I don’t think it’s
worth spending time on improving PERL_OLD_COPY_ON_WRITE as it’s ‘dead
code, never intended to go live’ according to its author.  I am
bothering with at least this much because I don’t want to break it
knowingly.
universal.c: Ignore SvIsCOW in XS_Internals_SvREADONLY

SvIsCOW used to check SVf_READONLY|SVf_FAKE.  e3918bb703ca changed
that, but did not change the assumptions that code already made (that
there could be not truly read-only COWs.

Now SvREADONLY actually means read-only, so Internals::SvREADONLY
should not be saying that read-ony COWs are not, nor does it need to
flatten COWs when making them read-only.  Hence, locking hash values
no longer has a speed and memory hit if that hash contains COWs.

Part of the code is left in place for PERL_OLD_COPY_ON_WRITE, to avoid
making read-only COWs under that configuration.  See the previous com-
mit for why.
Make OLD_COPY_ON_WRITE handle SvLEN==0 scalars

SvLEN==0 means the scalar does not own the buffer.

PERL_OLD_COPY_ON_WRITE can’t do its copy-on-write with those, as
SvIsCOW && SvLEN==0 means a shared hash key scalar.

PerlIO::encoding passes such scalars to the Encode object’s
encode method.

Why am I even fixing this?  I was trying to make sure that I wasn’t
breaking PERL_OLD_COPY_ON_WRITE with other changes.  I got assertion
failures from encoding.t so I looked to see what the problem might be,
thinking it could affect other configurations.  It turns out not to be
specific to PERL_OLD_COPY_ON_WRITE, but since I have found the problem
I might as well fix it anyway.
Fix up Peek.t for alternate COW configurations

I.e., -DPERL_OLD_COPY_ON_WRITE and -DPERL_NO_COW
Make tr/a/b/ croak on read-only null COWs

$ ./perl -Ilib -e 'use constant nullrocow => (keys%{{""=>undef}})[0]; for(nullrocow) { y/a/b/ }'
$ ./perl -Ilib -e 'use constant nullro => ""; for(nullro) { y/a/b/ }'
Modification of a read-only value attempted at -e line 1.

It should croak on COW scalars that are read-only, even if they are
zero-length, just as it does on non-COW scalars.

This logic is left over from when READONLY+FAKE meant COW.
Don’t treat COWs specially in locked hashes

This is left over from when READONLY+FAKE meant copy-on-write.

Read-only copy-on-write scalars (which could not occur with the old
way of flagging things) must not be exempt from hash key restrictions.
Remove SvIsCOW checks from mg.c:S_save_magic

It no longer needs to worry about SvIsCOW.  This logic is left over
from when READONLY+FAKE was used for COWs.

Since it is possible for COWs to be read-only now, this logic is actu-
ally faulty, as it doesn’t temporarily stop read-only COWs from being
read-only, as it does for other read-only values.

This actually causes bugs with scalar-tied locked hash keys, which
croak on FETCH.
Remove SvIsCOW checks from mg.c:mg_localize

It no longer needs to worry about SvIsCOW.  This logic is left over
from when READONLY+FAKE was used for COWs.

Since it is possible for COWs to be read-only now, this logic is actu-
ally faulty, as it doesn’t temporarily stop read-only COWs from being
read-only, as it does for other read-only values.

This actually causes discrepancies with scalar-tied locked hash keys,
which differ in readonliness when localised depending on whether the previous value used copy-on-write.

Whether such scalars should be read-only after localisation is open
to debate, but it should not differ based on the means of storing the
previous value.
Read-only COWs should not be exempt from s/// croaking

$  ./miniperl -Ilib -e 'for(__PACKAGE__) { s/a/a/ }'
Modification of a read-only value attempted at -e line 1.
$  ./miniperl -Ilib -e 'for(__PACKAGE__) { s/b/b/ }'
$  ./miniperl -Ilib -e 'for("main") { s/a/a/ }'
Modification of a read-only value attempted at -e line 1.
$  ./miniperl -Ilib -e 'for("main") { s/b/b/ }'
Modification of a read-only value attempted at -e line 1.

When I pass the constant "main" to s///, it croaks whether the regular
expression matches or not.

When I pass __PACKAGE__, which has the same content and is also read-
only, it only croaks when the pattern matches.

This commit removes some logic that is left over from when
READONLY+FAKE meant copy-on-write.  Read-only does mean read-only now,
so copy-on-write scalars should not be exempt from read-only checks.
Stop system select from croaking on read-only COW ""

System select (select with 4 arguments) does not allow any of its
first three arguments to be read-only unless they are undef or
empty strings.

It does not work properly for read-only copy-on-write empty strings,
because it passes all copy-on-write through sv_force_normal under the
expectation that they will shortly be modified.  It should not be
doing that for read-only empty strings.
In sv.c:sv_magic don’t allow tying ro COWs

Read-only COWs are read-only and should not be treated as though they
were not.  This logic is left over from when READONLY+FAKE meant
copy-on-write.
Don’t allow read-only COWs to be blessed

The logic exempting copy-on-write scalars from read-only checks in
sv_bless was left over from when READONLY+FAKE meant copy-on-write.
[Merge] Read-only COWs

Commit 9a0a85075 made shared hash key constants read-only.  This meant
that copy-on-write scalars (shared hash key scalars are one type
of this) could have the read-only flag set, which could not hap-
pen before.

Much code still assumed that read-only && !cow was the proper way to
check for read-onliness (which was correct before perl 5.18, when
READONLY+FAKE meant COW).

This branch fixes up all the instances if SvIsCOW to work correctly
with read-only COWs.

It also allows Internals::SvREADONLY to make a COW read-only without
stopping it from being a COW (affecting constant.pm and Hash::Util).

I also went and fixed up tests under -DPERL_OLD_COPY_ON_WRITE and
-DPERL_NO_COW, in the process of making sure I wasn’t breaking those.