Make OLD_COPY_ON_WRITE handle SvLEN==0 scalars
authorFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 06:30:33 +0000 (23:30 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 14:41:25 +0000 (07:41 -0700)
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.

sv.c

diff --git a/sv.c b/sv.c
index 99b23db..fc22350 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4340,7 +4340,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, SV* sstr, const I32 flags)
                ? (!((sflags & CAN_COW_MASK) == CAN_COW_FLAGS
 # ifdef PERL_OLD_COPY_ON_WRITE
                     && (SvFLAGS(dstr) & CAN_COW_MASK) == CAN_COW_FLAGS
-                    && SvTYPE(sstr) >= SVt_PVIV
+                    && SvTYPE(sstr) >= SVt_PVIV && len
 # else
                     && !(SvFLAGS(dstr) & SVf_BREAK)
                     && !(sflags & SVf_IsCOW)