[perl #87708] atan2 $tied, $tied
authorFather Chrysostomos <sprout@cpan.org>
Wed, 6 Apr 2011 04:39:01 +0000 (21:39 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 6 Apr 2011 05:21:01 +0000 (22:21 -0700)
This fixes atan2 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, the operands
would be reversed.

pp.c
pp.h
t/op/tie_fetch_count.t

diff --git a/pp.c b/pp.c
index 8b15b6e..9858f91 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3082,7 +3082,7 @@ PP(pp_atan2)
     dVAR; dSP; dTARGET;
     tryAMAGICbin_MG(atan2_amg, 0);
     {
-      dPOPTOPnnrl_nomg;
+      dPOPTOPnnrl_halfmg;
       SETn(Perl_atan2(left, right));
       RETURN;
     }
diff --git a/pp.h b/pp.h
index 6903069..eef6a0b 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -370,6 +370,11 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
 #define dPOPTOPnnrl_nomg \
     NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
+#ifdef PERL_CORE
+# define dPOPTOPnnrl_halfmg \
+    NV left  = SvNV_nomg(TOPm1s); \
+    NV right = TOPs == TOPm1s ? SvNV(TOPs) : SvNV_nomg(TOPs); sp--
+#endif
 #define dPOPTOPiirl    dPOPXiirl(TOP)
 #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
 #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
index 9ab77d9..a0e7491 100644 (file)
@@ -252,9 +252,9 @@ bin_test '.' ,  1, 2, 12;
     bin_int_test '==',  1, 2, "";
     bin_int_test '!=',  1, 2, 1;
     bin_int_test '<=>', 1, 2, -1;
-    tie $var, "main", 1, 4;
-    cmp_ok(atan2($var, $var), '<', .3, 'retval of atan2 $var, $var');
-    check_count 'atan2',  2;
 }
+tie $var, "main", 1, 4;
+cmp_ok(atan2($var, $var), '<', .3, 'retval of atan2 $var, $var');
+check_count 'atan2',  2;
 
 __DATA__