Re: [perl #75676] PUSH on tied arrays

[email protected] (Nicholas Clark)
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Sat, Jun 12, 2010 at 12:54:05PM +0100, Dave Mitchell wrote:
> On Fri, Jun 11, 2010 at 06:37:56AM -0700, Nicholas Clark wrote:
> > 2: For push and unshift, the PP code ignores the return value of PUSH and
> >    UNSHIFT, and makes a (second) call to the tied object, FETCHSIZE.
> 
> Er, where does this happen? I can't see it, which means I'm probably
> misinterpreting something.

No, it means that my description was inadequate. I'd forgotten that I'd also
had to do a bit of chasing to figure out *why* it wasn't completely buggy and
simply returning the size of the underlying array. This code at the end of
pp_push:

    if (OP_GIMME(PL_op, 0) != G_VOID) {
	PUSHi( AvFILL(ary) + 1 );
    }


AvFILL expands to:

#define AvFILL(av)	((SvRMAGICAL((const SV *) (av))) \
			 ? mg_size(MUTABLE_SV(av)) : AvFILLp(av))


and for a tied array, SvRMAGICAL() is true, hence a call to mg_size() is made,
and that calls the FETCHSIZE method.

Nicholas Clark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.