Bill Allombert on Sat, 26 Nov 2005 19:29:02 +0100


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

Re: pari_init and programs using libpari.


On Tue, May 17, 2005 at 02:37:52PM +0200, Bill Allombert wrote:
> Hello pari-dev,
> 
> We are considering adding a new function as an optionnal replacement for
> pari_init. The idea is to add a flag that would let the user some
> behaviour of pari_init tpht might interfer with the program, in
> particular the installation of a signa handler.

So the attached patch adds a function
void    pari_init_opts(size_t parisize, ulong maxprime, ulong init_opts);

parisize and maxprime are as usual, init_opts is a bitmask:
INIT_JMPm: Set error handler setjmp
INIT_SIGm: Set up signal handling

Cheers,
Bill.
Index: src/gp/gp.c
===================================================================
RCS file: /home/cvs/pari/src/gp/gp.c,v
retrieving revision 1.279
diff -u -r1.279 gp.c
--- src/gp/gp.c	22 Nov 2005 09:23:06 -0000	1.279
+++ src/gp/gp.c	26 Nov 2005 18:07:14 -0000
@@ -812,7 +812,7 @@
 {
   free_graph(); freeall();
   kill_all_buffers(NULL);
-  if (INIT_SIG) pari_sig_init(SIG_DFL);
+  pari_sig_init(SIG_DFL);
   term_color(c_NONE);
   pariputs_opt("Goodbye!\n");
   if (GP_DATA->flags & TEXMACS) tm_end_output();
@@ -1845,9 +1845,7 @@
   pari_addfunctions(&pari_oldmodules, functions_oldgp,helpmessages_oldgp);
 
   init_graph();
-  INIT_SIG_off;
-  pari_init(top-bot, GP_DATA->primelimit);
-  INIT_SIG_on;
+  pari_init_opts(top-bot, GP_DATA->primelimit, 0);
   pari_sig_init(gp_sighandler);
 #ifdef READLINE
   init_readline();
Index: src/headers/paridecl.h
===================================================================
RCS file: /home/cvs/pari/src/headers/paridecl.h,v
retrieving revision 1.540
diff -u -r1.540 paridecl.h
--- src/headers/paridecl.h	26 Nov 2005 14:29:22 -0000	1.540
+++ src/headers/paridecl.h	26 Nov 2005 18:07:15 -0000
@@ -1243,6 +1243,7 @@
 void    msgtimer(char *format, ...);
 GEN     newbloc(long n);
 void    pari_err(long numerr, ...);
+void    pari_init_opts(size_t parisize, ulong maxprime, ulong init_opts);
 void    pari_init(size_t parisize, ulong maxprime);
 void    pari_sig_init(void (*f)(int));
 GEN     reorder(GEN x);
Index: src/language/anal.h
===================================================================
RCS file: /home/cvs/pari/src/language/anal.h,v
retrieving revision 1.77
diff -u -r1.77 anal.h
--- src/language/anal.h	10 Nov 2005 14:57:30 -0000	1.77
+++ src/language/anal.h	26 Nov 2005 18:07:15 -0000
@@ -136,15 +136,10 @@
 enum { EpUSER = 100, EpNEW, EpALIAS, EpVAR, EpGVAR, EpMEMBER, EpINSTALL };
 
 /* signals */
-extern ulong init_opts;
 #define INIT_JMPm 1
 #define INIT_SIGm 2
 #define INIT_JMP     (init_opts & INIT_JMPm)
 #define INIT_SIG     (init_opts & INIT_SIGm)
-#define INIT_JMP_on  (init_opts |= INIT_JMPm)
-#define INIT_SIG_on  (init_opts |= INIT_SIGm)
-#define INIT_JMP_off (init_opts &= ~INIT_JMPm)
-#define INIT_SIG_off (init_opts &= ~INIT_SIGm)
 
 /* defaults  */
 char* get_sep(const char *t);
Index: src/language/init.c
===================================================================
RCS file: /home/cvs/pari/src/language/init.c,v
retrieving revision 1.282
diff -u -r1.282 init.c
--- src/language/init.c	26 Nov 2005 13:30:58 -0000	1.282
+++ src/language/init.c	26 Nov 2005 18:07:15 -0000
@@ -47,7 +47,6 @@
 long    *ordvar;
 ulong   DEBUGFILES, DEBUGLEVEL, DEBUGMEM, compatible;
 ulong   precreal, precdl;
-ulong   init_opts = INIT_JMPm | INIT_SIGm;
 pari_sp bot = 0, top = 0, avma;
 size_t memused;
 
@@ -638,7 +637,7 @@
 /* initialize PARI data. You can call pari_addfunctions() first to add other
  * routines to the default set */
 void
-pari_init(size_t parisize, ulong maxprime)
+pari_init_opts(size_t parisize, ulong maxprime, ulong init_opts)
 {
   ulong u;
 
@@ -687,6 +686,12 @@
   (void)manage_var(manage_var_init,NULL); /* init nvar */
   var_not_changed = 1; (void)fetch_named_var("x");
   try_to_recover = 1;
+}
+
+void
+pari_init(size_t parisize, ulong maxprime)
+{
+  pari_init_opts(parisize, maxprime, INIT_JMPm | INIT_SIGm);
 }
 
 static void