[BACK]Return to ox_pari.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_pari

Diff for /OpenXM/src/ox_pari/ox_pari.c between version 1.15 and 1.20

version 1.15, 2016/09/23 07:03:29 version 1.20, 2020/08/26 06:03:31
Line 1 
Line 1 
 /*  $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.14 2016/08/23 03:03:26 ohara Exp $  */  /*  $OpenXM: OpenXM/src/ox_pari/ox_pari.c,v 1.19 2019/12/19 08:34:41 fujimoto Exp $  */
   
   #include <signal.h>
 #include "ox_pari.h"  #include "ox_pari.h"
   
 OXFILE *fd_rw;  OXFILE *fd_rw;
Line 26  void gc_free(void *p,size_t size)
Line 27  void gc_free(void *p,size_t size)
 void init_gc()  void init_gc()
 {  {
   GC_INIT();    GC_INIT();
   mp_set_memory_functions(GC_malloc,gc_realloc,gc_free);  
 }  }
   
 void init_pari()  void init_pari()
 {  {
   pari_init(paristack,2);    pari_init(paristack,2);
     mp_set_memory_functions(GC_malloc,gc_realloc,gc_free);
 }  }
   
 int initialize_stack()  int initialize_stack()
Line 85  void pops(int n)
Line 86  void pops(int n)
   
 int sm_mathcap()  int sm_mathcap()
 {  {
   #if 0
   char *opts[] = {"no_ox_reset", NULL};    char *opts[] = {"no_ox_reset", NULL};
   mathcap_init2(OX_PARI_VERSION, ID_STRING, "ox_pari", NULL, NULL, opts);    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));    push((cmo*)oxf_cmo_mathcap(fd_rw));
   return 0;    return 0;
 }  }
Line 152  int sm_executeFunction()
Line 157  int sm_executeFunction()
   struct parif *parif;    struct parif *parif;
   unsigned long prec;    unsigned long prec;
   char buf[BUFSIZ];    char buf[BUFSIZ];
   int status;    extern unsigned long precreal;
   char *err;  
   
   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;  
   }  
   cmo_string *func = (cmo_string *)pop();    cmo_string *func = (cmo_string *)pop();
   if(func->tag != CMO_STRING) {    if(func->tag != CMO_STRING) {
     sprintf(buf,"sm_executeFunction : func->tag=%d is not CMO_STRING",func->tag);      sprintf(buf,"sm_executeFunction : func->tag=%d is not CMO_STRING",func->tag);
Line 182  int sm_executeFunction()
Line 174  int sm_executeFunction()
   }    }
   for ( i = 0; i < ac; i++ ) {    for ( i = 0; i < ac; i++ ) {
     av[i] = (cmo *)pop();      av[i] = (cmo *)pop();
 //    fprintf(stderr,"arg%d:",i);  
 //    print_cmo(av[i]);  
 //    fprintf(stderr,"\n");  
   }    }
   if( strcmp( func->s, "exit" ) == 0 )    if( strcmp( func->s, "exit" ) == 0 )
     exit(0);      exit(0);
   
     if ( !strcmp(func->s,"allocatemem") ) {
       paristack =  cmo_to_int(av[0]);
       pari_close();
       init_pari();
       return 0;
     }
   parif =search_parif(func->s);    parif =search_parif(func->s);
   if ( !parif ) {    if ( !parif ) {
     sprintf(buf,"%s : not implemented",func->s);      sprintf(buf,"%s : not implemented",func->s);
     push((cmo*)make_error2(buf));      push((cmo*)make_error2(buf));
     return -1;      return -1;
  } else if ( parif->type == 0 ) {    } else if ( parif->type <= 2 ) {
     /* one long int variable */      /* type=1 => one GEN argument possibly with prec */
     int a = cmo_to_int(av[0]);      /* type=2 => one GEN argument with optarg */
     a = (int)(parif->f)(a);      /* type=3 => one GEN, return ulong */
     ret = (cmo *)new_cmo_int32(a);  
     push(ret);  
     return 0;  
   } else if ( parif->type == 1 ) {  
     /* one number/poly/matrix argument possibly with prec */  
     av0 = avma;      av0 = avma;
     z = cmo_to_GEN(av[0]);      z = cmo_to_GEN(av[0]);
     prec = ac==2 ? cmo_to_int(av[1])*3.32193/32+3 : precreal;      prec = ac==2 ? cmo_to_int(av[1])*3.32193/32+3 : precreal;
Line 214  int sm_executeFunction()
Line 205  int sm_executeFunction()
       settyp(z,t_MAT);        settyp(z,t_MAT);
       z = shallowtrans(z);        z = shallowtrans(z);
     }      }
     printf("input : "); output(z);      pari_CATCH(CATCH_ALL) {
     m = (*parif->f)(z,prec);        GEN E = pari_err_last();
     ret = GEN_to_cmo(m);        long code = err_get_num(E);
     avma = av0;        char *err = pari_err2str(E);
     push(ret);        if ( code == e_MEM || code == e_STACK ) {
     return 0;          sprintf(buf,"%s\nIncrease PARI stack by pari(allocatemem,size).",err);
   } else if ( parif->type == 2 ) {        } else
     /* one number/poly/matrix argument with flag=0 */          sprintf(buf,"An error occured in PARI :%s",err);
     av0 = avma;        push((cmo*)make_error2(buf));
     z = cmo_to_GEN(av[0]);        pari_CATCH_reset();
     if ( ismatrix(z) ) {        avma = av0;
       int i,len;        return -1;
       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);      pari_TRY {
     m = (*parif->f)(z,0);        ret = 0;
     ret = GEN_to_cmo(m);        if ( parif->type == 0 ) {
     avma = av0;          gp_allocatemem(z);
     push(ret);          ret = av[0];
     return 0;          /* allocatemem */
         } else if ( parif->type == 1 ) {
           m = (*parif->f)(z,prec);
           ret = GEN_to_cmo(m);
         } else if ( parif->type == 2 ) {
           m = (*parif->f)(z,parif->opt);
           ret = GEN_to_cmo(m);
         } else if ( parif->type == 3 ) {
           /* XXX */
           unsigned long a;
           a = (unsigned long)(*parif->f)(z);
           ret = (cmo *)new_cmo_int32((int)a);
         }
         avma = av0;
         push(ret);
         return 0;
       }
       pari_ENDCATCH
   } else {    } else {
     sprintf(buf,"%s : not implemented",func->s);      sprintf(buf,"%s : not implemented",func->s);
     push((cmo*)make_error2(buf));      push((cmo*)make_error2(buf));
Line 291  int receive()
Line 294  int receive()
   return 0;    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()  int main()
 {  {
   init_gc();  #if defined(ANDROID)
   ox_stderr_init(stderr);    if ( _setjmp(ox_env) ) {
   initialize_stack();  #else
   init_pari();    if ( sigsetjmp(ox_env,~0) ) {
   #endif
       fprintf(stderr,"resetting libpari and sending OX_SYNC_BALL...");
       init_pari();
       initialize_stack();
       send_ox_tag(fd_rw,OX_SYNC_BALL);
       fprintf(stderr,"done\n");
     } else {
       init_gc();
       ox_stderr_init(stderr);
       init_pari();
       initialize_stack();
   
       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);  #if defined(__CYGWIN__)
   oxf_determine_byteorder_server(fd_rw);    void *mysignal(int sig,void (*handler)(int m));
     mysignal(SIGUSR1,usr1_handler);
   #else
     signal(SIGUSR1,usr1_handler);
   #endif
   
   while(1){    while(1){
     receive();      receive();

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.20

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>