This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #109542] Make num ops treat $1 as "$1"
authorFather Chrysostomos <sprout@cpan.org>
Wed, 6 Jun 2012 03:09:32 +0000 (20:09 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 7 Jun 2012 15:18:54 +0000 (08:18 -0700)
commit01f91bf275559c4ad5a42efe7848a0db00ceb317
treed1210a4901f728e53a84cc155c635ddb4bdefc0f
parentef5fe392ebd662891a80860e9ba74cc961823c81
[perl #109542] Make num ops treat $1 as "$1"

Numeric ops were not taking magical variables into account.  So $1 (a
magical variable) would be treated differently from "$1" (a non-magi-
cal variable0.

In determining whether to use an integer operation, they would call
SvIV_please_nomg, and then check whether the sv was SvIOK as a result.

SvIV_please_nomg would call SvIV_nomg if the sv were SvPOK or SvNOK.

The problem here is that gmagical variables are never SvIOK, but
only SvIOKp.

In fact, the private flags are used differently for gmagical and non-
magical variables.  For non-gmagical variables, the private flag indi-
cates that there is a cached value.  If the public flag is not set,
then the cached value is imprecise.  For gmagical variables, imprecise
values are never cached; only the private flags are used, and they are
equivalent to the public flags on non-gmagical variables.

This commit changes SvIV_please_nomg to take gmagical variables
into account, using the newly-added sv_gmagical_2iv_please (see the
docs for it in the diff).  SvIV_please_nomg now returns true or
false, not void, since a subsequent SvIOK is not reliable.  So
‘SvIV_please_nomg(sv); if(SvIOK)’ becomes ‘if(SvIV_please_nomg(sv))’.
embed.fnc
embed.h
pp.c
pp_hot.c
proto.h
sv.c
sv.h
t/op/arith.t