Karim BELABAS on Fri, 13 Nov 1998 16:14:49 +0100 (MET)

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

Re: C stack overflow in 2.0.12

[Matias Atria:]
> The following commands cause a segmentation fault in version 2.0.12.alpha:
> ? a.b=[]
> ? a.b=concat(a.b, "blah")
> ? a.b
> ** CRASH **

That's the usual outcome of infinite recursion. The real culprit is the OS
which has the C stack reside in a fixed-size memory segment; when C stack
frames nest too deeply, we reach addresses outside that segment and a SEGV is
raised. Now we have a major problem: the signal handler itself needs a stack
frame, and gp crashes. This happens on Solaris, for instance, and not on Linux
(as far as I could see).

GP is not protected against that ((f()=f()); f fails just the same), [I could
prevent the final crash by specify an alternate stack for signals, e.g use
sigaltstack(2) on Solaris (thx for the tip, Igor!), but I haven't done it
yet. But I can do nothing about the SEGV...]

> I know the input is incorrect (i.e. should be concat(a.b, ["blah"])) but
> still, GP shouldn't crash :-)

The input is actually locally correct, although it doesn't make any sense
globally. Basically, because member functions definitions are processed in
the same way as user functions, i.e they _replace_ anything going by the same
name, and cannot use the former definition.

> ? a.b=[]
define a user member function ".b" which returns the empty vector, whatever
"a" is, e.g. Pi.b --> []

> ? a.b=concat(a.b, "blah")
erase the former definition, and replace it by a new one, which makes use of
the _new_ definition (the old a.b=[] has been lost). concat is perfectly ok
there: concat(x, ["blah"]) --> add the element "blah" to the list/array x
       concat(x, "blah") --> concatenate the two strings x and "blah"
(depending on what x actually is you will get syntax errors)

> ? a.b
infinite recursion (need to call a.b to evaluate a.b).

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://pari.home.ml.org