Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math::BigInt gives completely when Math::BigInt::GMP is used #9405

Closed
p5pRT opened this issue Jul 5, 2008 · 9 comments
Closed

Math::BigInt gives completely when Math::BigInt::GMP is used #9405

p5pRT opened this issue Jul 5, 2008 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 5, 2008

Migrated from rt.perl.org#56608 (status was 'rejected')

Searchable as RT56608$

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

From pcg@goof.com

Created by pcg@goof.com

When Math​::BigInt uses GMP as backend, it gives completely bogus results​:

  perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m = Math​::BigInt->new (2) ** 24 - 1; warn $m + $b'
  -105689855 at -e line 1.

  perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m = Math​::BigInt->new (2) ** 32 - 1; warn $m + $b'
  3221291522 at -e line 1.

This only seems to happen with 32-bit perls.

Perl Info

Flags:
    category=library
    severity=low

Site configuration information for perl 5.10.0:

Configured by Marc Lehmann at Sat Jan 19 07:46:38 CET 2008.

Summary of my perl5 (revision 5 version 10 subversion 0 patch 33007) configuration:
  Platform:
    osname=linux, osvers=2.6.23-1-amd64, archname=amd64-linux
    uname='linux cerebro 2.6.23-1-amd64 #1 smp fri dec 21 12:00:17 utc 2007 x86_64 gnulinux '
    config_args='-Duselargefiles -Dxxxxuse64bitint -Uuse64bitall -Dusemymalloc=n -Dcc=gcc -Dccflags=-DPERL_DONT_CREATE_GVSV_disabled -ggdb -Dcppflags=-DPERL_DONT_CREATE_GVSV_disabled -D_GNU_SOURCE -I/opt/include -Doptimize=-O6 -march=opteron -mtune=opteron -funroll-loops -fno-strict-aliasing -Dcccdlflags=-fPIC -Dldflags=-L/opt/perl/lib -L/opt/lib -Dlibs=-ldl -lm -lcrypt -Darchname=amd64-linux -Dprefix=/opt/perl -Dprivlib=/opt/perl/lib/perl5 -Darchlib=/opt/perl/lib/perl5 -Dvendorprefix=/opt/perl -Dvendorlib=/opt/perl/lib/perl5 -Dvendorarch=/opt/perl/lib/perl5 -Dsiteprefix=/opt/perl -Dsitelib=/opt/perl/lib/perl5 -Dsitearch=/opt/perl/lib/perl5 -Dsitebin=/opt/perl/bin -Dman1dir=/opt/perl/man/man1 -Dman3dir=/opt/perl/man/man3 -Dsiteman1dir=/opt/perl/man/man1 -Dsiteman3dir=/opt/perl/man/man3 -Dman1ext=1 -Dman3ext=3 -Dpager=/usr/bin/less -Uafs -Uusesfio -Uusenm -Uuseshrplib -Dd_dosuid -Dusethreads=undef -Duse5005threads=undef -Duseithreads=undef -Dusemultiplicity=undef -Demail=perl-binary@plan9.de -Dcf_email=perl-binary@plan9.de -Dcf_by=Marc Lehmann -Dlocincpth=/opt/perl/include /opt/include -Dmyhostname=localhost -Dmultiarch=undef -Dbin=/opt/perl/bin -Dxxxusedevel -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-DPERL_DONT_CREATE_GVSV_disabled -ggdb -fno-strict-aliasing -pipe -I/opt/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O6 -march=opteron -mtune=opteron -funroll-loops -fno-strict-aliasing',
    cppflags='-DPERL_DONT_CREATE_GVSV_disabled -D_GNU_SOURCE -I/opt/include -DPERL_DONT_CREATE_GVSV_disabled -ggdb -fno-strict-aliasing -pipe -I/opt/include'
    ccversion='', gccversion='4.2.3 20080102 (prerelease) (Debian 4.2.2-5)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags ='-L/opt/perl/lib -L/opt/lib -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-ldl -lm -lcrypt
    perllibs=-ldl -lm -lcrypt
    libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O6 -march=opteron -mtune=opteron -funroll-loops -fno-strict-aliasing -L/opt/perl/lib -L/opt/lib -L/usr/local/lib'

Locally applied patches:
    MAINT


@INC for perl 5.10.0:
    /root/src/sex
    /opt/perl/lib/perl5
    /opt/perl/lib/perl5
    /opt/perl/lib/perl5
    /opt/perl/lib/perl5
    /opt/perl/lib/perl5
    .


Environment for perl 5.10.0:
    HOME=/root
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=de_DE.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/root/s2:/root/s:/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11/bin:/usr/games:/usr/local/bin:/usr/local/sbin:/root/pserv:.
    PERL5LIB=/root/src/sex
    PERL5_CPANPLUS_CONFIG=/root/.cpanplus/config
    PERLDB_OPTS=ornaments=0
    PERL_ANYEVENT_EDNS0=1
    PERL_ANYEVENT_PROTOCOLS=ipv4
    PERL_BADLANG (unset)
    PERL_UNICODE=0
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

From p5p@perl.wizbit.be

