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

Re: [PATCH] Re: [perl #76814] FETCH called twice.

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
August 22, 2010 12:16
Subject:
Re: [PATCH] Re: [perl #76814] FETCH called twice.
Message ID:
771FC455-1D27-4115-8F76-8FF7B7DB3389@cpan.org

On Aug 19, 2010, at 8:09 AM, Abigail wrote:

> On Sun, Aug 01, 2010 at 12:14:52PM -0700, Father Chrysostomos wrote:
> 
> 
> Thank you for your patches.
> 
> 
>> • The first patch fixes string comparison operators. It changes sv_eq, sv_cmp, sv_cmp_locale and sv_collxfrm to _flags forms, with macros under the old names for sv_eq and sv_collxfrm, but functions for sv_cmp* since pp_sort.c needs them.
>> 
>> • The second patch fixes ! by doing the same thing to sv_2bool and adding SvTRUE_nomg. It also corrects the docs that state incorrectly that SvTRUE does not handle magic.
>> 
>> • The third patch fixes m and s. It modifies pp_regcomp to avoid extra magic. It also corrects a bug in sv_catsv_flags, which would still call mg_get(ssv) even without the SV_GMAGIC flag set.
>> 
>> • The fourth patch fixes y. (This has caused double magick at least as far back as 5.6.2.)
>> 
>> • The || case is not a bug, as there are two separate operators operating on it in the test script. In
>> 
>>  $dummy = $x || $y
>> 
>> The || does mg_get($x). If it’s true it returns it and the = does mg_get($x). If $x is false, then $y is returned, so magic is called once on each of $x and $y. Similarly, && will seemingly call mg_get($x) twice if $x is false.
>> 
>> If you just write:
>> 
>>  $x || $y
>> 
>> then magic is only called once on $x.
> 
> I don't understand why it's not a bug. If I do
> 
>    $dummy = f () || g ();
> 
> people would consider it to be a bug if f () were to be called twice. Why
> should $x be FETCHed twice then? In fact, IMO, if $x is tied, $x in
> rvalue context should just be a shorthand for C<< (tied $x) -> FETCH >>.

(Except that (tied $x)->FETCH doesn’t allow $_[0] assignment to change what the variable is tied too. :-)

Is it really rvalue context? Consider the following examples:

 $dummy = \($x || $y);
 $dummy = ${\($x || $y)};

Can you come up with a way to unify the concepts such that your test would work and my two examples would continue to work (oh, and ${\($a||$b)} = $c as well)?

In the mean time, is there any chance the first four patches could be applied?

> 
> 
>> The fifth patch attached hereto corrects the test.
>> 
>> • The sixth attachment is not a patch, but a text file of entries to be copied and pasted into perldelta, patches for which go stale too quickly.
>> 
>> Let’s see whether I remember the attachments....
>> 
> 
> 
> 
> Abigail


Thread Previous | Thread Next


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