Bill Allombert on Tue, 19 Sep 2006 20:30:16 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: PARI_stack_limit |
On Sun, Sep 17, 2006 at 08:33:17PM +0200, Bill Allombert wrote: > So I would propose we: > > 1) make stack-checking optional through a init_opts options. I changed my mind about 1. Since pari_init_stackcheck() does not actually mess with the system in any way (it just set a variable) it is not suitable for an init_opts option. > 2) make pari_init_stackcheck public and document it. Here a patch that do the first part, making sure it is available even if STACK_CHECK is not defined (which fix a major bug in 2.3). The public pari_init_stackcheck() also accept NULL as argument and in that case disable the stack checking completly. It would make sense at this stage to make PARI_stack_limit static but this would break backward compatibility. > At this point the question is whether pari_thread_init should call > pari_init_stackcheck itself The patch does not settle that issue. Note that under --enable-tls, each new thread start automatically with PARI_stack_limit=NULL and thus with disabled stack-cheking. Cheers, Bill.
Index: src/language/init.c =================================================================== RCS file: /home/cvs/pari/src/language/init.c,v retrieving revision 1.313 diff -u -r1.313 init.c --- src/language/init.c 19 Sep 2006 11:36:22 -0000 1.313 +++ src/language/init.c 19 Sep 2006 17:34:42 -0000 @@ -193,13 +193,19 @@ /* C STACK SIZE CONTROL */ /* (avoid core dump on deep recursion) */ /*********************************************************************/ +THREAD void *PARI_stack_limit = NULL; + #ifdef STACK_CHECK /* adapted from Perl code written by Dominic Dunlop */ -THREAD void *PARI_stack_limit = NULL; # ifdef __EMX__ /* Emulate */ -# define STACK_CHECK_INIT(b) \ - ((void)b, PARI_stack_limit = get_stack(1./16, 32*1024)) +void +pari_init_stackcheck(void *stack_base) +{ + (void) stack_base; + if (!stack_base) { PARI_stack_limit = NULL; return; } + PARI_stack_limit = get_stack(1./16, 32*1024); +} # else /* !__EMX__ */ #include <sys/types.h> #include <sys/time.h> @@ -209,12 +215,12 @@ * be used on the stack. Leave PARI_stack_limit at its initial value (NULL) * to show no check should be made [init failed]. Assume stack grows downward. */ -static void +void pari_init_stackcheck(void *stack_base) { struct rlimit rip; ulong size; - + if (!stack_base) { PARI_stack_limit = NULL; return; } if (getrlimit(RLIMIT_STACK, &rip)) return; size = rip.rlim_cur; if (size == (ulong)RLIM_INFINITY || size > (ulong)stack_base) @@ -222,11 +228,14 @@ else PARI_stack_limit = (void*)((ulong)stack_base - (size/16)*15); } -# define STACK_CHECK_INIT(b) pari_init_stackcheck(b) # endif /* !__EMX__ */ #else -# define STACK_CHECK_INIT(b) ((void)b) +void +pari_init_stackcheck(void *stack_base) +{ + PARI_stack_limit = NULL; +} #endif /* STACK_CHECK */ /*********************************************************************/ @@ -591,7 +600,7 @@ { ulong u; - STACK_CHECK_INIT(&u); + pari_init_stackcheck(&u); if ((init_opts&INIT_DFTm)) { GP_DATA = default_gp_data(); pari_init_defaults(); } err_catch_stack=NULL; Index: src/headers/paridecl.h =================================================================== RCS file: /home/cvs/pari/src/headers/paridecl.h,v retrieving revision 1.594 diff -u -r1.594 paridecl.h --- src/headers/paridecl.h 18 Sep 2006 14:05:16 -0000 1.594 +++ src/headers/paridecl.h 19 Sep 2006 17:35:35 -0000 @@ -1247,6 +1247,7 @@ 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_init_stackcheck(void *stack_base); void pari_sig_init(void (*f)(int)); void pari_thread_init(size_t parisize); void pari_thread_close(void);