Index: Singular/interpolation.cc
===================================================================
--- Singular/interpolation.cc	(revision d882518b93f286d7db8ab355fea6f1781b41f6d1)
+++ Singular/interpolation.cc	(revision 30d5747867002622ecc3828f793f4457c352afab)
@@ -15,13 +15,9 @@
 #include <kernel/ring.h>
 #ifdef HAVE_FACTORY
+#define SI_DONT_HAVE_GLOBAL_VARS
 #  include <factory/factory.h>
 #endif /* HAVE_FACTORY */
 
-//memory management
-#define mdmALLOC(x) omAlloc0(x)
-#define mdmFREE(x) omFree(x)
-
 // parameters to debug
-//#define debb
 //#define shmat
 //#define checksize
@@ -144,4 +140,5 @@
 #endif
 
+#if 0  /* only for debuggig*/
 void WriteMono (mono_type m) // Writes a monomial on the screen - only for debug
 {
@@ -151,5 +148,4 @@
 }
 
-#ifdef debb
 void WriteMonoList (mon_list_entry *list)
 {
@@ -228,5 +224,6 @@
    u1=1; u2=0;
    u = a; v = p;
-   while (v != 0) {
+   while (v != 0)
+   {
       q = u / v;
       r = u % v;
@@ -310,12 +307,16 @@
            if (Greater ((*curptr).mon,mon)) break;
            prevptr=curptr;
-           curptr=curptr->next;}
-     temp=(mon_list_entry*)mdmALLOC(sizeof(mon_list_entry));
+           curptr=curptr->next;
+     }
+     temp=(mon_list_entry*)omAlloc0(sizeof(mon_list_entry));
      (*temp).next=curptr;
-     (*temp).mon=(exponent*)mdmALLOC(sizeof(exponent)*variables);
+     (*temp).mon=(exponent*)omAlloc0(sizeof(exponent)*variables);
      memcpy(temp->mon,mon,sizeof(exponent)*variables);
-     if (prevptr==NULL) return temp; else {
+     if (prevptr==NULL) return temp;
+     else
+     {
           prevptr->next=temp;
-          return list;}
+          return list;
+     }
 }
 
