develooper Front page | perl.perl5.porters | Postings from May 2007

Re: [PATCH] Math::BigInt::FastCalc v0.15

Thread Previous | Thread Next
From:
Tels
Date:
May 28, 2007 05:16
Subject:
Re: [PATCH] Math::BigInt::FastCalc v0.15
Message ID:
200705281402.41683@bloodgate.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Moin,

On Monday 28 May 2007 09:57:27 Nicholas Clark wrote:
> On Sun, May 27, 2007 at 02:43:15PM +0000, Tels wrote:
> > Another oddity I noticed is that for magic strings (like matches coming
> > out of the regexp engine), the following failed under v5.8.8:
> >
> >       SvPV(x, len);	/* convert to string & store length */
> >       cur = SvEND(x);	/* points to \0 instead */
> >
> > This solves it:
> >
> >       cur = SvPV(x, len);	/* convert to string & store length */
> >       cur += len;
> >
> > However, I am not sure is this a bug in Perl or just my poor
> > understanding of XS.
>
> I don't know for sure, either.
> If you add
>
>    sv_dump(x);
>
> at that point, what is the dump output for one of the magic strings?

Oh, this problem can only be reproduced if I put in the code that caused 
parts inside Calc to get BigInts (so it doesn't happen in the normal 
FastCalc testsuite). But with that code, the follow perl snipped triggers 
it:

	use Math::BigFloat;
	$x = Math::BigFloat->new('0.008'); $y = Math::BigFloat->new(29);
	$x->bdiv(3,$y);

And this:

      end = SvPV(x, len);
      end += len;
      cur = SvEND(x);
      if (end != cur)
        {
        printf ("end: %p, cur: %p\n", cur, end);
        sv_dump(x);
        }

produces this:

	# perl -Ilib -Iblib/arch t.pl
	end: 0xb16ac0, cur: 0x669a32
	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 addition (+)
	 at /usr/lib/perl5/5.8.8/Math/BigInt/Calc.pm line 281.
	end: 0xb16ac0, cur: 0x669a12
	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. 
OTOH, how is my XS code supposed to handle an overloaded string, anyway?

Best wishes,

Tels


- -- 
 Signed on Mon May 28 13:55:41 2007 with key 0x93B84C15.
 View my photo gallery: http://bloodgate.com/photos
 PGP key on http://bloodgate.com/tels.asc or per email.

 "Call me Justin, Justin Case."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iQEVAwUBRlrhAXcLPEOTuEwVAQKpLgf7BBeGOQhjmA2NcDixev2WIy6gaD06CdK+
k45z+bd3n64TMwCqMaKb1X+cC9Pw8bE/Fdlwf4JWLNgvBbVN5Tr8IVTcecKHQNqA
WvWc/o+lTCa27BUSRWUklkaxlCZRd8K14ME0qGlHN50rXAwO6dO3HT3ZCMI9Zg4E
tD72tNeN1nutZKQPBI5cgswF6TgZKz7YNbhtvfSvKOZC8NEjDgy1e2ugS1jQREg+
ReiaCeXaWIjLVx/r1VT1QFFQcVJpa24iE4O0U9R+dLlz3Uc+vjRdeFiMU09KAlpm
ZwMQSg37RMu13oxpc4IXZs5sOXdbgNzR1rdE6d/sKc5Bxt66Bx/TXA==
=qzWc
-----END PGP SIGNATURE-----

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About