Karim BELABAS on Mon, 22 Jan 2001 14:34:33 +0100 (MET)

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

Re: Re. Strangely modified variables

> Many thanks, Gerhard, for pointing me in the right direction. The problem
> turned out to be a stack fault as you suspected. Interestingly, it was
> caused by GEN P not being initialised. Obviously, the GENs must be defined
> before the stack is initialised , so the pointers begin life pointing to
> some miscellaneous part of memory.
> My first assignment to P was with stoi (l), where l is a long, initialised
> to 0. For some reason, P = stoi (0) doesn't return a value within the PARI
> stack, so P continues to point into space! Simply initialising l with 1
> instead, solved the problem.

The pari 'stack' is a large scratchspace created by the command pari_init().
[most PARI command will segfault if called _before_ stack is initiallized]
This is wiped out periodically.

A number of miscellaneous PARI objects are _permanent_ and don't belong to
this stack (manual calls this the 'heap'). The integer 0 is one of them. It is
the constant "gzero" and points to a chunk of memory (universal constants)
malloced and initialized in pari_init (will never be modified by any of the
PARI functions).

stoi(0) just returns this constant pointer gzero, pointing to constant data in
the heap. Although you apparently solved your problem, I doubt the
interpretation is accurate.

Try adding a number of debugging comments as suggested by Gerhard in your
original program, of the form:

   fprintferr("gzero is %08lx = %Z", gzero, gzero);
   fprintferr("P     is %08lx = %Z", P, P);

(they should give identical output once P = stoi(0)).

If P somehow "points into space" _after_ the statement P = stoi(0), you either
have modified P (easy to check, is 'gzero' still OK?), or wiped out the data
associated to the constant gzero [and you'll run into lots of trouble later].


P.S: Maybe you could send me a minimal _complete_ program (including the
pari_init statement) exhibiting the problem.
Karim Belabas                    email: Karim.Belabas@math.u-psud.fr
Dep. de Mathematiques, Bat. 425
Universite Paris-Sud             Tel: (00 33) 1 69 15 57 48
F-91405 Orsay (France)           Fax: (00 33) 1 69 15 60 19
PARI/GP Home Page: http://www.parigp-home.de/