@@ -331,5 +332,5 @@
 {
      mono_type m;
-     m=(exponent*)mdmALLOC(sizeof(exponent)*variables);
+     m=(exponent*)omAlloc0(sizeof(exponent)*variables);
      int i;
      for (i=0;i<variables;i++) m[i]=0;
@@ -340,36 +341,36 @@
 {
      int i,j,k;
-     points=(coordinates*)mdmALLOC(sizeof(coordinates)*n_points);
+     points=(coordinates*)omAlloc0(sizeof(coordinates)*n_points);
      for (i=0;i<n_points;i++)
      {
-         points[i]=(coordinate_products*)mdmALLOC(sizeof(coordinate_products)*variables);
-         for (j=0;j<variables;j++) points[i][j]=(modp_number*)mdmALLOC(sizeof(modp_number)*(max_coord));
-     }
-     condition_list=(condition_type*)mdmALLOC(sizeof(condition_type)*final_base_dim);
-     for (i=0;i<final_base_dim;i++) condition_list[i].mon=(exponent*)mdmALLOC(sizeof(exponent)*variables);
-     modp_points=(modp_coordinates*)mdmALLOC(sizeof(modp_coordinates)*n_points);
-     for (i=0;i<n_points;i++) modp_points[i]=(modp_number*)mdmALLOC(sizeof(modp_number)*variables);
+         points[i]=(coordinate_products*)omAlloc0(sizeof(coordinate_products)*variables);
+         for (j=0;j<variables;j++) points[i][j]=(modp_number*)omAlloc0(sizeof(modp_number)*(max_coord));
+     }
+     condition_list=(condition_type*)omAlloc0(sizeof(condition_type)*final_base_dim);
+     for (i=0;i<final_base_dim;i++) condition_list[i].mon=(exponent*)omAlloc0(sizeof(exponent)*variables);
+     modp_points=(modp_coordinates*)omAlloc0(sizeof(modp_coordinates)*n_points);
+     for (i=0;i<n_points;i++) modp_points[i]=(modp_number*)omAlloc0(sizeof(modp_number)*variables);
      if (!only_modp)
      {
-        q_points=(q_coordinates*)mdmALLOC(sizeof(q_coordinates)*n_points);
+        q_points=(q_coordinates*)omAlloc0(sizeof(q_coordinates)*n_points);
         for (i=0;i<n_points;i++)
         {
-            q_points[i]=(mpq_t*)mdmALLOC(sizeof(mpq_t)*variables);
+            q_points[i]=(mpq_t*)omAlloc0(sizeof(mpq_t)*variables);
             for (j=0;j<variables;j++) mpq_init(q_points[i][j]);
         }
-        int_points=(int_coordinates*)mdmALLOC(sizeof(int_coordinates)*n_points);
+        int_points=(int_coordinates*)omAlloc0(sizeof(int_coordinates)*n_points);
         for (i=0;i<n_points;i++)
         {
-            int_points[i]=(mpz_t*)mdmALLOC(sizeof(mpz_t)*variables);
+            int_points[i]=(mpz_t*)omAlloc0(sizeof(mpz_t)*variables);
             for (j=0;j<variables;j++) mpz_init(int_points[i][j]);
         }
      }
-     coord_exist=(coord_exist_table*)mdmALLOC(sizeof(coord_exist_table)*n_points);
+     coord_exist=(coord_exist_table*)omAlloc0(sizeof(coord_exist_table)*n_points);
      for (i=0;i<n_points;i++)
      {
-         coord_exist[i]=(bool*)mdmALLOC(sizeof(bool)*variables);
+         coord_exist[i]=(bool*)omAlloc0(sizeof(bool)*variables);
          for (j=0;j<variables;j++) coord_exist[i][j]=false;
      }
-     generic_column_name=(mono_type*)mdmALLOC(sizeof(mono_type)*final_base_dim);
+     generic_column_name=(mono_type*)omAlloc0(sizeof(mono_type)*final_base_dim);
      for (i=0;i<final_base_dim;i++) generic_column_name[i]=ZeroMonomial ();
      good_primes=0;
@@ -378,6 +379,6 @@
      if (!only_modp)
      {
-        polycoef=(mpz_t*)mdmALLOC(sizeof(mpz_t)*(final_base_dim+1));
-        polyexp=(mono_type*)mdmALLOC(sizeof(mono_type)*(final_base_dim+1));
+        polycoef=(mpz_t*)omAlloc0(sizeof(mpz_t)*(final_base_dim+1));
+        polyexp=(mono_type*)omAlloc0(sizeof(mono_type)*(final_base_dim+1));
         for (i=0;i<=final_base_dim;i++)
         {
@@ -403,7 +404,7 @@
      int i,j;
      check_list=MonListAdd (check_list,ZeroMonomial ());
-     my_row=(modp_number*)mdmALLOC(sizeof(modp_number)*final_base_dim);
-     my_solve_row=(modp_number*)mdmALLOC(sizeof(modp_number)*final_base_dim);
-     column_name=(mono_type*)mdmALLOC(sizeof(mono_type)*final_base_dim);
+     my_row=(modp_number*)omAlloc0(sizeof(modp_number)*final_base_dim);
+     my_solve_row=(modp_number*)omAlloc0(sizeof(modp_number)*final_base_dim);
+     column_name=(mono_type*)omAlloc0(sizeof(mono_type)*final_base_dim);
      for (i=0;i<final_base_dim;i++) column_name[i]=ZeroMonomial ();
      last_solve_column=0;
@@ -411,8 +412,8 @@
      modp_number pos_gen;
      bool gen_ok;
-     modp_Reverse=(modp_number*)mdmALLOC(sizeof(modp_number)*myp);
+     modp_Reverse=(modp_number*)omAlloc0(sizeof(modp_number)*myp);
 
 // produces table of modp inverts by finding a generator of (Z_myp*,*)
-     gen_table=(modp_number*)mdmALLOC(sizeof(modp_number)*myp);
+     gen_table=(modp_number*)omAlloc0(sizeof(modp_number)*myp);
      gen_table[1]=1;
      for (pos_gen=2;pos_gen<myp;pos_gen++)
@@ -432,5 +433,5 @@
      for (i=2;i<myp;i++) modp_Reverse[gen_table[i]]=gen_table[myp-i+1];
      modp_Reverse[1]=1;
-     mdmFREE(gen_table);
+     omFree(gen_table);
 }
 
@@ -443,6 +444,6 @@
      {
            pptr=ptr->next;
-           mdmFREE(ptr->mon);
-           mdmFREE(ptr);
+           omFree(ptr->mon);
+           omFree(ptr);
            ptr=pptr;}
      return NULL;
@@ -456,13 +457,13 @@
          for (j=0;j<variables;j++)
          {
-             mdmFREE(points[i][j]);
+             omFree(points[i][j]);
          }
-         mdmFREE(points[i]);
-     }
-     mdmFREE(points);
-     for (i=0;i<final_base_dim;i++) mdmFREE(condition_list[i].mon);
-     mdmFREE(condition_list);
-     for (i=0;i<n_points;i++) mdmFREE(modp_points[i]);
-     mdmFREE(modp_points);
+         omFree(points[i]);
+     }
+     omFree(points);
+     for (i=0;i<final_base_dim;i++) omFree(condition_list[i].mon);
+     omFree(condition_list);
+     for (i=0;i<n_points;i++) omFree(modp_points[i]);
+     omFree(modp_points);
      if (!only_modp)
      {
@@ -470,30 +471,30 @@
         {
             for (j=0;j<variables;j++) mpq_clear(q_points[i][j]);
-            mdmFREE(q_points[i]);
-        }
-        mdmFREE(q_points);
+            omFree(q_points[i]);
+        }
+        omFree(q_points);
         for (i=0;i<n_points;i++)
         {
             for (j=0;j<variables;j++) mpz_clear(int_points[i][j]);
-            mdmFREE(int_points[i]);
-        }
-        mdmFREE(int_points);
+            omFree(int_points[i]);
+        }
+        omFree(int_points);
         generic_lt=FreeMonList (generic_lt);
         for (i=0;i<=final_base_dim;i++)
         {
             mpz_clear(polycoef[i]);
-            mdmFREE(polyexp[i]);
-        }
-        mdmFREE(polycoef);
-        mdmFREE(polyexp);
+            omFree(polyexp[i]);
+        }
+        omFree(polycoef);
+        omFree(polyexp);
         if (!only_modp) mpz_clear(common_denom);
      }
      for (i=0;i<final_base_dim;i++)
      {
-         mdmFREE(generic_column_name[i]);
-     }
-     mdmFREE(generic_column_name);
-     for (i=0;i<n_points;i++) mdmFREE(coord_exist[i]);
-     mdmFREE(coord_exist);
+         omFree(generic_column_name[i]);
+     }
+     omFree(generic_column_name);
+     for (i=0;i<n_points;i++) omFree(coord_exist[i]);
+     omFree(coord_exist);
      pDelete(&comparizon_p1);
      pDelete(&comparizon_p2);
