=================================================================== RCS file: /home/cvs/OpenXM/src/ox_pari/ox_pari.c,v retrieving revision 1.20 retrieving revision 1.24 diff -u -p -r1.20 -r1.24 --- OpenXM/src/ox_pari/ox_pari.c 2020/08/26 06:03:31 1.20 +++ OpenXM/src/ox_pari/ox_pari.c 2022/03/28 09:21:56 1.24 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.19 2019/12/19 08:34:41 fujimoto Exp $ */ +/* $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.23 2021/03/25 07:03:21 noro Exp $ */ #include #include "ox_pari.h" @@ -9,6 +9,7 @@ static int stack_size = 0; static int stack_pointer = 0; static cmo **stack = NULL; extern int debug_print; +extern unsigned long precreal; long paristack=10000000; #define INIT_S_SIZE 2048 @@ -33,6 +34,7 @@ void init_pari() { pari_init(paristack,2); mp_set_memory_functions(GC_malloc,gc_realloc,gc_free); + gmp_check(); } int initialize_stack() @@ -157,7 +159,6 @@ int sm_executeFunction() struct parif *parif; unsigned long prec; char buf[BUFSIZ]; - extern unsigned long precreal; cmo_string *func = (cmo_string *)pop(); if(func->tag != CMO_STRING) { @@ -184,6 +185,13 @@ int sm_executeFunction() init_pari(); return 0; } + if ( !strcmp(func->s,"pari_setprec") ) { + long n,prec; + + n = cmo_to_int(av[0]); + setrealprecision(n,&prec); + return 0; + } parif =search_parif(func->s); if ( !parif ) { sprintf(buf,"%s : not implemented",func->s); @@ -196,7 +204,7 @@ int sm_executeFunction() av0 = avma; z = cmo_to_GEN(av[0]); - prec = ac==2 ? cmo_to_int(av[1])*3.32193/32+3 : precreal; + prec = ac==2 ? ndec2prec(cmo_to_int(av[1])) : nbits2prec(precreal); if ( ismatrix(z) ) { int i,len; len = lg(z); @@ -268,7 +276,7 @@ int receive_and_execute_sm_command() exit(0); break; default: - printf("receive_and_execute_sm_command : code=%d\n",code);fflush(stdout); + ox_printf("receive_and_execute_sm_command : code=%d\n",code); break; } return 0; @@ -281,15 +289,15 @@ int receive() tag = receive_ox_tag(fd_rw); switch(tag) { case OX_DATA: - printf("receive : ox_data %d\n",tag);fflush(stdout); + ox_printf("receive : ox_data %d\n",tag); push(receive_cmo(fd_rw)); break; case OX_COMMAND: - printf("receive : ox_command %d\n",tag);fflush(stdout); + ox_printf("receive : ox_command %d\n",tag); receive_and_execute_sm_command(); break; default: - printf("receive : tag=%d\n",tag);fflush(stdout); + ox_printf("receive : tag=%d\n",tag); } return 0; } @@ -309,6 +317,10 @@ void usr1_handler(int sig) #endif } +#if defined(USE_OXPARI_LOG) +#define LOGFILE "/tmp/oxpari.log" +#endif + int main() { #if defined(ANDROID) @@ -316,18 +328,21 @@ int main() #else if ( sigsetjmp(ox_env,~0) ) { #endif - fprintf(stderr,"resetting libpari and sending OX_SYNC_BALL..."); + ox_printf("resetting libpari and sending OX_SYNC_BALL..."); init_pari(); initialize_stack(); send_ox_tag(fd_rw,OX_SYNC_BALL); - fprintf(stderr,"done\n"); + ox_printf("done\n"); } else { init_gc(); - ox_stderr_init(stderr); + +#if defined(LOGFILE) + ox_stderr_init(fopen(LOGFILE,"a")); +#endif init_pari(); initialize_stack(); - fprintf(stderr,"ox_pari\n"); + ox_printf("ox_pari\n"); fd_rw = oxf_open(3); oxf_determine_byteorder_server(fd_rw);