develooper Front page | perl.perl5.porters | Postings from August 2010

Re: [perl.git] branch blead, updated. v5.13.4-15-gd88e091

From:
Jesse Vincent
Date:
August 20, 2010 16:29
Subject:
Re: [perl.git] branch blead, updated. v5.13.4-15-gd88e091
Message ID:
20100820232851.GW19167@fsck.bestpractical.com
I'm 95% offline this weekend, but +1 to backport for 5.12.2.


On Sat, Aug 21, 2010 at 01:23:38AM +0200, Jan Dubois wrote:
> In perl.git, the branch blead has been updated
> 
> <http://perl5.git.perl.org/perl.git/commitdiff/d88e091f660036722622a815efa9ef3779605ea6?hp=ecf9cdab78811498b3ffea48cfdfb09f678050d2>
> 
> - Log -----------------------------------------------------------------
> commit d88e091f660036722622a815efa9ef3779605ea6
> Author: Ben Morrow <ben@morrow.me.uk>
> Date:   Fri Aug 20 18:35:58 2010 +0100
> 
>     Fix my $x = 3; $x = length(undef);.
>     
>     Assignment of length() to a lexical is optimized by passing the
>     assigned-to variable as TARG, avoiding a pp_padsv and pp_sassign.
>     9f621b which changed length(undef) to return undef didn't take this into
>     account, and used SETs (which doesn't set TARG), so the code above left
>     $x == 3.
> -----------------------------------------------------------------------
> 
> Summary of changes:
>  pp.c          |    9 ++++++---
>  t/op/length.t |   17 ++++++++++++++++-
>  2 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/pp.c b/pp.c
> index 0da8bba..fcb7ff2 100644
> --- a/pp.c
> +++ b/pp.c
> @@ -3105,8 +3105,10 @@ PP(pp_length)
>  	    = sv_2pv_flags(sv, &len,
>  			   SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
>  
> -	if (!p)
> -	    SETs(&PL_sv_undef);
> +	if (!p) {
> +	    sv_setsv(TARG, &PL_sv_undef);
> +	    SETTARG;
> +	}
>  	else if (DO_UTF8(sv)) {
>  	    SETi(utf8_length((U8*)p, (U8*)p + len));
>  	}
> @@ -3119,7 +3121,8 @@ PP(pp_length)
>  	else
>  	    SETi(sv_len(sv));
>      } else {
> -	SETs(&PL_sv_undef);
> +	sv_setsv_nomg(TARG, &PL_sv_undef);
> +	SETTARG;
>      }
>      RETURN;
>  }
> diff --git a/t/op/length.t b/t/op/length.t
> index c73d4c5..705b9d5 100644
> --- a/t/op/length.t
> +++ b/t/op/length.t
> @@ -6,7 +6,7 @@ BEGIN {
>      @INC = '../lib';
>  }
>  
> -plan (tests => 30);
> +plan (tests => 36);
>  
>  print "not " unless length("")    == 0;
>  print "ok 1\n";
> @@ -193,6 +193,21 @@ my $uo = bless [], 'U';
>  
>  is(length($uo), undef, "Length of overloaded reference");
>  
> +my $ul = 3;
> +is(($ul = length(undef)), undef, 
> +                    "Returned length of undef with result in TARG");
> +is($ul, undef, "Assigned length of undef with result in TARG");
> +
> +$ul = 3;
> +is(($ul = length($u)), undef,
> +                "Returned length of tied undef with result in TARG");
> +is($ul, undef, "Assigned length of tied undef with result in TARG");
> +
> +$ul = 3;
> +is(($ul = length($uo)), undef,
> +                "Returned length of overloaded undef with result in TARG");
> +is($ul, undef, "Assigned length of overloaded undef with result in TARG");
> +
>  # ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
>  
>  is($warnings, 0, "There were no warnings");
> 
> --
> Perl5 Master Repository

-- 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About