@@ -508,7 +509,7 @@
      lt_list=FreeMonList (lt_list);
      base_list=FreeMonList (base_list);
-     mdmFREE(my_row);
+     omFree(my_row);
      my_row=NULL;
-     mdmFREE(my_solve_row);
+     omFree(my_solve_row);
      my_solve_row=NULL;
      ptr=row_list;
@@ -516,13 +517,13 @@
      {
            pptr=ptr->next;
-           mdmFREE(ptr->row_matrix);
-           mdmFREE(ptr->row_solve);
-           mdmFREE(ptr);
+           omFree(ptr->row_matrix);
+           omFree(ptr->row_solve);
+           omFree(ptr);
            ptr=pptr;
      }
      row_list=NULL;
-     for (i=0;i<final_base_dim;i++) mdmFREE(column_name[i]);
-     mdmFREE(column_name);
-     mdmFREE(modp_Reverse);
+     for (i=0;i<final_base_dim;i++) omFree(column_name[i]);
+     omFree(column_name);
+     omFree(modp_Reverse);
 }
 
@@ -536,5 +537,5 @@
     int j,k;
     mono_type mn;
-    mn=(exponent*)mdmALLOC(sizeof(exponent)*variables);
+    mn=(exponent*)omAlloc0(sizeof(exponent)*variables);
     memcpy(mn,mon,sizeof(exponent)*variables);
     for (k=0;k<variables;k++)
