[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))’.
pp_negate: Don’t treat nummified str as num

I think it’s a bug that this prints 0:

$ ./perl -lIlib -MDevel::Peek -e '$x = "dogs"; 0+$x; Dump $x; print -$x'
SV = PVNV(0x802340) at 0x821b90
  REFCNT = 1
  FLAGS = (POK,pIOK,pNOK,pPOK)
  IV = 0
  NV = 0
  PV = 0x301620 "dogs"\0
  CUR = 4
  LEN = 16
0

This variable is a string, not a number.  The number 0 is just a
cached value.  It lacks the IOK flag precisely because the IV is not
representative of the actual value of the scalar.

This logic here is a little bit odd:

        if( !SvNIOK( sv ) && looks_like_number( sv ) ){
           SvIV_please( sv );
        }

	if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) {

SvIV_please sets the flags on sv but then they are ignored when check-
ing for integrality.

To fix the bug mentioned above, I had to change this logic to use sv
directly, rather than the saved flags.

That meant that this bug was also fixed at the same time, since the
integer code is no longer bypassed when it is SvIV_please that sets
the integer flags:

$ ./perl -Ilib -le 'print -97656250000000000'
-97656250000000000
$ ./perl -Ilib -le 'print -"97656250000000000"'
-9.765625e+16
Fix perl #57706 for magical vars: -"-10"

Commit a5b92898 caused -"-10" to return 10, not "+10".  But it wasn’t
working for magical variables.

SvIV_please_nomg was fixed recently for magical variables, but not
SvIV_please, so change pp_negate to use that.

(Ironically, SvIV_please has never called magic, so the
SvIV_please_nomg variant never needed to exist.  So the two could
be merged.)
pp_negate and the Unicode Bug

$ ./perl -Ilib -Mutf8 -CO -le 'print -"3 apples"'
-3
$ ./perl -Ilib -Mutf8 -CO -le 'print -"3 μῆλα"'
-3 μῆλα

This has been this way since 5.10.1.  In 5.10.0, it was consistent:

$ perl5.10.0 -Mutf8 -CO -le 'print -"3 apples"'
-3
$ perl5.10.0 -Mutf8 -CO -le 'print -"3 μῆλα"'
-3

But the worst part is that we get a non-numeric warning now for a
string operation:

$ perl5.10.1 -Mutf8 -CO -lwe 'print -"3 μῆλα"'
Argument "\x{33}\x{20}..." isn't numeric in negation (-) at -e line 1.
-3 μῆλα

This goes back to commit a43d94f2c089, which by itself looks perfectly
correct (I won’t quote the diff here, as it is long; but it doesn’t
touch pp_negate):

commit a43d94f2c089c6f14197795daeebb7835550a747
Author: Nicholas Clark <nick@ccl4.org>
Date:   Mon Jan 7 18:24:39 2008 +0000

    Don't set the public IV or NV flags if the string converted from has
    trailing garbage. This behaviour is consistent with not setting the
    public IV or NV flags if the value is out of range for the type.

    p4raw-id: //depot/perl@32894

It seems that pp_negate was already buggy before that (or ‘validly’
assumed that numeric coercion would set public flags).  And it looks
as though commit 8eb28a70b2e is at fault here.

It changed this:

$ perl5.6.2 -Mutf8 -lwe 'print -"ð"'
-ð

to this:

$ perl5.8.1 -Mutf8 -lwe 'print -"ð"'
Argument "\x{f0}" isn't numeric in negation (-) at -e line 1.
0

to comply with what happens when the UTF8 flag is not set.  But it was
relying on bugs in sv_2iv, etc.

So, from 5.8.0 to 5.10.0 inclusive, unary negation prepends "-" if the
string begins with [A-Za-z], but from 5.10.1 onwards it behaves diffe-
rently depending on the internal UTF8 flag (even prepending "-" to
ASCII-only strings like "%apples" if the UTF8 flag is on).

This commit restores the 5.8.0-5.10.0 behaviour, which was at least
self-consistent.