Front page | perl.perl5.porters |
Postings from May 2007
Re: Should SvEND(sv) assert SvPOKp(sv)? (was Re: [PATCH] Math::BigInt::FastCalc v0.15)
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
May 29, 2007 15:57
Subject:
Re: Should SvEND(sv) assert SvPOKp(sv)? (was Re: [PATCH] Math::BigInt::FastCalc v0.15)
Message ID:
20070529225507.GP18077@plum.flirble.org
On Mon, May 28, 2007 at 11:44:32PM +0000, Tels wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Moin,
>
> On Monday 28 May 2007 20:19:34 Nicholas Clark wrote:
> > On Mon, May 28, 2007 at 02:02:34PM +0000, Tels wrote:
> > > SV = PVIV(0x9c7d20) at 0x786590
> > > REFCNT = 1
> > > FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
> > > IV = 0
> > > RV = 0xb16ac0
> > > PV = 0xb16ac0 ""
> > > CUR = 0
> > > LEN = 0
> > > Argument "\0\0" isn't numeric in numeric eq (==)
> > > at /usr/lib/perl5/5.8.8/Math/BigInt/Calc.pm line 304.
> > >
> > > Hm. So I should have checked for SvPOK() before accessing SvEND() I
> > > guess.
> >
> > Yes. Or, more correctly, I think, just not use it in the general case.
> >
> > I wondered whether SvEND() should assert that SvPOKp() is set.
>
> Well, if that catches bugs like mine, that would be good. OTOH, I am still
> unsure what my code should do with the given SV anyways. Would be SvCUR() +
> SvLEN() to access the end be even correct?
No, it wouldn't be correct.
I think that we need to document (more clearly, rather than implied) that
SvCUR() and SvLEN() and SvEND() are only valid if the scalar says it's
SvPOK(). Couple this with the fact that calling SvPV() doesn't guarantee
that a scalar will be SvPOK() afterwards, because it may be returning a
pointer to a temporary buffer, and it implies that for general scalar
handling, one should be using the pointer and length returned by SvPV(),
and doing end calculations using those, completely ignoring SvPVX(), SvCUR()
and SvEND()
(Oh, and check the value of SvUTF8() after calling SvPV(), not before.
As overloading can mean that the flag only becomes set correctly after the
first read)
> I cannot comment yet on that as I know not enough. Is my code buggy, or just
> right-for-certain-inputs? Can you explain this in a bit more details, esp.
> regarding the OVERLOAD flag.
Yes, it's buggy if it's using SvEND(). But happens to be right for (pretty
much) all the non-OVERLOAD cases
But I hadn't thought through this until your example.
Nicholas Clark
Thread Previous
|
Thread Next