Patches for Giac

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

infinity0
Messages : 36
Inscription : dim. févr. 05, 2017 5:46 pm

Patches for Giac

Message par infinity0 » dim. févr. 05, 2017 6:17 pm

Hi, I'm packaging Giac for Debian.

Pari in Debian is compiled with thread-local storage (TLS). However, Giac 1.2.3-21 is not compatible with that. Instead, we must apply a patch, see below. (I cannot attach it to this post, the forum says "The extension patch is not allowed.")

I have written the patch in a way, that it should still work for non-TLS pari. Could you please apply this to the next version of Giac? If you need, I can also explain how it works in detail - just ask me.

Thank you!

Code : Tout sélectionner

diff --git a/src/pari.cc b/src/pari.cc
index 441141c..b59bf0b 100644
--- a/src/pari.cc
+++ b/src/pari.cc
@@ -53,7 +53,11 @@ static long int abs(long int & l){
 extern "C" {
 #include <pari/pari.h>
 #include <pari/paripriv.h>
+#ifdef ENABLE_TLS
+  extern THREAD void *PARI_stack_limit;
+#else
   extern void *PARI_stack_limit;
+#endif
   extern entree functions_basic[];
 }
 #if PARI_VERSION_CODE<PARI_VERSION(2,4,0) // 132096
@@ -106,15 +110,13 @@ namespace giac {
     gp_read_str("[x,y,z,t]");
   }
 
-  struct giac_pari_init {
-    giac_pari_init(long maxprime) { 
-      if(!avma){ 
-	do_giac_pari_init(maxprime); 
-      }
+  static long pari_maxprime=100000;
+  long get_pari_avma() {
+    if(!avma){
+      do_giac_pari_init(pari_maxprime);
     }
+    return avma;
   };
-  static long pari_maxprime=100000;
-  static giac_pari_init bidon(pari_maxprime);
 
   static gen pow2sizeof_long(pow(256,sizeof(long)));
   // Conversion of a GEN integer to a gen, using Horner method
@@ -593,7 +595,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     tmp=GEN2gen(gisprime(gen2GEN(e,vecteur(0),0),certif),vecteur(0));
     avma=av;
 #ifdef HAVE_LIBPTHREAD
@@ -609,7 +611,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     GEN g=gen2GEN(e,vecteur(0),0);
     GEN gf=factorint(g,0);
     s=GEN2string(gf);
@@ -627,7 +629,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     GEN g=gen2GEN(e,vecteur(0),0);
     GEN gf=ggamma(g,precision(g));
     res=GEN2gen(gf,vecteur(0));
@@ -645,7 +647,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     GEN g=gen2GEN(e,vecteur(0),0);
     GEN gf=gzeta(g,precision(g));
     res=GEN2gen(gf,vecteur(0));
@@ -663,7 +665,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     GEN g=gen2GEN(e,vecteur(0),0);
     GEN gf=gpsi(g,precision(g));
     res=GEN2gen(gf,vecteur(0));
@@ -681,7 +683,7 @@ namespace giac {
     abort_if_locked();
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     tmp=GEN2gen(ffinit(gen2GEN(p,vecteur(0),0),n,0),vecteur(0));
     avma=av;
 #ifdef HAVE_LIBPTHREAD
@@ -698,7 +700,7 @@ namespace giac {
   // GEN combine_factors(GEN a, GEN famod, GEN p, long klim, long hint);
   bool pari_lift_combine(const vecteur & a,const vector<vecteur> & factmod,gen & modulo,vector<vecteur> & res){
 #ifdef PARI23
-    long av=avma;
+    long av=get_pari_avma();
     GEN pari_a=gen2GEN(r2e(a,x__IDNT_e,context0),vecteur(0),0);
     string s("[");
     vector<vecteur>::const_iterator it=factmod.begin(),itend=factmod.end();
@@ -731,7 +733,7 @@ namespace giac {
   }
 
   static gen pari_exec(const string & s,GIAC_CONTEXT){
-    long av=avma;
+    long av=get_pari_avma();
     void * save_pari_stack_limit = PARI_stack_limit;
     PARI_stack_limit=0; // required since the stack changed
 #ifdef PARI23
@@ -804,7 +806,7 @@ namespace giac {
     lidnt(v,vars,false);
     vars.erase(vars.begin());
     bool parse_all=false;
-    long av=avma;
+    long av=get_pari_avma();
 #ifdef PARI23
     if (setjmp(GP_DATA->env)){ 
       avma = av;
@@ -951,7 +953,7 @@ namespace giac {
 	} // end if (i!=pari_function_table.end())
       } // end if vstr!=""
       if (vstr=="" && vs==2){
-	long av=avma;
+	long av=get_pari_avma();
 	gen res= GEN2gen(gen2GEN(v[1],vars,contextptr),vars);
 	avma=av;
 	return res;
@@ -1063,7 +1065,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     GEN G=gen2GEN(change_subtype(p,_POLY1__VECT),vecteur(0),contextptr);
     if (debug_infolevel)
       CERR << "pari_polroots " << GEN2gen(G,vecteur(1,vx_var)) << endl;
@@ -1087,7 +1089,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     void * save_pari_stack_limit = PARI_stack_limit;
     PARI_stack_limit=0; 
     GEN P=gen2GEN(p,lv,contextptr);
@@ -1111,7 +1113,7 @@ namespace giac {
 #ifdef HAVE_LIBPTHREAD
     pthread_cleanup_push(pari_cleanup, (void *) pari_mutex_ptr);
 #endif
-    long av=avma;
+    long av=get_pari_avma();
     void * save_pari_stack_limit = PARI_stack_limit;
     PARI_stack_limit=0; 
     GEN P=gen2GEN(p,lv,contextptr);

parisse
Messages : 5740
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Patches for Giac

Message par parisse » lun. févr. 06, 2017 9:32 am

In other words, declare PARI_stack_limit as THREAD if ENABLE_TLS is defined, and replace all reads to avma with get_pari_avma(), where this function insures that pari is initialized by checking avma!=0, is this correct?

infinity0
Messages : 36
Inscription : dim. févr. 05, 2017 5:46 pm

Re: Patches for Giac

Message par infinity0 » lun. févr. 06, 2017 12:16 pm

Yes, exactly.

parisse
Messages : 5740
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Patches for Giac

Message par parisse » lun. févr. 06, 2017 12:21 pm

I have applied the changes, you can check with the latest source here:
http://www-fourier.ujf-grenoble.fr/~par ... .3.tar.bz2
If it's ok, I will make a build and update the giac_stable.tgz link to 1.2.3-25

infinity0
Messages : 36
Inscription : dim. févr. 05, 2017 5:46 pm

Re: Patches for Giac

Message par infinity0 » lun. févr. 06, 2017 4:29 pm

Yes, I've confirmed that it works. Thank you!

parisse
Messages : 5740
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Patches for Giac

Message par parisse » mar. févr. 07, 2017 12:22 pm

giac_stable now links to the patched 1.2.3-25 version.

Répondre