=================================================================== RCS file: /home/cvs/OpenXM/src/ox_pari/ox_pari.c,v retrieving revision 1.12 retrieving revision 1.19 diff -u -p -r1.12 -r1.19 --- OpenXM/src/ox_pari/ox_pari.c 2015/08/21 01:20:30 1.12 +++ OpenXM/src/ox_pari/ox_pari.c 2019/12/19 08:34:41 1.19 @@ -1,5 +1,6 @@ -/* $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.11 2015/08/21 00:53:53 noro Exp $ */ +/* $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.18 2019/07/25 05:59:15 noro Exp $ */ +#include #include "ox_pari.h" OXFILE *fd_rw; @@ -85,7 +86,12 @@ void pops(int n) int sm_mathcap() { - mathcap_init(OX_PARI_VERSION, ID_STRING, "ox_pari", NULL, NULL); +#if 0 + char *opts[] = {"no_ox_reset", NULL}; + mathcap_init2(OX_PARI_VERSION, ID_STRING, "ox_pari", NULL, NULL, opts); +#else + mathcap_init2(OX_PARI_VERSION, ID_STRING, "ox_pari", NULL, NULL, NULL); +#endif push((cmo*)oxf_cmo_mathcap(fd_rw)); return 0; } @@ -151,9 +157,18 @@ int sm_executeFunction() struct parif *parif; unsigned long prec; char buf[BUFSIZ]; + int status; + char *err; - if ( setjmp(GP_DATA->env) ) { - sprintf(buf,"sm_executeFunction : an error occured in PARI."); + if ( (status = setjmp(GP_DATA->env)) != 0 ) { + err = errmessage[status]; + if ( status == errpile ) { + sprintf(buf,"%s\nIncrease PARI stack by pari(allocatemem,size).",err); + init_pari(); + } else if ( strlen(err) != 0 ) + sprintf(buf,"An error occured in PARI :%s",err); + else + sprintf(buf,"An error occured in PARI."); push((cmo*)make_error2(buf)); return -1; } @@ -210,6 +225,24 @@ int sm_executeFunction() avma = av0; push(ret); return 0; + } else if ( parif->type == 2 ) { + /* one number/poly/matrix argument with flag=0 */ + av0 = avma; + z = cmo_to_GEN(av[0]); + if ( ismatrix(z) ) { + int i,len; + len = lg(z); + for ( i = 1; i < len; i++ ) + settyp(z[i],t_COL); + settyp(z,t_MAT); + z = shallowtrans(z); + } + printf("input : "); output(z); + m = (*parif->f)(z,0); + ret = GEN_to_cmo(m); + avma = av0; + push(ret); + return 0; } else { sprintf(buf,"%s : not implemented",func->s); push((cmo*)make_error2(buf)); @@ -263,17 +296,51 @@ int receive() return 0; } +#if defined(ANDROID) +jmp_buf ox_env; +#else +sigjmp_buf ox_env; +#endif + +void usr1_handler(int sig) +{ +#if defined(ANDROID) + _longjmp(ox_env,1); +#else + siglongjmp(ox_env,1); +#endif +} + int main() { - init_gc(); - ox_stderr_init(stderr); - initialize_stack(); - init_pari(); +#if defined(ANDROID) + if ( _setjmp(ox_env) ) { +#else + if ( sigsetjmp(ox_env,~0) ) { +#endif + fprintf(stderr,"resetting libpari and sending OX_SYNC_BALL..."); + initialize_stack(); + init_pari(); + send_ox_tag(fd_rw,OX_SYNC_BALL); + fprintf(stderr,"done\n"); + } else { + init_gc(); + ox_stderr_init(stderr); + initialize_stack(); + init_pari(); + + fprintf(stderr,"ox_pari\n"); - fprintf(stderr,"ox_pari\n"); + fd_rw = oxf_open(3); + oxf_determine_byteorder_server(fd_rw); + } - fd_rw = oxf_open(3); - oxf_determine_byteorder_server(fd_rw); +#if defined(__CYGWIN__) + void *mysignal(int sig,void (*handler)(int m)); + mysignal(SIGUSR1,usr1_handler); +#else + signal(SIGUSR1,usr1_handler); +#endif while(1){ receive();