Changeset b335e35 in git


Ignore:
Timestamp:
Jan 17, 2022, 2:16:09 PM (17 months ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
4c1b5d9a51feb5ce7896c89dcb0b4db3768454fb
Parents:
2d5c1931cd9af26341282db39ce50f9e5ae279ff
Message:
xalloc: omMemDup, omRealloc0
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/ideals.cc

    r2d5c19 rb335e35  
    17341734      block1[k+1] = origR->block1[k];
    17351735      ord[k+1] = origR->order[k];
    1736       if (origR->wvhdl[k]!=NULL) wv[k+1] = (int*) omMemDup(origR->wvhdl[k]);
     1736      if (origR->wvhdl[k]!=NULL)
     1737      #ifdef HAVE_OMALLOC
     1738        wv[k+1] = (int*) omMemDup(origR->wvhdl[k]);
     1739      #else
     1740      {
     1741        int l=(origR->block1[k]-origR->block0[k]+1)*sizeof(int);
     1742        wv[k+1]=(int*)omalloc(l);
     1743        memcpy(wv[k+1],origR->wvhdl[k],l);
     1744      }
     1745      #endif
    17371746    }
    17381747    block0[0] = 1;
  • libpolys/polys/monomials/ring.cc

    r2d5c19 rb335e35  
    982982        tmpR.order[1]=r2->order[0];
    983983        if (r2->wvhdl[0]!=NULL)
     984        #ifdef HAVE_OMALLOC
    984985          tmpR.wvhdl[1]=(int *)omMemDup(r2->wvhdl[0]);
     986        #else
     987        {
     988          int l=(r2->block1[0]-r2->block0[0]+1)*sizeof(int);
     989          tmpR.wvhdl[1]=(int*)omalloc(l);
     990          memcpy(tmpR.wvhdl[1],r2->wvhdl[0],l);
     991        }
     992        #endif
    985993      }
    986994      else
     
    10601068          tmpR.block1[i]=r1->block1[i];
    10611069          if (r1->wvhdl[i]!=NULL)
     1070          #ifdef HAVE_OMALLOC
    10621071            tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]);
     1072          #else
     1073          {
     1074            int l=(r1->block1[i]-r1->block0[i]+1)*sizeof(int);
     1075            tmpR.wvhdl[i]=(int*)omalloc(l);
     1076            memcpy(tmpR.wvhdl[i],r1->wvhdl[i],l);
     1077          }
     1078          #endif
    10631079        }
    10641080        j=i;
     
    10801096            if (r2->wvhdl[i]!=NULL)
    10811097            {
     1098              #ifdef HAVE_OMALLOC
    10821099              tmpR.wvhdl[j] = (int*) omMemDup(r2->wvhdl[i]);
     1100              #else
     1101              {
     1102                int l=(r2->block1[i]-r2->block0[i]+1)*sizeof(int);
     1103                tmpR.wvhdl[j]=(int*)omalloc(l);
     1104                memcpy(tmpR.wvhdl[j],r2->wvhdl[i],l);
     1105              }
     1106              #endif
    10831107            }
    10841108            j++;
     
    11071131        if (r1->wvhdl[i]!=NULL)
    11081132        {
     1133          #ifdef HAVE_OMALLOC
    11091134          tmpR.wvhdl[i] = (int*) omMemDup(r1->wvhdl[i]);
     1135          #else
     1136          {
     1137            int l=(r1->block1[i]-r1->block0[i]+1)*sizeof(int);
     1138            tmpR.wvhdl[i]=(int*)omalloc(l);
     1139            memcpy(tmpR.wvhdl[i],r1->wvhdl[i],l);
     1140          }
     1141          #endif
    11101142        }
    11111143      }
     
    14471479      if (r->wvhdl[j]!=NULL)
    14481480      {
     1481        #ifdef HAVE_OMALLOC
    14491482        res->wvhdl[j] = (int*) omMemDup(r->wvhdl[j]);
     1483        #else
     1484        {
     1485          int l=(r->block1[j]-r->block0[j]+1)*sizeof(int);
     1486          res->wvhdl[j]=(int*)omalloc(l);
     1487          memcpy(res->wvhdl[j],r->wvhdl[j],l);
     1488        }
     1489        #endif
    14501490      }
    14511491      else
     
    15771617      if (r->wvhdl[j]!=NULL)
    15781618      {
     1619        #ifdef HAVE_OMALLOC
    15791620        res->wvhdl[j+1] = (int*) omMemDup(r->wvhdl[j]); //DIFF
     1621        #else
     1622        {
     1623          int l=(r->block1[j]-r->block0[j]+1)*sizeof(int);
     1624          res->wvhdl[j+1]=(int*)omalloc(l);
     1625          memcpy(res->wvhdl[j+1],r->wvhdl[j],l);
     1626        }
     1627        #endif
    15801628      }
    15811629      else
     
    22392287
    22402288static void rO_WDegree64(int &place, int &bitplace, int start, int end,
    2241     long *o, sro_ord &ord_struct, int64 *weights)
     2289    long *o, sro_ord &ord_struct, int *weights)
    22422290{
    22432291  // weighted degree (aligned) of variables v_start..v_end, ordsgn 1,
     
    22482296  ord_struct.data.wp64.end=end;
    22492297  ord_struct.data.wp64.place=place;
    2250   ord_struct.data.wp64.weights64=weights;
     2298  int l=end-start+1;
     2299  ord_struct.data.wp64.weights64=(int64*)omAlloc(l*sizeof(int64));
     2300  for(int i=0;i<l;i++) ord_struct.data.wp64.weights64[i]=weights[i];
    22512301  o[place]=1;
    22522302  place++;
     
    24002450
    24012451static void rO_ISPrefix(int &place, int &bitplace, int &prev_ord,
    2402     long *o, int /*N*/, int *v, sro_ord &ord_struct)
     2452    long *o, int N, int *v, sro_ord &ord_struct)
    24032453{
    24042454  if ((prev_ord== 1) || (bitplace!=BITS_PER_LONG))
     
    24082458  ord_struct.ord_typ = ro_isTemp;
    24092459  ord_struct.data.isTemp.start = place;
     2460  #ifdef HAVE_OMALLOC
    24102461  ord_struct.data.isTemp.pVarOffset = (int *)omMemDup(v);
     2462  #else
     2463  ord_struct.data.isTemp.pVarOffset = (int *)omAlloc((N+1)*sizeof(int));
     2464                          memcpy(ord_struct.data.isTemp.pVarOffset,v,(N+1)*sizeof(int));
     2465  #endif
    24112466  ord_struct.data.isTemp.suffixpos = -1;
    24122467
     
    34433498      case ringorder_a64:
    34443499        rO_WDegree64(j,j_bits,r->block0[i],r->block1[i],tmp_ordsgn,
    3445                      tmp_typ[typ_i], (int64 *)(r->wvhdl[i]));
     3500                     tmp_typ[typ_i], r->wvhdl[i]);
    34463501        typ_i++;
    34473502        break;
     
    41814236          int l;
    41824237          for(l=r->typ[j].data.wp64.start;l<=r->typ[j].data.wp64.end;l++)
    4183             Print(" %ld",(long)(((int64*)r->typ[j].data.wp64.weights64)+l-r->typ[j].data.wp64.start));
     4238            Print(" %ld",(long)(r->typ[j].data.wp64.weights64+l-r->typ[j].data.wp64.start);
    41844239          }
    41854240        }
     
    44424497    if (r->wvhdl[j-1] != NULL)
    44434498    {
     4499      #ifdef HAVE_OMALLOC
    44444500      wvhdl[j] = (int*) omMemDup(r->wvhdl[j-1]);
     4501      #else
     4502      {
     4503        int l=(r->block1[j-1]-r->block0[j-1]+1)*sizeof(int);
     4504        wvhdl[j]=(int*)omalloc(l);
     4505        memcpy(wvhdl[j],r->wvhdl[j-1],l);
     4506      }
     4507      #endif
    44454508    }
    44464509  }
     
    46204683    if (r->wvhdl[j]!=NULL)
    46214684    {
     4685      #ifdef HAVE_OMALLOC
    46224686      new_r->wvhdl[j] = (int*) omMemDup(r->wvhdl[j]);
     4687      #else
     4688      {
     4689        int l=(r->block1[j]-r->block0[j]+1)*sizeof(int);
     4690        new_r->wvhdl[j]=(int*)omalloc(l);
     4691        memcpy(new_r->wvhdl[j],r->wvhdl[j],l);
     4692      }
     4693      #endif
    46234694    }
    46244695  }
     
    48444915    if (r->wvhdl[i] != NULL)
    48454916    {
     4917      #ifdef HAVE_OMALLOC
    48464918      wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
     4919      #else
     4920      {
     4921        int l=(r->block1[i]-r->block0[i]+1)*sizeof(int);
     4922        wvhdl[j]=(int*)omalloc(l);
     4923        memcpy(wvhdl[j],r->wvhdl[i],l);
     4924      }
     4925      #endif
    48474926    } // else wvhdl[j] = NULL;
    48484927  }
     
    51885267  int i=0;
    51895268  while((r->typ[i].ord_typ!=ro_wp64) && (r->typ[i].ord_typ>0)) i++;
    5190   assume(r->typ[i].ord_typ==ro_wp64);
    5191   return (int64*)(r->typ[i].data.wp64.weights64);
     5269  if (r->typ[i].ord_typ!=ro_wp64) return NULL; /* should not happen*/
     5270  return r->typ[i].data.wp64.weights64;
    51925271}
    51935272
  • libpolys/reporter/s_buff.cc

    r2d5c19 rb335e35  
    241241    if (str_p>=str_l)
    242242    {
     243      int old_str_l=str_l;
    243244      str_l=str_l*2;
    244       str=(char*)omRealloc0(str,str_l);
     245      str=(char*)omRealloc(str,str_l);
     246      memset(str+old_str_l,0,old_str_l);
    245247    }
    246248    c=s_getc(F);
  • omalloc/xalloc.h

    r2d5c19 rb335e35  
    1313#include <string.h>
    1414#include "omalloc/omConfig.h"
    15 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    16   #ifdef HAVE_MALLOC_H
    17   #include <malloc.h>
    18   #elif defined(HAVE_MALLOC_MALLOC_H)
    19   #include <malloc/malloc.h>
    20   #endif
    21 #endif
    2215#ifdef __cplusplus
    2316extern "C" {
     
    8578extern int om_sing_opt_show_mem;
    8679
    87 static inline void * omalloc(size_t s)
    88 { if (s!=0)
    89 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    90    { return malloc(s); }
    91 #else
    92   {long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; }
    93 #endif
    94   else return NULL;
    95 }
    96 static inline void * omAlloc(size_t s)
    97 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    98 { return malloc(s); }
    99 #else
    100 { long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; }
    101 #endif
     80#define omalloc(s) malloc(s)
     81#define omAlloc(s) malloc(s)
     82
    10283static inline void * omAlloc0(size_t s)
    10384{ void *d=omAlloc(s);memset(d,0,s); return d; }
     
    10889{ if (d==NULL) return omAlloc(ns);
    10990  else
    110 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    11191  return realloc(d,ns);
    112 #else
    113   {
    114     long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long));
    115     *dd=ns+sizeof(long);dd++; return dd;
    116   }
    117 #endif
    11892}
    11993#define omReallocAligned(A,B) omRealloc(A,B)
     
    12195{ if (d==NULL) return omAlloc(ns);
    12296  else
    123 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    12497  return realloc(d,ns);
    125 #else
    126   {
    127     long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long));
    128     *dd=ns+sizeof(long);dd++; return dd;
    129   }
    130 #endif
    131 }
    132 static inline long omSizeOfAddr(void *d)
    133 #ifdef HAVE_MALLOC_USABLE_SIZE
    134 { return malloc_usable_size(d); }
    135 #elif defined(HAVE_AMLLOC_SIZE)
    136 { return malloc_size(d); }
    137 #else
    138 { long *dd=(long*)d; dd--; return *dd;}
    139 #endif
    140 
    141 static inline void omfree(void *d)
    142 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    143 { free(d); }
    144 #else
    145 { if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}}
    146 #endif
    147 
    148 static inline void omFree(void *d)
    149 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    150 { free(d); }
    151 #else
    152 { long *dd=(long*)d; dd--; free(dd);}
    153 #endif
    154 
    155 static inline void *omRealloc0(void *d, size_t ns)
    156 {
    157 #ifdef HAVE_MALLOC_USABLE_SIZE
    158   size_t os=0;
    159   if (d!=NULL) os=malloc_usable_size(d);
    160   if (os>=ns)
    161   {
    162     void *n=realloc(d,ns);
    163     return n;
    164   }
     98}
     99
     100static inline void *omRealloc0Size(void *d, __attribute__((unused)) size_t os, size_t ns)
     101{ if (d==NULL)
     102    return omAlloc0(ns);
    165103  else
    166104  {
    167     char *n=(char*)realloc(d,ns);
    168     memset(n+(ns-os),0,ns-os);
    169     return (void*)n;
     105    char *p=(char *)realloc(d,ns);
     106    if (ns>os) memset(p+os,0,ns-os);
     107    return (void*)p;
    170108  }
    171 #elif defined(HAVE_MALLOC_SIZE)
    172   size_t os=0;
    173   if (d!=NULL) os=malloc_size(d);
    174   if (os>=ns)
    175   {
    176     void *n=realloc(d,ns);
    177     return n;
    178   }
    179   else
    180   {
    181     char *n=(char*)realloc(d,ns);
    182     memset(n+(ns-os),0,ns-os);
    183     return (void*)n;
    184   }
    185 #else
    186   void *n=omAlloc0(ns);
    187   if (d!=NULL)
    188   {
    189     size_t c;
    190     size_t os=omSizeOfAddr(d);
    191     if (ns>os) c=os; else c=ns;
    192     memcpy(n,d,c);
    193     omFree(d);
    194   }
    195   return n;
    196 #endif
    197 }
    198 static inline void omFreeSize(void *d, __attribute__((unused)) size_t s)
    199 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE)
    200 { free(d); }
    201 #else
    202 { if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}}
    203 #endif
     109}
     110
     111#define omfree(d) free(d)
     112#define omFree(d) free(d)
     113#define omFreeSize(d,s) free(d)
    204114
    205115static inline char * omStrDup(const char *s)
     
    207117  return strcpy(ns,s);
    208118}
    209 static inline void * omMemDup(void * s)
    210 #ifdef HAVE_MALLOC_USABLE_SIZE
    211 { size_t l=malloc_usable_size(s);
    212   void *n=malloc(l);
    213   memcpy(n,s,l);
    214   return n;
    215 }
    216 #elif defined(HAVE_MALLOC_SIZE)
    217 { size_t l=malloc_size(s);
    218   void *n=malloc(l);
    219   memcpy(n,s,l);
    220   return n;
    221 }
    222 #else
    223 { long *n;long *d=(long*)s; d--;
    224   n=(long*)malloc(*d+sizeof(long));
    225   memcpy(n,d,(*d)+sizeof(long));
    226   n++;
    227   return n;
    228 }
    229 #endif
    230119
    231120/* #define omSizeWOfBin(bin_ptr) ((bin_ptr)->sizeW) */
     
    290179#define omrealloc(A,NS)          omRealloc(A,NS)
    291180#define omreallocSize(A,OS,NS)   omRealloc(A,NS)
    292 #define omRealloc0Size(A,OS,NS)  omRealloc0(A,NS)
    293 #define omrealloc0Size(A,OS,NS)  omRealloc0(A,NS)
     181#define omrealloc0Size(A,OS,NS)  omRealloc0Size(A,OS,NS)
    294182#define omMarkAsStaticAddr(A)
    295 #define omMemCpyW(A,B,S)         memcpy(A,B,(S)<<2)
    296 #define omMemcpyW(A,B,S)         memcpy(A,B,(S)<<2)
    297183#define omGetSpecBin(A)          (A)
    298184#define omUnGetSpecBin(A)        do {} while (0)
    299 #define memcpyW(A,B,C)         memcpy(A,B,(C)*sizeof(long))
    300 #define omGetStickyBinOfBin(B) omGetSpecBin(B)
     185#define omMemcpyW(A,B,C)         memcpy(A,B,(C)*sizeof(long))
     186#define omGetStickyBinOfBin(B)   omGetSpecBin(B)
    301187
    302188
Note: See TracChangeset for help on using the changeset viewer.