Stop split from mangling constants
authorFather Chrysostomos <sprout@cpan.org>
Fri, 21 Jun 2013 04:44:00 +0000 (21:44 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 23 Jun 2013 06:16:39 +0000 (23:16 -0700)
commit60041a0991995a4c82b6531822e284e1cc1c8a07
tree2c222e797cc5145a4d48f4ce3fb70108a2cbdc43
parent48c357fd49c074d84fc228fa5b89b851bd74d637
Stop split from mangling constants

At compile time, if split occurs on the right-hand side of an assign-
ment to a list of scalars, if the limit argument is a constant con-
taining the number 0 then it is modified in place to hold one more
than the number of scalars.

This means ‘constants’ can change their values, if they happen to be
in the wrong place at the wrong time:

$ ./perl -Ilib -le 'use constant NULL => 0; ($a,$b,$c) = split //, $foo, NULL; print NULL'
4

I considered checking the reference count on the SV, but since XS code
could create its own const ops with weak references to the same cons-
tants elsewhere, the safest way to avoid modifying someone else’s SV
is to mark the split op in ck_split so we know the SV belongs to that
split op alone.

Also, to be on the safe side, turn off the read-only flag before modi-
fying the SV, instead of relying on the special case for compile time
in sv_force_normal.
dist/B-Deparse/Deparse.pm
dump.c
ext/B/B/Concise.pm
op.c
op.h
t/op/split.t