@@ -547,5 +548,5 @@
         *ev=modp_mul(*ev,points[con.point_ref][k][mn[k]]);
     }
-    mdmFREE(mn);
+    omFree(mn);
 }
 
@@ -561,5 +562,5 @@
     int j,k;
     mono_type mn;
-    mn=(exponent*)mdmALLOC(sizeof(exponent)*variables);
+    mn=(exponent*)omAlloc0(sizeof(exponent)*variables);
     memcpy(mn,mon,sizeof(exponent)*variables);
     for (k=0;k<variables;k++)
@@ -573,5 +574,5 @@
         for (j=1;j<=mn[k];j++) mpz_mul(ev,ev,int_points[con.point_ref][k]);  // this loop computes the product of coordinate
     }
-    mdmFREE(mn);
+    omFree(mn);
     mpz_clear(mon_conv);
 }
@@ -693,5 +694,5 @@
          }
      }
-     mdmFREE(mon);
+     omFree(mon);
 }
 
@@ -765,5 +766,5 @@
            }
            row_ptr=row_ptr->next;
-#ifdef debb
+#if 0 /* only debugging */
            PrintS("reduction by row ");
            Info ();
@@ -805,11 +806,11 @@
           if (DivisibleMon (m,c_ptr->mon))
           {
-             if (p_ptr==NULL) 
+             if (p_ptr==NULL)
                 check_list=c_ptr->next;
              else
                 p_ptr->next=c_ptr->next;
              n_ptr=c_ptr->next;
-             mdmFREE(c_ptr->mon);
-             mdmFREE(c_ptr);
+             omFree(c_ptr->mon);
+             omFree(c_ptr);
              c_ptr=n_ptr;
           }
@@ -829,6 +830,6 @@
         memcpy(mon,check_list->mon,sizeof(exponent)*variables);
         n_check_list=check_list->next;
-        mdmFREE(check_list->mon);
-        mdmFREE(check_list);
+        omFree(check_list->mon);
+        omFree(check_list);
         check_list=n_check_list;
      }
@@ -872,8 +873,8 @@
          ptr=ptr->next;
      }
-     temp=(row_list_entry*)mdmALLOC(sizeof(row_list_entry));
-     (*temp).row_matrix=(modp_number*)mdmALLOC(sizeof(modp_number)*final_base_dim);
+     temp=(row_list_entry*)omAlloc0(sizeof(row_list_entry));
+     (*temp).row_matrix=(modp_number*)omAlloc0(sizeof(modp_number)*final_base_dim);
      memcpy((*temp).row_matrix,my_row,sizeof(modp_number)*(final_base_dim));
-     (*temp).row_solve=(modp_number*)mdmALLOC(sizeof(modp_number)*final_base_dim);
+     (*temp).row_solve=(modp_number*)omAlloc0(sizeof(modp_number)*final_base_dim);
      memcpy((*temp).row_solve,my_solve_row,sizeof(modp_number)*(final_base_dim));
      (*temp).first_col=first_col;
@@ -941,5 +942,5 @@
     modp_result_entry *temp;
     int i;
