diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-10-27 23:30:28 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-10-28 02:04:57 -0700 |
commit | cd84013aab030da47b76a44fb3f7b6016be85b78 (patch) | |
tree | 0310735e26cc23a0f1991ab83c8d427f4fd5cf83 /t | |
parent | 78a84e43f7c23daa5ea308f75bfa99ce0fd2a841 (diff) | |
download | perl-cd84013aab030da47b76a44fb3f7b6016be85b78.tar.gz |
sv.c: !SvLEN does not mean undefined
There are various SvPOKp(sv) && SvLEN(sv) checks in numeric
conversion routines in sv.c, which date back to perl 1. (See
<http://perl5.git.perl.org/perl.git/blob/8d063cd8450e59e:/str.c#l89>.)
Back then it did not matter, as str->len (later SvLEN) was always set
when there was a PV. It was not until perl 5.003_01 (1edc1566d5) that
we got the SvLEN==0 mechanism for PVs not owned by the scalar. (I
don’t believe it was actually used till later, so when this became a
problem I don’t know--but that’s enough digging.)
A regexp returned by ${qr//} is POK but does not own its string. This
means that nummifying a regexp will result in a uninitialized warning.
The SvLEN check is redundant and problematic, so I am removing it.
(This also means I can remove the sv_force_normal calls in the next
commit, since shared hash key scalars, which also have SvLEN==0 will
no longer need it to pass the SvLEN checks.)
This does mean, however, that SVt_REGEXP can reach code paths that
expect to be able to use Sv[IN]VX (not valid for regexps), so I actu-
ally have to check that the type != SVt_REGEXP as well. We already
have code for handling fbm scalars (for which Sv[IN]VX fields are also
unusable), so we can send regexps through those paths.
Diffstat (limited to 't')
-rw-r--r-- | t/lib/warnings/9uninit | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index d1450d5d21..2877f14394 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -2072,3 +2072,17 @@ Use of uninitialized value $h{"17"} in sprintf at - line 5. Use of uninitialized value $h{"18"} in sprintf at - line 5. Use of uninitialized value $h{"19"} in sprintf at - line 5. Use of uninitialized value $h{"20"} in sprintf at - line 5. +######## +# NAME SvPOK && SvLEN==0 should not produce uninit warning +use warnings 'uninitialized'; + +$v = int(${qr||}); # sv_2iv on a regexp +$v = 1.1 * ${qr||}; # sv_2nv on a regexp +$v = ${qr||} << 2; # sv_2uv on a regexp + +sub TIESCALAR{bless[]} +sub FETCH {${qr||}} +tie $t, ""; +$v = 1.1 * $t; # sv_2nv on a tied regexp + +EXPECT |