Citeren Marc Lehmann <perlbug-followup@​perl.org>​:

-----------------------------------------------------------------
[Please enter your report here]

When Math​::BigInt uses GMP as backend, it gives completely bogus results​:

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 24 - 1; warn $m + $b'
-105689855 at -e line 1.

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 32 - 1; warn $m + $b'
3221291522 at -e line 1.

This only seems to happen with 32-bit perls.

[Please do not change anything below this line]
-----------------------------------------------------------------

Can you run​:

perl -MMath​::BigInt=lib,GMP -Mbignum=version

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

From nospam-abuse@bloodgate.com

On Saturday 05 July 2008 10​:28​:54 Bram wrote​:

Citeren Marc Lehmann <perlbug-followup@​perl.org>​:

-----------------------------------------------------------------
[Please enter your report here]

When Math​::BigInt uses GMP as backend, it gives completely bogus
results​:

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 24 - 1; warn $m + $b'
-105689855 at -e line 1.

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 32 - 1; warn $m + $b'
3221291522 at -e line 1.

This only seems to happen with 32-bit perls.

I am pretty sure that is because the value is in-between treated as
signed vs. unsigned integer and thus arrives wrongly in libgmp.

Can you please run​:

  perl -Mbignum,l,GMP=v

?

All the best,

Tels

--
Signed on Sat Jul 5 10​:50​:08 2008 with key 0x93B84C15.
View my photo gallery​: http​://bloodgate.com/photos
PGP key on http​://bloodgate.com/tels.asc or per email.

"Un bon mot ne prouve rien."

  -- Voltaire

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

From nospam-abuse@bloodgate.com

On Saturday 05 July 2008 10​:50​:59 you wrote​:

On Saturday 05 July 2008 10​:28​:54 Bram wrote​:

Citeren Marc Lehmann <perlbug-followup@​perl.org>​:

-----------------------------------------------------------------
[Please enter your report here]

When Math​::BigInt uses GMP as backend, it gives completely bogus
results​:

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 24 - 1; warn $m + $b'
-105689855 at -e line 1.

perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m =
Math​::BigInt->new (2) ** 32 - 1; warn $m + $b'
3221291522 at -e line 1.

This only seems to happen with 32-bit perls.

I am pretty sure that is because the value is in-between treated as
signed vs. unsigned integer and thus arrives wrongly in libgmp.

Can you please run​:

perl \-Mbignum\,l\,GMP=v

Sorry,

  perl -Mbignum=l,GMP,v

But I think I found the bug, GMP,xs contains​:

  if (SvUOK(x))
  {
  mpz_init_set_si(*RETVAL, (UV)SvUV(x));
  }
  else
  {
  ...

That should probably be​:

  if (SvUOK(x))
  {
  mpz_init_set_ui(*RETVAL, (UV)SvUV(x)); // _ui to fix [perl #56608]
  }
  else
  {
  ...

Marc, could you please patch, recompile and test with this and see if it
resolves it? I only have a 64bit Perl on this machine.

All the best,

Tels

--
Signed on Sat Jul 5 10​:54​:34 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.

"In my opiniation, "burglarize" is a perfectionally validative
wordification. How else would reportization of the securitial/policial
forceship appearize to be importantive enoughly to be respectative by
the massmediaship and influentate the societyness?"

  -- SharpFang (651121) on 2004-12-13 at /. about "burgle"
vs. "burglarize"

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2008

From kraai@ftbfs.org

Howdy,

I was able to reproduce the original problem on my system and, after
making the change suggested by Tels, found that the commands produced
the following output​:

$ perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m = Math​::BigInt->new (2) ** 24 - 1; warn $m + $b'
3238068738 at -e line 1.
$ perl -MMath​::BigInt=lib,GMP -e 'my $b = 0xc0010203; my $m = Math​::BigInt->new (2) ** 32 - 1; warn $m + $b'
7516258818 at -e line 1.

These match the results produced by bc.

Here's the output requested by Bram​:

$ perl -MMath​::BigInt=lib,GMP -Mbignum=version
bignum v0.23
Math​::BigInt v1.89 lib => Math​::BigInt​::GMP v1.24
Math​::BigFloat v1.60

The output requested by Tels was the same.

--
Matt http​://ftbfs.org/

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2014

From dana@acm.org

Just to make the connection, this is in Math​::BigInt​::GMP's queue as RT 71548, and still open.

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2016

From @dcollinsn

On Sun Mar 02 22​:53​:47 2014, danaj wrote​:

Just to make the connection, this is in Math​::BigInt​::GMP's queue as
RT 71548, and still open.

In that ticket, which is still open, the maintainer reports that Math-BigInt-GMP-1.46 has been uploaded, which fixes this bug.

In any event, Math​::BigInt​::GMP is not a core module, so this should be closed rejected. Please visit https://rt.cpan.org/Public/Bug/Display.html?id=71548 for further discussion related to this issue. (In particular, if this is confirmed fixed on a system that was previously broken, please report this there, so that the maintainer knows that they can close that ticket.)

--
Respectfully,
Dan Collins

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2016

@dcollinsn - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant