in reply to Re^4: perl5.10 Devel::Size behaviour changed? (bug report)
in thread perl5.10 Devel::Size behaviour changed?

Any operation that queries the size does the same thing:

Not so.
>perl -MDevel::Peek -le"my @a = qw(a b c); print @a-1; Dump \@a,1" 2 SV = RV(0x238c60) at 0x238c54 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a22c SV = PVAV(0x239a4c) at 0x182a22c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x182521c FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL)

If it's a bug, it's not attributable to Devel::Size.

If it's a bug that reading $#a adds magic to @a, then that's not attributable to D::S.

The bug in D::S is that it should be using the method that doesn't add magic.

Replies are listed 'Best First'.
Re^6: perl5.10 Devel::Size behaviour changed? (bug report)
by BrowserUk (Patriarch) on Sep 04, 2009 at 19:29 UTC

    I see you removed the "rvalue" reference...

    Anyway, the code of D::S does this:

    if (AvMAX(thing) != -1) { /* an array with 10 slots has AvMax() set to 9 - te 2007-04-22 * +/ total_size += sizeof(SV *) * (AvMAX(thing) + 1);

    And AvMAX is defined as:

    #define AvMAX(av) ((XPVAV*) SvANY(av))->xav_max

    Ie. It simply gets the value from a struct member.

    It also references AvALLOC & AvARYLEN, but neither of those does anything with magic either:

    #define AvARRAY(av) ((av)->sv_u.svu_array) #define AvALLOC(av) (*((SV***)&((XPVAV*) SvANY(av))->xav_alloc)) #define AvMAX(av) ((XPVAV*) SvANY(av))->xav_max #define AvFILLp(av) ((XPVAV*) SvANY(av))->xav_fill #define AvARYLEN(av) (*Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)))

    The only "method" that touches magic is AvFILL:

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

    And AvFILL doesn't appear anywhere in the D::S source.

    So, I say again, the bug does not lie with D::S.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      D::S also uses AvARRAY, AvALLOC and AvARYLEN.

      use strict; use warnings; use Devel::Peek qw( Dump ); use Inline C => <<'__EOI__'; void call_AvMAX(AV* av) { AvMAX(av); } void call_AvARRAY(AV* av) { AvARRAY(av); } void call_AvALLOC(AV* av) { AvALLOC(av); } void call_AvARYLEN(AV* av) { AvARYLEN(av); } __EOI__ my @a = qw( a b c ); print("After init:\n"); Dump(\@a, 1); call_AvMAX(\@a); print("\nAfter AvMAX:\n"); Dump(\@a, 1); call_AvARRAY(\@a); print("\nAfter AvARRAY:\n"); Dump(\@a, 1); call_AvALLOC(\@a); print("\nAfter AvALLOC:\n"); Dump(\@a, 1); call_AvARYLEN(\@a); print("\nAfter AvARYLEN:\n"); Dump(\@a, 1);
      After init: SV = RV(0x238c18) at 0x238c0c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a68c SV = PVAV(0x2399f4) at 0x182a68c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x1824504 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) After AvMAX: SV = RV(0x238c18) at 0x238c0c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a68c SV = PVAV(0x2399f4) at 0x182a68c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x1824504 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) After AvARRAY: SV = RV(0x238c18) at 0x238c0c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a68c SV = PVAV(0x2399f4) at 0x182a68c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x1824504 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) After AvALLOC: SV = RV(0x238c18) at 0x238c0c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a68c SV = PVAV(0x2399f4) at 0x182a68c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x1824504 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) After AvARYLEN: SV = RV(0x238c18) at 0x238c0c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a68c SV = PVAV(0x2399f4) at 0x182a68c REFCNT = 2 FLAGS = (PADMY,RMG) MAGIC = 0x23fdbc MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED ARRAY = 0x1824504 FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL)

      So AvARYLEN is the culprit. In 5.10.1, AvARYLEN is defined as

      #define AvARYLEN(av) (*Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)))

      Sounds familiar.