-    temp=(modp_result_entry*)mdmALLOC(sizeof(modp_result_entry));
+    temp=(modp_result_entry*)omAlloc0(sizeof(modp_result_entry));
     if (cur_result==NULL)
     {
@@ -968,10 +969,10 @@
      {
          next_gen=cur_gen->next;
-         mdmFREE(cur_gen->coef);
-         mdmFREE(cur_gen->lt);
-         mdmFREE(cur_gen);
+         omFree(cur_gen->coef);
+         omFree(cur_gen->lt);
+         omFree(cur_gen);
          cur_gen=next_gen;
      }
-     mdmFREE(e);
+     omFree(e);
 }
 
@@ -990,8 +991,8 @@
          cur_ptr=cur_ptr->next;
      }
-     temp=(generator_entry*)mdmALLOC(sizeof(generator_entry));
+     temp=(generator_entry*)omAlloc0(sizeof(generator_entry));
      if (prev_ptr==NULL) cur_result->generator=temp; else prev_ptr->next=temp;
      temp->next=NULL;
-     temp->coef=(modp_number*)mdmALLOC(sizeof(modp_number)*final_base_dim);
+     temp->coef=(modp_number*)omAlloc0(sizeof(modp_number)*final_base_dim);
      memcpy(temp->coef,my_solve_row,sizeof(modp_number)*final_base_dim);
      temp->lt=ZeroMonomial ();
@@ -1009,5 +1010,5 @@
      while (cur_ptr!=NULL)
      {
-         for (i=0;i<final_base_dim;i++) 
+         for (i=0;i<final_base_dim;i++)
              cur_ptr->coef[i]=modp_mul(cur_ptr->coef[i],modp_denom);
          cur_ptr->ltcoef=modp_denom;
@@ -1016,5 +1017,5 @@
 #endif
 }
-
+#if 0 /* only debbuging */
 void PresentGenerator (int i)  // only for debuging, writes a generator in its form in program
 {
@@ -1037,4 +1038,5 @@
      }
 }
+#endif
 
 modp_number TakePrime (modp_number p)  // takes "previous" (smaller) prime
@@ -1055,6 +1057,6 @@
      modp_number *congr_ptr;
      modp_number prod;
-     in_gamma=(modp_number*)mdmALLOC(sizeof(modp_number)*n);
-     congr=(modp_number*)mdmALLOC(sizeof(modp_number)*n);
+     in_gamma=(modp_number*)omAlloc0(sizeof(modp_number)*n);
+     congr=(modp_number*)omAlloc0(sizeof(modp_number)*n);
      congr_ptr=congr;
      while (cur_ptr!=NULL)
@@ -1077,6 +1079,6 @@
 void CloseChinese (int n) // after CRA
 {
-     mdmFREE(in_gamma);
-     mdmFREE(congr);
+     omFree(in_gamma);
+     omFree(congr);
      mpz_clear(bigcongr);
 }
@@ -1111,5 +1113,5 @@
      int coef;
      char *str=NULL;
-     str=(char*)mdmALLOC(sizeof(char)*1000);
+     str=(char*)omAlloc0(sizeof(char)*1000);
      modp_result_entry *cur_ptr;
      generator_entry *cur_gen;
@@ -1121,6 +1123,6 @@
      mpz_init(sol);
      mpz_init(nsol);
-     u=(modp_number*)mdmALLOC(sizeof(modp_number)*n);
-     v=(modp_number*)mdmALLOC(sizeof(modp_number)*n);
+     u=(modp_number*)omAlloc0(sizeof(modp_number)*n);
+     v=(modp_number*)omAlloc0(sizeof(modp_number)*n);
      for (coef=0;coef<=final_base_dim;coef++)
      {
@@ -1163,7 +1165,7 @@
 #endif
      }
-     mdmFREE(u);
-     mdmFREE(v);
-     mdmFREE(str);
+     omFree(u);
+     omFree(v);
+     omFree(str);
      ClearGCD ();
      mpz_clear(sol);
@@ -1284,9 +1286,9 @@
      good_primes++;
 }
