[perl #87708] $tied + $tied and $tied - $tied under ‘use integer’
authorFather Chrysostomos <sprout@cpan.org>
Wed, 6 Apr 2011 19:40:44 +0000 (12:40 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 6 Apr 2011 19:40:44 +0000 (12:40 -0700)
This is just part of #87708.

This fixes + and - under ‘use integer’ when the same tied scalar is
used for both operands and returns two different values. Before this
commit, get-magic would be called only once and the same value used.
In 5.12.x + just worked but the operands were swapped for -.

pp.h
t/lib/warnings/9uninit
t/op/tie_fetch_count.t

diff --git a/pp.h b/pp.h
index e676e04..80ebfe6 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -355,9 +355,10 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
     SV *leftsv = CAT2(X,s);                            \
     IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
 #define dPOPXiirl_ul_nomg(X) \
-    IV right = POPi;                                   \
+    SV *rightsv = POPs;                                        \
     SV *leftsv = CAT2(X,s);                            \
-    IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
+    IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0;        \
+    IV right = SvIV(rightsv)
 
 #define dPOPPOPssrl    dPOPXssrl(POP)
 #define dPOPPOPnnrl    dPOPXnnrl(POP)
index 7dfeb7b..d634846 100644 (file)
@@ -556,10 +556,10 @@ $v = $m1 != $g1;
 $v = $m1 <=> $g1;
 $v = -$m1;
 EXPECT
-Use of uninitialized value $g1 in integer addition (+) at - line 6.
 Use of uninitialized value $m1 in integer addition (+) at - line 6.
-Use of uninitialized value $g1 in integer subtraction (-) at - line 7.
+Use of uninitialized value $g1 in integer addition (+) at - line 6.
 Use of uninitialized value $m1 in integer subtraction (-) at - line 7.
+Use of uninitialized value $g1 in integer subtraction (-) at - line 7.
 Use of uninitialized value $g1 in integer multiplication (*) at - line 8.
 Use of uninitialized value $m1 in integer multiplication (*) at - line 8.
 Use of uninitialized value $g1 in integer division (/) at - line 9.
index d0a3b62..79c9015 100644 (file)
@@ -232,20 +232,9 @@ bin_test '.' ,  1, 2, 12;
     bin_int_test '*' ,  2, 3, 6;
     bin_int_test '/' , 10, 2, 5;
     bin_int_test '%' , 11, 2, 1;
-    # For these two, one of the tests in bin_int_test passes and the other
-    # fails, so we spell them out for now.
-    #bin_int_test '+' ,  1, 2, 3;
-    #bin_int_test '-' , 11, 2, 9;
-    {
-        use integer;
-        tie my $var, "main", 1, 2;
-        is($var + $var, 3, 'retval of $var + $var under use integer');
-        { local $TODO; check_count '+ under use integer',  2; }
-        tie $var, "main", 11, 2;
-        is($var - $var, 9, 'retval of $var - $var under use integer');
-        { local $TODO; check_count '- under use integer',  2; }
-    }
 }
+bin_int_test '+' ,  1, 2, 3;
+bin_int_test '-' , 11, 2, 9;
 bin_int_test '<' ,  1, 2, 1;
 bin_int_test '>' , 44, 2, 1;
 bin_int_test '<=', 44, 2, "";