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

[perl #76814] FETCH called twice

July 29, 2010 20:36
[perl #76814] FETCH called twice
Message ID:
# New Ticket Created by  Abigail 
# Please include the string:  [perl #76814]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.12.1.

[Please describe your issue here]

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;


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 <>   
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          

    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, <>.                                       

I'll write a couple of test cases for this and commit them.


[Please do not change anything below this line]
Site configuration information for perl 5.12.1:

Configured by abigail at Wed May 19 02:45:31 CEST 2010.

Summary of my perl5 (revision 5 version 12 subversion 1) configuration:
    osname=linux, osvers=2.6.11-1.1369_fc4smp, archname=i686-linux-64int-ld
    uname='linux almanda 2.6.11-1.1369_fc4smp #1 smp thu jun 2 23:08:39 edt 2005 i686 i686 i386 gnulinux '
    config_args='-des -Dusedevel -Uversiononly -Doptimize=-g -Dcc=gcc -Dprefix=/opt/perl -Dusemorebits'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.0.2 20051125 (Red Hat 4.0.2-8)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -g -L/usr/local/lib'

Locally applied patches:

@INC for perl 5.12.1:

Environment for perl 5.12.1:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About