-
+#if 0 /* only debuggig */
 void WriteGenerator () // writes generator (only for debugging)
 {
      char *str;
-     str=(char*)mdmALLOC(sizeof(char)*1000);
+     str=(char*)omAlloc0(sizeof(char)*1000);
      int i;
      for (i=0;i<=final_base_dim;i++)
@@ -1298,7 +1300,8 @@
          PrintS(" ");
      }
-     mdmFREE(str);
+     omFree(str);
      PrintLn();
 }
+#endif
 
 bool CheckGenerator () // evaluates generator to check whether it is good
@@ -1339,9 +1342,9 @@
          {
              mpz_clear(gen_list->polycoef[i]);
-             mdmFREE(gen_list->polyexp[i]);
+             omFree(gen_list->polyexp[i]);
          }
-         mdmFREE(gen_list->polycoef);
-         mdmFREE(gen_list->polyexp);
-         mdmFREE(gen_list);
+         omFree(gen_list->polycoef);
+         omFree(gen_list->polyexp);
+         omFree(gen_list);
          gen_list=temp;
       }
@@ -1369,9 +1372,9 @@
          temp=temp->next;
      }
-     temp=(gen_list_entry*)mdmALLOC(sizeof(gen_list_entry));
+     temp=(gen_list_entry*)omAlloc0(sizeof(gen_list_entry));
      if (prev==NULL) gen_list=temp; else prev->next=temp;
      temp->next=NULL;
-     temp->polycoef=(mpz_t*)mdmALLOC(sizeof(mpz_t)*(final_base_dim+1));
-     temp->polyexp=(mono_type*)mdmALLOC(sizeof(mono_type)*(final_base_dim+1));
+     temp->polycoef=(mpz_t*)omAlloc0(sizeof(mpz_t)*(final_base_dim+1));
+     temp->polyexp=(mono_type*)omAlloc0(sizeof(mono_type)*(final_base_dim+1));
      for (i=0;i<=final_base_dim;i++)
      {
@@ -1383,4 +1386,5 @@
 }
 
+#if 0 /* only debugging */
 void ShowGenList ()
 {
@@ -1388,5 +1392,5 @@
      int i;
      char *str;
-     str=(char*)mdmALLOC(sizeof(char)*1000);
+     str=(char*)omAlloc0(sizeof(char)*1000);
      temp=gen_list;
      while (temp!=NULL)
@@ -1403,6 +1407,7 @@
          temp=temp->next;
      }
-     mdmFREE(str);
-}
+     omFree(str);
+}
+#endif
 
 
@@ -1414,5 +1419,5 @@
      bool row_is_zero;
 
-#ifdef debb
+#if 0 /* only debugging */
      Info ();
 #endif
@@ -1422,5 +1427,5 @@
            TakeNextMonomial (cur_mon);
            ProduceRow (cur_mon);
-#ifdef debb
+#if 0 /* only debugging */
            cout << "row produced for monomial ";
            WriteMono (cur_mon);
@@ -1435,5 +1440,5 @@
               ReduceCheckListByMon (cur_mon);
               NewGenerator (cur_mon);
-#ifdef debb
+#if 0 /* only debugging */
               cout << "row is zero - linear dependence found (should be seen in my_solve_row)" << endl;
               cout << "monomial added to leading terms list" << endl;
@@ -1447,5 +1452,5 @@
               UpdateCheckList (cur_mon);
               ReduceCheckListByLTs ();
-#ifdef debb
+#if 0 /* only debugging */
               cout << "row is non-zero" << endl;
               cout << "monomial added to quotient basis list" << endl;
@@ -1455,5 +1460,5 @@
 #endif
               PrepareRow (cur_mon);
-#ifdef debb
+#if 0 /* only debugging */
               cout << "row prepared and put into matrix" << endl;
               Info ();
@@ -1461,5 +1466,5 @@
            }
         }
-        mdmFREE(cur_mon);
+        omFree(cur_mon);
 }
 
