Bill Allombert on Wed, 28 Nov 2012 13:25:43 +0100

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: when pari_init() fail

On Wed, Nov 28, 2012 at 05:37:28PM +0900, Iwao Kimura wrote:
> Hi all,
> The following short code is compiled normaly but it fails when invoked:
> /* zzpari.c */
> #include <pari/pari.h>
> int
> main (void)
> {
>   pari_init(10000, 2);
>   return 0;
> }
> $ gcc -o zzpari-dyn zzpari.c -O3 -mtune=native -g -Wall
> -fno-strict-aliasing -fomit-frame-pointer
>  -I /home/iwao/include -L/home/iwao/lib -Wl,-rpath "/home/iwao/lib" -lpari
> -lgmp -lm
> $ ./zzpari-dyn
>   ***   bug in PARI/GP (Segmentation Fault), please report.
>   ***   Error in the PARI system. End of program.
> The code is 'git pull'ed today.
> I found the reason why this happen by some hours investigation,
> the first argument of pari_init() is too small.
> But I wonder this behavior is intended one or not.

No, it is a bug. In pari_init_opts(), the call to
initprimetable() happens too soon. It shoud at least
be after init_universal_constants() so that 
err_e_STACK is defined.

With that change, one get:
  ***   the PARI stack overflows !
  current stack size: 10000 (0.010 Mbytes)
  [hint] you can increase GP stack with allocatemem()

  ***   Error in the PARI system. End of program.

Whether this one is intended or not is another story.
(This is due to commit 496549f714f3).
In practice, the prime table is computed at least up to
65309, which need about 40000 bytes of stack (on 64bit).