From: Simon Cozens Date: Sun, 22 Apr 2001 18:47:25 +0000 (+0100) Subject: Re: [ID 20010422.003] Core dump in overloaded bool while using ' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1dc13c174ce1e7042058992973b5cae87df5d46d;p=p5sagit%2Fp5-mst-13.2.git Re: [ID 20010422.003] Core dump in overloaded bool while using ' Message-ID: <20010422184725.A14411@netthink.co.uk> p4raw-id: //depot/perl@9782 --- diff --git a/sv.c b/sv.c index 5778adb..5ce8a1a 100644 --- a/sv.c +++ b/sv.c @@ -1730,7 +1730,7 @@ Perl_sv_2iv(pTHX_ register SV *sv) if (SvROK(sv)) { SV* tmpstr; if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)) && - (SvRV(tmpstr) != SvRV(sv))) + (SvTYPE(tmpstr) != SVt_RV || (SvRV(tmpstr) != SvRV(sv)))) return SvIV(tmpstr); return PTR2IV(SvRV(sv)); } @@ -1984,7 +1984,7 @@ Perl_sv_2uv(pTHX_ register SV *sv) if (SvROK(sv)) { SV* tmpstr; if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)) && - (SvRV(tmpstr) != SvRV(sv))) + (SvTYPE(tmpstr) != SVt_RV || (SvRV(tmpstr) != SvRV(sv)))) return SvUV(tmpstr); return PTR2UV(SvRV(sv)); } @@ -2268,7 +2268,7 @@ Perl_sv_2nv(pTHX_ register SV *sv) if (SvROK(sv)) { SV* tmpstr; if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)) && - (SvRV(tmpstr) != SvRV(sv))) + (SvTYPE(tmpstr) != SVt_RV || (SvRV(tmpstr) != SvRV(sv)))) return SvNV(tmpstr); return PTR2NV(SvRV(sv)); } @@ -2684,7 +2684,7 @@ Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp) if (SvROK(sv)) { SV* tmpstr; if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)) && - (SvRV(tmpstr) != SvRV(sv))) + (SvTYPE(tmpstr) != SVt_RV || (SvRV(tmpstr) != SvRV(sv)))) return SvPV(tmpstr,*lp); sv = (SV*)SvRV(sv); if (!sv) @@ -2924,7 +2924,7 @@ Perl_sv_2bool(pTHX_ register SV *sv) if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv,bool_)) && - (SvRV(tmpsv) != SvRV(sv))) + (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; } diff --git a/t/pragma/overload.t b/t/pragma/overload.t index 2cf937b..86ac857 100755 --- a/t/pragma/overload.t +++ b/t/pragma/overload.t @@ -1016,7 +1016,35 @@ unless ($aaa) { main::test($x+0 =~ /Recurse=ARRAY/); # 221 } +# BugID 20010422.003 +package Foo; + +use overload + 'bool' => sub { return !$_[0]->is_zero() || undef; } +; + +sub is_zero + { + my $self = shift; + return $self->{var} == 0; + } + +sub new + { + my $class = shift; + my $self = {}; + $self->{var} = shift; + bless $self,$class; + } + +package main; + +use strict; + +my $r = Foo->new(8); +$r = Foo->new(0); +test(($r || 0) == 0); # 221 # Last test is: sub last {221}