Karim Belabas on Mon, 31 Oct 2005 20:21:38 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Lifting and handling errors |
* Chris Condrat [2005-10-31 09:29]: > On 10/27/05, Karim Belabas <belabas@math.u-bordeaux1.fr> wrote: >> >> Indeed lift() will probably overflow the stack again. The current >> documentation of 'trap' suggests installing an error handler by typing >> >> { trap(errpile, >> print(reorder); >> writebin("crash")) } >> >> This will save the values of all user variables in file 'crash' when >> stack overflow occurs. And print their names on screen for diagnostics. > > I'm sorry, I forgot to mention that I'm using the C library, not the GP > interface. I can't find any documentation on how errors are trapped. That's "normal", the interface is considered to be insatisfactory, so will change. If you really want to try using it, the following code adapted from gen2.c should be easy to understand: /* equality test by subtraction */ int gegal_try(GEN x, GEN y) { int i; CATCH(CATCH_ALL) { CATCH_RELEASE(); return 0; /* caught something, test fails */ } TRY { i = gcmp0(gsub(x, y)); /* gsub may raise an exception */ } ENDCATCH; return i; } In your example, you don't want to CATCH( CATCH_ALL ), but only to CATCH( errpile ). But IMHO, it's better to avoid these hacks, and simply use something like if ((long)(avma - bot) < taille2(x)) { /* lifting x will probably overflow stack */ ... } else { /* we will be fine */ ... } Hope this helps, Karim. -- Karim Belabas Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux.fr/~belabas/ F-33405 Talence (France) http://pari.math.u-bordeaux.fr/ [PARI/GP]