Vipul Ved Prakash on Mon, 18 Sep 2000 13:00:58 +0530 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Math::Pari segfaults? |
On Sun, Sep 17, 2000 at 03:57:47PM -0400, Ilya Zakharevich wrote: > This summer I have been debugging a similar problem. My conclusion was: > this is the problem sitting deeply in PARI semantic. Maybe your > problem is the same. > > PARI's Mod(a,b) may reference the b modulus in several ways, one of > them being that the object for Mod(a,b) just keeps the pointer to b. > *Without increasing the refcount of b* (there is no notion of refcount > in PARI!). The logic of Math::Pari is such that you cannot control > whether this way of storing the modulus is used. > > Corollary for Math::Pari: if you use $c = Mod($a,$b), $b should live > strictly longer than $b. > > [snip] Hi Ilya, After a few wild goose chases, I discovered the bug. makerandom_itv() (in Crypt::Random) was doing $c = Mod(0, $b-$a); -- this statement was triggering the segfault. I changed it $d = $b-$a; $c = Mod(0, $d); and now it seems to work fine. ($a,$b,$c,$d are Math::Pari objects.) While this seems to have something to do with PARI's non-existent refcounting mechanism, I don't understand exactly why $c = Mod(0, $b-$a) was breaking. I would appreciate if you could explain. best regards, vipul. -- VIPUL VED PRAKASH | Cryptography mail@vipul.net | Distributed Systems http://www.vipul.net | Network Agents 91 11 2233328 | Perl Hacking