Dirk Laurie on Wed, 06 Apr 2011 12:34:51 +0200


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

Trapping errors in library mode


When calling the Pari library from C, I don't want my program
to exit when I do something silly like dividing by zero.  So
I initialize not by pari_init but by pari_init_opts, omitting
INIT_JMPm from the list of options.  This works, in the sense
that I no longer get 

  ***   division by zero
  ***   Error in the PARI system. End of program.

Instead, I get (under Linux)

  ***   division by zero
Segmentation fault

which not everybody will agree is much nicer.  

The libpari documentation has nothing else on INIT_JMPm.
So I peeked in the source code.  I _think_ I should write
a routine headed 
    int my_exception_handler(long numerr)
using gp_exception_handler as a model, and say 
    default_exception_handler = my_exception_handler;

However, exploiting undocumented features by reverse-engineering
code is a _bad_ idea, so I'm asking here whether this is the
canonical way.

Dirk Laurie