On Tue, Jun 07, 2005 at 11:15:03AM +0200, Rafael Garcia-Suarez wrote:
> Yitzchak Scott-Thoennes wrote:
> > 
> > How do you feel about this:
> > 
> > --- perl/av.c.orig      2005-06-02 01:07:41.000000000 -0700
> > +++ perl/av.c   2005-06-06 02:05:04.853572800 -0700
> > @@ -927,8 +927,8 @@ Perl_av_exists(pTHX_ AV *av, I32 key)
> >             return FALSE;
> >      }
> >  
> > -    if (key <= AvFILLp(av) && AvARRAY(av)[key] != &PL_sv_undef
> > -       && AvARRAY(av)[key])
> > +    if (key <= AvFILLp(av) && AvARRAY(av)[key]
> > +        && (AvARRAY(av)[key] != &PL_sv_undef || ! AvREAL(av)))
> >      {
> >         return TRUE;
> >      }
> > 
> > which should make exists true for any parameter actually passed, so
> > long as @_ isn't reified.
> 
> I don't like it. It doesn't solve the whole problem but only reduces
> the set of cases where weird behaviour is observed, making this weird
> behaviour perhaps more obscure and less predictable.

I agree with the sentiment, but think it would be worth it (perhaps in
conjuction with a short warning in perlfunc/exists that exists on @_
or @DB::args may not work).

The only complete fix I see would be to also make av_reify replace all
PL_sv_undefs with new sv's, something like (untested):

--- perl/av.c.orig      2005-06-02 01:07:41.000000000 -0700
+++ perl/av.c   2005-06-07 16:25:15.358164800 -0700
@@ -40,6 +40,8 @@ Perl_av_reify(pTHX_ AV *av)
        assert(sv);
        if (sv != &PL_sv_undef)
            (void)SvREFCNT_inc(sv);
+       else
+            AvARRAY(av)[key] = newSV(0);
     }
     key = AvARRAY(av) - AvALLOC(av);
     while (key)

This doesn't seem like too awful a penalty to pay for making exists()
work consistently.

Unless there's something that can be done to pp_entersub (probably too
expensive) or pp_undef (don't know the repercussions of this).

Reply via email to