Changeset dd6b1d in git


Ignore:
Timestamp:
Mar 31, 2010, 8:15:34 AM (14 years ago)
Author:
Martin Monerjan
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
69b4990f59641fb854b4b0c6b4c68f32a163ae9d
Parents:
6184b1dc226c2756136736be02b9732d2388e385
Message:
Tweaked preprocessing step in getConeNormals i.e. removed several
memleaks
Removed variables that are no longer needed in the interior point part
of getExtremalRays
Adjusted warnings for INT_MAX overflows
Tried strcpy and the such in readConeFromFile


git-svn-id: file:///usr/local/Singular/svn/trunk@12702 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    r6184b1 rdd6b1d  
    904904                }
    905905                computeInv((ideal&)I,initialForm,*gamma);
     906                delete gamma;
    906907                //Create leading ideal
    907908                ideal L=idInit(IDELEMS(initialForm),1);
     
    911912                }               
    912913               
    913                 LObject *P = new sLObject();
     914                LObject *P = new sLObject();//TODO What's the difference between sLObject and LObject?
    914915                memset(P,0,sizeof(LObject));
    915916
     
    925926                                if(P->p!=NULL)  //spoly non zero=?
    926927                                {       
    927                                         poly p;//=pInit(); NOTE Evil memleak if pInit is used                   
    928                                         poly q;//=pInit();
     928                                        poly p;//NOTE Don't use pInit here. Evil memleak will follow
     929                                        poly q;
     930                                        poly pDel,qDel;
    929931                                        p=pCopy(P->p);
    930932                                        q=pHead(p);     //Monomial q
     933                                        pDelete(&q);
     934                                        pDel=p; qDel=q;
    931935                                        isMaybeFacet=FALSE;
    932936                                        //TODO: Suffices to check LTs here
    933937                                        while(p!=NULL)
    934                                         {
     938                                        {                                               
    935939                                                q=pHead(p);
    936940                                                for(int ll=0;ll<IDELEMS(L);ll++)
     
    946950                                                        break;//while(p!=NULL)
    947951                                                }
    948                                                 p=pNext(p);                                             
     952                                                p=pNext(p);
     953                                                pDelete(&q);                                           
    949954                                        }//while
    950                                         pDelete(&p);
     955//                                      pDelete(&p);//NOTE Better to use pDel and qDel. Commenting in this line will not work!
    951956                                        pDelete(&q);
     957                                        pDelete(&pDel);
     958                                        pDelete(&qDel);
    952959                                        if(isMaybeFacet==FALSE)
    953960                                        {
     
    969976                                                goto _start;    //mea culpa, mea culpa, mea maxima culpa
    970977                                        }
    971                                 }//if(P->p!=NULL)                               
     978                                }//if(P->p!=NULL)
     979                                pDelete(&(P->p));
    972980                        }//for k
    973981                }//for jj
     
    976984                delete P;
    977985                idDelete(&initialForm);
    978                 //idDelete(L);
    979                 delete gamma;
    980986        }//for(ii<ddineq-rowsize
    981987//      delete gamma;
     
    14101416        /* Compute interior point on the fly*/
    14111417        int64vec *ivIntPointOfCone = new int64vec(this->numVars);
    1412         mpq_t *colSum = new mpq_t[this->numVars];
    1413         int denom[this->numVars];//denominators of colSum
     1418//      mpq_t *colSum = new mpq_t[this->numVars];
     1419//      int denom[this->numVars];//denominators of colSum
    14141420        //NOTE TODO need to gcd of rows and factor out! -> makeInt
    14151421        /*for(int jj=0;jj<this->numVars;jj++)
     
    14501456        mpz_clear(den);
    14511457        mpz_clear(tmp);*/
     1458        int64vec *foo = new int64vec(this->numVars);
    14521459        for(int ii=0;ii<P->rowsize;ii++)
    14531460        {
    1454                 int64vec *foo = new int64vec(this->numVars);
     1461//              int64vec *foo = new int64vec(this->numVars);
    14551462                int64vec *tmp = ivIntPointOfCone;
    14561463                makeInt(P,ii+1,*foo);
    14571464                ivIntPointOfCone = iv64Add(ivIntPointOfCone,foo);
    14581465                delete tmp;
    1459                 delete foo;
    1460         }
     1466//              delete foo;
     1467        }
     1468        delete foo;
    14611469        int64 ggT=(*ivIntPointOfCone)[0];
    14621470        for (int ii=0;ii<(this->numVars);ii++)
     
    14831491        }
    14841492//      mpq_clear(qkgV);
    1485         delete [] colSum;
     1493//      delete [] colSum;
    14861494        /*For homogeneous input (like Det3,3,5) the int points may be negative. So add a suitable multiple of (1,_,1)*/
    14871495        if(hasHomInput==TRUE && iv64isStrictlyPositive(ivIntPointOfCone)==FALSE)
     
    22742282                        {
    22752283                                //Found a parallel vector. Add it
    2276                                 initialFormElement = pAdd((initialFormElement),(poly)pHead(aktpoly));
     2284                                initialFormElement = pAdd((initialFormElement),(poly)pHead(aktpoly));//pAdd = p_Add_q destroys args
    22772285                        }
    22782286                        omFree(v);
     
    25002508        dd_LPSolverType solver=dd_DualSimplex;
    25012509        dd_LPSolutionPtr lpSol=NULL;
    2502         dd_rowset ddlinset,ddredrows;   //needed for dd_FindRelativeInterior
    2503         dd_rowindex ddnewpos;
     2510//      dd_rowset ddlinset,ddredrows;   //needed for dd_FindRelativeInterior
     2511//      dd_rowindex ddnewpos;
    25042512        dd_NumberType numb;     
    25052513        //M->representation=dd_Inequality;
     
    27902798        {                               
    27912799                A[jj]=(*ivw)[jj];
    2792                 if(A[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight!\n");
     2800                if((*ivw)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight!\n");
    27932801        }                       
    27942802        res->wvhdl[0]=(int *)A;
     
    28322840                A1[jj]=(*ivw)[jj];
    28332841                A2[jj]=-(*fNormal)[jj];
    2834                 if(A1[jj]>=INT_MAX || A2[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight2!\n");
     2842                if((*ivw)[jj]>=INT_MAX || (*fNormal)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight2!\n");
    28352843        }                       
    28362844        res->wvhdl[0]=(int *)A1;
     
    38233831        replacementRing->order[2]=ringorder_C;
    38243832
    3825         int64vec *ivw = this->getIntPoint();
     3833        int64vec *ivw = this->getIntPoint(TRUE);
    38263834//      assert(this->ivIntPt); 
    38273835        int length=ivw->length();       
     
    38303838        {
    38313839                A[jj]=(*ivw)[jj];
    3832                 if(A[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::replaceDouble_ringorder_a_ByASingleOne!\n");
     3840                if((*ivw)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::replaceDouble_ringorder_a_ByASingleOne!\n");
    38333841        }       
    3834         delete ivw;
     3842//      delete ivw;
    38353843        replacementRing->wvhdl[0]=(int *)A;
    38363844        replacementRing->block1[0]=length;
     
    40474055                        {
    40484056                                string weight;
    4049                                 weight=line.substr(0,line.find_first_of(",)"));                         
    4050                                 (*iv)[ii]=atol(weight.c_str());//Better to long. Weight bound in Singular:2147483647
     4057                                weight=line.substr(0,line.find_first_of(",)"));
     4058                                char *w=new char[weight.size()+1];
     4059                                strcpy(w,weight.c_str());
     4060                                (*iv)[ii]=atol(w/*weight.c_str()*/);//Better to long. Weight bound in Singular:2147483647
     4061                                delete[] w;
    40514062                                line.erase(0,line.find_first_of(",)")+1);
    40524063                        }
     
    40854096                        getline(gcInputFile, line);
    40864097                        strGcBasisLength = line;
    4087                         int size=atoi(strGcBasisLength.c_str());
     4098                        char *s=new char[strGcBasisLength.size()+1];
     4099                        strcpy(s,strGcBasisLength.c_str());
     4100                        int size=atoi(s/*strGcBasisLength.c_str()*/);
     4101                        delete[] s;
    40884102                        gcBasisLength=size;             
    40894103                        gc->gcBasis=idInit(size,1);
     
    41034117                                {
    41044118                                        poly strPoly;//=pInit();
    4105                                         number nCoeff=nInit(1);
    4106                                         number nCoeffNom=nInit(1);
    4107                                         number nCoeffDenom=nInit(1);
     4119                                       
    41084120                                        string strMonom, strCoeff, strCoeffNom, strCoeffDenom;
    41094121                                        bool hasCoeffInQ = FALSE;       //does the polynomial have rational coeff?
     
    41234135                                        strMonom = line.substr(0,found);
    41244136                                        line.erase(0,found);
     4137                                        number nCoeff=nInit(1);
     4138                                        number nCoeffNom=nInit(1);
     4139                                        number nCoeffDenom=nInit(1);
    41254140                                        found = strMonom.find_first_of("/");
    41264141                                        if(found!=string::npos) //i.e. "/" exists in strMonom
     
    41304145                                                strCoeffDenom=strMonom.substr(found+1,strMonom.find_first_not_of("1234567890",found+1));
    41314146                                                strMonom.erase(0,found);
    4132                                                 strMonom.erase(0,strMonom.find_first_not_of("1234567890/"));                   
    4133                                                 nRead(strCoeffNom.c_str(), &nCoeffNom);
    4134                                                 nRead(strCoeffDenom.c_str(), &nCoeffDenom);
     4147                                                strMonom.erase(0,strMonom.find_first_not_of("1234567890/"));   
     4148                                                char *Nom=new char[strCoeffNom.size()+1];
     4149                                                char *Denom=new char[strCoeffDenom.size()+1];
     4150                                                strcpy(Nom,strCoeffNom.c_str());
     4151                                                strcpy(Denom,strCoeffDenom.c_str());           
     4152                                                nRead(Nom/*strCoeffNom.c_str()*/, &nCoeffNom);
     4153                                                nRead(Denom/*strCoeffDenom.c_str()*/, &nCoeffDenom);
     4154                                                delete[] Nom;
     4155                                                delete[] Denom;
    41354156                                        }
    41364157                                        else
    41374158                                        {
    41384159                                                found = strMonom.find_first_not_of("1234567890");
    4139                                                 strCoeff = strMonom.substr(0,found);
     4160                                                strCoeff = strMonom.substr(0,found);                                           
    41404161                                                if(!strCoeff.empty())
    41414162                                                {
    4142                                                         nRead(strCoeff.c_str(),&nCoeff);
     4163                                                        char *coeff = new char[strCoeff.size()+1];
     4164                                                        strcpy(coeff, strCoeff.c_str());
     4165                                                        nRead(coeff/*strCoeff.c_str()*/,&nCoeff);
     4166                                                        delete[] coeff;
    41434167                                                }
    4144                                                 else
    4145                                                 {
    4146 //                                                      intCoeff = 1;
    4147                                                         nCoeff = nInit(1);
    4148                                                 }
    4149                                                                                                
    41504168                                        }
    4151                                         const char* monom = strMonom.c_str();                                   
    4152                                                
    4153                                         p_Read(monom,strPoly,currRing); //strPoly:=monom                               
     4169                                        char* monom = new char[strMonom.size()+1];
     4170                                        strcpy(monom, strMonom.c_str());                                               
     4171                                        p_Read(monom,strPoly,currRing); //strPoly:=monom
     4172                                        delete[] monom;
    41544173                                        switch (hasCoeffInQ)
    41554174                                        {
     
    41644183                                                        if(!nIsOne(nCoeff))
    41654184                                                        {
    4166 //                                                              if(hasNegCoeff)
    4167 //                                                                      intCoeff *= -1;
    4168 //                                                              pSetCoeff(strPoly,(number) intCoeff);
    41694185                                                                pSetCoeff(strPoly, nCoeff );
    41704186                                                        }
    41714187                                                        break;
    4172                                                                                                        
    41734188                                        }
    41744189                                                //pSetCoeff(strPoly, (number) intCoeff);//Why is this set to zero instead of 1???
    41754190                                        if(pIsConstantComp(resPoly))
    4176                                                 resPoly=pCopy(strPoly);                                                 
     4191                                        {
     4192                                                resPoly=pCopy(strPoly);
     4193                                                pDelete(&strPoly);
     4194                                        }
    41774195                                        else
     4196                                        {
     4197//                                              poly tmp=pAdd(pCopy(resPoly),strPoly);//foo is destroyed
     4198//                                              pDelete(&resPoly);
     4199//                                              resPoly=tmp;
     4200//                                              pDelete(&tmp);
    41784201                                                resPoly=pAdd(resPoly,strPoly);//pAdd = p_Add_q, destroys args
    4179 //                                      nDelete(&nCoeff);
     4202                                        }
     4203                                        /*if(nCoeff!=NULL)                                     
     4204                                                nDelete(&nCoeff);*/ //NOTE This may cause a crash on certain examples...
    41804205                                        nDelete(&nCoeffNom);
    41814206                                        nDelete(&nCoeffDenom);
    4182 //                                      pDelete(&strPoly);
    41834207                                }//while(!line.empty())                 
    41844208                                gc->gcBasis->m[jj]=pCopy(resPoly);
    41854209                                pDelete(&resPoly);      //reset
    4186 //                              pDelete(&strPoly);      //NOTE Crashes - already deleted by pAdd                               
    41874210                        }
    41884211//                      break;
     
    42024225                                        found = normalString.find(",");
    42034226                                        component=normalString.substr(0,found);
    4204                                         (*fN)[ii]=atol(component.c_str());
     4227                                        char *sComp = new char[component.size()+1];
     4228                                        strcpy(sComp,component.c_str());
     4229                                        (*fN)[ii]=atol(sComp/*component.c_str()*/);
     4230                                        delete[] sComp;
    42054231                                        normalString.erase(0,found+1);
    42064232                                }
Note: See TracChangeset for help on using the changeset viewer.