Skip to content

Commit

Permalink
[perl #87708] $tied == $tied
Browse files Browse the repository at this point in the history
This is only part of #87708.

This fixes the + operator outside of any ‘use integer’ scope 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 it just worked.

I tried modifying pp_eq throughout to take this case into account,
but it made the most common cases slightly slower, presumably because
of the extra checks. So this follows the same temp sv method that I
used for pp_add (in 4c3ac4b and 837c879), which, though slowing down
this edge cases due to the extra allocation, leaves the most common
cases just as fast. (And, in case my benchmarks were unreliably [not
unlikely], this method is also safer, as it has less chance of getting
different code paths wrong.)
  • Loading branch information
Father Chrysostomos committed Apr 7, 2011
1 parent a778d1f commit 7d779b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
12 changes: 12 additions & 0 deletions pp_hot.c
Expand Up @@ -342,6 +342,18 @@ PP(pp_eq)
RETURN;
}
#endif
if (TOPs == TOPm1s && SvGMAGICAL(TOPs)) {
SV * const svl = sv_newmortal();
/* Print the uninitialized warning now, so it includes the vari-
able name. */
if (!SvOK(TOPs)) {
if (ckWARN(WARN_UNINITIALIZED)) report_uninit(TOPs);
sv_setiv(svl,0);
}
else sv_setsv_flags(svl, TOPs, 0);
SvGETMAGIC(TOPs);
TOPm1s = svl;
}
#ifdef PERL_PRESERVE_IVUV
SvIV_please_nomg(TOPs);
if (SvIOK(TOPs)) {
Expand Down
11 changes: 8 additions & 3 deletions t/lib/warnings/9uninit
Expand Up @@ -693,12 +693,17 @@ sub TIESCALAR{bless[]}
sub FETCH { undef }

tie my $m1, "";
my $v = $m1 + $m1;
my $v;
$v = $m1 + $m1;
$v = $m1 - $m1;
no warnings;
$v = $m1 + $m1;
$v = $m1 - $m1;
EXPECT
Use of uninitialized value $m1 in addition (+) at - line 6.
Use of uninitialized value $m1 in addition (+) at - line 6.
Use of uninitialized value $m1 in addition (+) at - line 7.
Use of uninitialized value $m1 in addition (+) at - line 7.
Use of uninitialized value $m1 in subtraction (-) at - line 8.
Use of uninitialized value $m1 in subtraction (-) at - line 8.
########
use warnings 'uninitialized';
my ($m1, $v);
Expand Down
5 changes: 1 addition & 4 deletions t/op/tie_fetch_count.t
Expand Up @@ -225,10 +225,7 @@ my $todo = 'bug #87708';
bin_test '|' , 1, 2, 3;
}
bin_test '.' , 1, 2, 12;
{
local $TODO = $todo ;
bin_test '==', 1, 2, "";
}
bin_test '==', 1, 2, "";
bin_test '+' , 1, 2, 3;
bin_int_test '*' , 2, 3, 6;
bin_int_test '/' , 10, 2, 5;
Expand Down

0 comments on commit 7d779b2

Please sign in to comment.