From c31c2913381bad74c5f1f5c67c4d9c6e037550ad Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 5 Apr 2011 21:39:01 -0700 Subject: [PATCH] [perl #87708] atan2 $tied, $tied 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 | 2 +- pp.h | 5 +++++ t/op/tie_fetch_count.t | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pp.c b/pp.c index 8b15b6e..9858f91 100644 --- 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 --- a/pp.h +++ b/pp.h @@ -370,6 +370,11 @@ Does not use C. See also C, C and C. #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) diff --git a/t/op/tie_fetch_count.t b/t/op/tie_fetch_count.t index 9ab77d9..a0e7491 100644 --- a/t/op/tie_fetch_count.t +++ b/t/op/tie_fetch_count.t @@ -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__ -- 2.7.4