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

FETCH called twice.

Thread Next
From:
Abigail
Date:
July 27, 2010 14:41
Subject:
FETCH called twice.
Message ID:
20100727214219.GA3850@almanda

A couple of my CPAN modules broke recently, due to FETCH, under certain
conditions, being called twice. 

This is a reduced test case:

    use 5.010;
    use strict;
    use warnings;
    
    my $count;

    sub TIESCALAR {bless []}
    sub FETCH {$count ++; 1}

    tie my $foo => "main";

    {no warnings 'void'; $foo eq 'foo';}

    say $count;

    __END__

This should print '1'. However, with blead, it prints 2.

git bisect tells commit 6f1401dc2acd2a2b85df22b0a74e5f7e6e0a33aa is the
culprit. This is the commit entry:

commit 6f1401dc2acd2a2b85df22b0a74e5f7e6e0a33aa
Author: David Mitchell <davem@iabyn.com>
Date:   Fri May 21 14:18:21 2010 +0100

    make overload respect get magic
    
    In most places, ops checked their args for overload *before* doing
    mg_get(). This meant that, among other issues, tied vars that
    returned overloaded objects wouldn't trigger calling the
    overloaded method.  (Actually, for tied and arrays and hashes, it
    still often would since mg_get gets called beforehand in rvalue
    context).
    
    This patch does the following:
    
    Makes sure get magic is called first.
    
    Moves most of the overload code formerly included by macros at the
    start of each pp function into the separate helper functions
    Perl_try_amagic_bin, Perl_try_amagic_un, S_try_amagic_ftest,
    with 3 new wrapper macros:
    tryAMAGICbin_MG, tryAMAGICun_MG, tryAMAGICftest_MG.
    This made the code 3800 bytes smaller.
    
    Makes sure that FETCH is not called multiple times. Much of this
    bit was helped by some earlier work from Father Chrysostomos.
    
    Added new functions and macros sv_inc_nomg(), sv_dec_nomg(),
    dPOPnv_nomg, dPOPXiirl_ul_nomg, dPOPTOPnnrl_nomg, dPOPTOPiirl_ul_nomg
    dPOPTOPiirl_nomg, SvIV_please_nomg, SvNV_nomg (again, some of
    these were based on Father Chrysostomos's work).
    
    Fixed the list version of the repeat operator (x): it now only
    calls overloaded methods for the scalar version:
        (1,2,$overloaded) x 10
    
    The only thing I haven't checked/fixed yet is overloading the
    iterator operator, <>.



Abigail

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