From: Yitzchak Scott-Thoennes <sthoenna@efn.org>
Date: Fri, 2 Sep 2005 00:05:52 +0000 (-0700)
Subject: Re: Fw: Tied hash numeric values are rounded off under Perl v5.8.6
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2b77b520a897b2de1a476dfdd714900e49cf942b;p=p5sagit%2Fp5-mst-13.2.git

Re: Fw: Tied hash numeric values are rounded off under Perl v5.8.6
Message-ID: <20050902070552.GA3992@efn.org>

p4raw-id: //depot/perl@25358
---

diff --git a/mg.c b/mg.c
index 628afa0..d3a001a 100644
--- a/mg.c
+++ b/mg.c
@@ -2793,8 +2793,16 @@ S_restore_magic(pTHX_ const void *p)
 	    SvFLAGS(sv) |= mgs->mgs_flags;
 	else
 	    mg_magical(sv);
-	if (SvGMAGICAL(sv))
-	    SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
+	if (SvGMAGICAL(sv)) {
+	    /* downgrade public flags to private,
+	       and discard any other private flags */
+
+	    U32 public = SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK);
+	    if (public) {
+		SvFLAGS(sv) &= ~( public | SVp_IOK|SVp_NOK|SVp_POK );
+		SvFLAGS(sv) |= ( public << PRIVSHIFT );
+	    }
+	}
     }
 
     mgs->mgs_sv = NULL;  /* mark the MGS structure as restored */
diff --git a/t/op/tie.t b/t/op/tie.t
index 2ea1285..1fe37e1 100755
--- a/t/op/tie.t
+++ b/t/op/tie.t
@@ -571,3 +571,10 @@ FIRSTKEY
 not empty
 FIRSTKEY
 empty
+########
+sub TIESCALAR { bless {} }
+sub FETCH { my $x = 3.3; 1 if 0+$x; $x }
+tie $h, "main";
+print $h,"\n";
+EXPECT
+3.3