Skip Menu |

This queue is for tickets about the Math-BigInt-FastCalc CPAN distribution.

Report information
The Basics
Id: 35162
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Math-BigInt-FastCalc

People
Owner: TELS [...] cpan.org
Requestors: ambrus [...] math.bme.hu
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.19
Fixed in: (no value)



CC: Richard <vzshzn [...] gmail.com>
Subject: Re: MBI segfault
Date: Thu, 17 Apr 2008 20:35:17 +0200
To: bug-Math-BigInt-FastCalc [...] rt.cpan.org
From: "Zsbán Ambrus" <ambrus [...] math.bme.hu>
Hi, The following command causes a segmentation fault on my perl 5.10.0 on i686 linux: perl -wE 'use Math::BigRat "lib", "FastCalc"; use Math::BigFloat "lib", "FastCalc"; say Math::BigFloat->as_number(Math::BigRat->new("10/7"));' This code is clearly wrong: the as_number method is called with parameters I shouldn't give to it. However, I believe it still shoudn't result in a segfault, but either die or give some result. This is especially true because FastCalc is now the default engine for MBI. At least two other people have confirmed that this command segfaults on their machine too. I couldn't reproduce the bug with perl 5.8.8. Zshzn has kindly volunteered to look in this segfault with a debugger. He says the following. On Wed, Apr 16, 2008 at 10:52 PM, Richard <vzshzn@gmail.com> wrote: Show quoted text
> Here's what I've found out about your > segfault: > > It happens in _copy of FastCalc.xs, which is called from BigFloat.pm's > as_number at about line 3642. > > as_number tries to _copy $x->{_m}, which is undef. I assume the undefness of > the situation causes the problem :p > > I would get more accurate info but by recompiling FastCalc the problem went > away. Maybe it has already been fixed, at least on one end.
Here are some details about my installation. [am]king ~/a/tmp$ perl -wE 'use Math::BigRat "lib", "FastCalc"; use Math::BigFloat "lib", "FastCalc"; say Math::BigFloat->as_number(Math::BigRat->new("10/7"));' Segmentation fault 139[am]king ~/a/tmp$ perl -V Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Platform: osname=linux, osvers=2.6.20.6, archname=i686-linux uname='linux king 2.6.20.6 #3 smp tue may 29 09:42:52 cest 2007 i686 gnulinux ' config_args='' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.1.1', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/lib64 libs=-lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.3.6.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.6' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO Built under linux Compiled at Dec 18 2007 19:48:06 @INC: /usr/local/lib/perl5/5.10.0/i686-linux /usr/local/lib/perl5/5.10.0 /usr/local/lib/perl5/site_perl/5.10.0/i686-linux /usr/local/lib/perl5/site_perl/5.10.0 /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl . [am]king ~/a/tmp$ perl -wE 'use Math::BigInt; say $Math::BigInt::VERSION;' # this is the version that comes with perl 5.10.0 1.88 [am]king ~/a/tmp$ perl -wE 'use Math::BigRat; say $Math::BigRat::VERSION;' # this one is updated though 0.22 [am]king ~/a/tmp$ perl -wE 'use Math::BigInt::FastCalc; say $Math::BigInt::FastCalc::VERSION;' 0.19 Incidentally, thanks for the new as_float method in Math::BigRat, it's just what I'd have needed for a program I wrote two months ago. Ambrus
Subject: Re: [rt.cpan.org #35162] Re: MBI segfault
Date: Thu, 17 Apr 2008 21:27:03 +0200
To: bug-Math-BigInt-FastCalc [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
Hello, On Thursday 17 April 2008 20:35:42 ambrus@math.bme.hu via RT wrote: Show quoted text
> Thu Apr 17 14:35:40 2008: Request 35162 was acted upon. > Transaction: Ticket created by ambrus@math.bme.hu > Queue: Math-BigInt-FastCalc > Subject: Re: MBI segfault > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: ambrus@math.bme.hu > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35162 > > > > Hi, > > The following command causes a segmentation fault on my perl 5.10.0 > on i686 linux: > > perl -wE 'use Math::BigRat "lib", "FastCalc"; use Math::BigFloat > "lib", "FastCalc"; say > Math::BigFloat->as_number(Math::BigRat->new("10/7"));'
[snip] It seems you use the BigInt from v5.10.0 and updated to the new FastCalc, so I will need a bit of time to track things down and check what actually happens. But it shouldn't segfault :) Thanx for the report! Show quoted text
> Incidentally, thanks for the new as_float method in Math::BigRat, > it's just what I'd have needed for a program I wrote two months ago.
Oh wow, coincidence, I just needed it for something and thought it might be useful. :) There are not many users of BigRat (or even BigFloat and BigInts) and I get basically zero feedback so I always add stuff when I think of it :) All the best, Tels -- Signed on Thu Apr 17 21:24:41 2008 with key 0x93B84C15. Get one of my photo posters: http://bloodgate.com/posters PGP key on http://bloodgate.com/tels.asc or per email. "I can confirm this experimentally. Inspired by this development, I implanted electrodes into a bowl of tomato soup. No amount of deep electrical stimulation could bring the soup into anything we could recognize as consciousness, nor was its ability to communicate improved. Possibly the failure of the deep electrical stimulation to elicit the desired response has something to do with the vegetative state of the tomatoes that were used to make the soup. With this in mind, I am going to be conducting further experiments using a crab bisque." -- Ohreally_factor (593551) on 2007-08-05 on /. (#20119773)
Download (untitled)
application/pgp-signature 481b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #35162] MBI segfault
Date: Fri, 18 Apr 2008 08:18:09 +0200
To: bug-Math-BigInt-FastCalc [...] rt.cpan.org
From: "Zsbán Ambrus" <ambrus [...] math.bme.hu>
On Thu, Apr 17, 2008 at 9:28 PM, nospam-abuse@bloodgate.com via RT <bug-Math-BigInt-FastCalc@rt.cpan.org> wrote: Show quoted text
> It seems you use the BigInt from v5.10.0 and updated to the new > FastCalc, so I will need a bit of time to track things down and check > what actually happens. But it shouldn't segfault :)
That's what the cpan shell wants to do because the BigInt that comes with perl 5.10.0 has the same version number (1.88) as the new one on cpan. Ambrus
Subject: Re: [rt.cpan.org #35162] MBI segfault
Date: Fri, 18 Apr 2008 18:27:05 +0200
To: bug-Math-BigInt-FastCalc [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
On Friday 18 April 2008 08:18:26 ambrus@math.bme.hu via RT wrote: Show quoted text
> Queue: Math-BigInt-FastCalc > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35162 > > > On Thu, Apr 17, 2008 at 9:28 PM, nospam-abuse@bloodgate.com via RT > > <bug-Math-BigInt-FastCalc@rt.cpan.org> wrote:
> > It seems you use the BigInt from v5.10.0 and updated to the new > > FastCalc, so I will need a bit of time to track things down and > > check what actually happens. But it shouldn't segfault :)
> > That's what the cpan shell wants to do because the BigInt that comes > with perl 5.10.0 has the same version number (1.88) as the new one on > cpan.
It shouldn't really matter as both versions should be indeed identical in code. All the best, Tels -- Signed on Fri Apr 18 18:26:36 2008 with key 0x93B84C15. Get one of my photo posters: http://bloodgate.com/posters PGP key on http://bloodgate.com/tels.asc or per email. "My name is Felicity Shagwell. Shagwell by name, shag very well by reputation."
Download (untitled)
application/pgp-signature 481b

Message body not shown because it is not plain text.

After looking into this issue, I noted that simple Math::BigFloat cannot handle being passed a Math::BigRat object. Of course I can have a look and find out why Math::BigInt::FastCalc segfaults, but I don't think I can do much sensible things in its codebase - after all, calling it with the wrong parameters won't ever get a correct result :) And since adding all the checks for wrong parameters (just to catch wrong calling styles in code above) would slow everything down, I fixed Math::BigFloat instead by doing the right thing when getting a non-Math::BigFloat object (which a BigRat is): # perl -Ilib -wle 'use Math::BigRat "lib", "FastCalc"; use Math::BigFloat "lib", "FastCalc"; print Math::BigFloat->as_number(Math::BigRat->new("120/7"));' 17 The fix will be in Math::BigInt v1.89. To force people to upgrade, I will also add a requirement for v1.89 in Math::BigInt::FastCalc v0.20 when I release it. If this doesn't solve your issue, or you have any comments, please reply to this bug report to re-open it. Thank you for your report! Tels