Changeset 366350 in git


Ignore:
Timestamp:
Mar 21, 2017, 1:46:42 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a271160a1532d13b51fd4fe8bcf0dd9b02490b5b
Parents:
8acf08c8c3f734aad67eab7e7b403203224fb8d0
Message:
xalloc: test for malloc_usable_size
Location:
xalloc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • xalloc/configure.ac

    r8acf08 r366350  
    6666AC_CHECK_HEADERS(unistd.h sys/mman.h fcntl.h /usr/include/malloc.h)
    6767
    68 AC_CHECK_FUNCS(popen mmap sbrk random)
     68AC_CHECK_FUNCS(popen mmap sbrk random malloc_usable_size)
    6969
    7070dnl llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
  • xalloc/omalloc.h

    r8acf08 r366350  
    6868
    6969static inline void * omalloc(size_t s)
    70 { if (s!=0) {long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; }
     70{ if (s!=0)
     71#ifdef HAVE_MALLOC_USABLE_SIZE
     72   { return malloc(s); }
     73#else
     74  {long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; }
     75#endif
    7176  else return NULL;
    7277}
    7378static inline void * omAlloc(size_t s)
     79#ifdef HAVE_MALLOC_USABLE_SIZE
     80{ return malloc(s); }
     81#else
    7482{ long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; }
     83#endif
    7584static inline void * omAlloc0(size_t s)
    7685{ void *d=omAlloc(s);memset(d,0,s); return d; }
     
    8190{ if (d==NULL) return omAlloc(ns);
    8291  else
     92#ifdef HAVE_MALLOC_USABLE_SIZE
     93  return realloc(d,ns);
     94#else
    8395  {
    8496    long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long));
    8597    *dd=ns+sizeof(long);dd++; return dd;
    8698  }
     99#endif
    87100}
    88101#define omReallocAligned(A,B) omRealloc(A,B)
     
    90103{ if (d==NULL) return omAlloc(ns);
    91104  else
     105#ifdef HAVE_MALLOC_USABLE_SIZE
     106  return realloc(d,ns);
     107#else
    92108  {
    93109    long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long));
    94110    *dd=ns+sizeof(long);dd++; return dd;
    95111  }
     112#endif
    96113}
    97114static inline long omSizeOfAddr(void *d)
     115#ifdef HAVE_MALLOC_USABLE_SIZE
     116{ return malloc_usable_size(d); }
     117#else
    98118{ long *dd=(long*)d; dd--; return *dd;}
     119#endif
    99120
    100121static inline void omFree(void *d)
     122#ifdef HAVE_MALLOC_USABLE_SIZE
     123{ free(d); }
     124#else
    101125{ if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}}
     126#endif
    102127
    103128static inline void *omRealloc0(void *d, size_t ns)
    104129{
     130#ifdef HAVE_MALLOC_USABLE_SIZE
     131  void *n=realloc(d,ns);
     132  memset(n,0,ns);
     133#else
    105134  void *n=omAlloc0(ns);
    106135  if (d!=NULL)
     
    112141    omFree(d);
    113142  }
     143#endif
    114144  return n;
    115145}
    116146static inline void omFreeSize(void *d, __attribute__((unused)) size_t s)
     147#ifdef HAVE_MALLOC_USABLE_SIZE
     148{ free(d); }
     149#else
    117150{ if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}}
     151#endif
    118152
    119153static inline char * omStrDup(const char *s)
     
    122156}
    123157static inline void * omMemDup(void * s)
     158#ifdef HAVE_MALLOC_USABLE_SIZE
     159{ size_t l=malloc_usable_size(s);
     160  void *n=malloc(l);
     161  memcpy(n,s,l);
     162  return n;
     163}
     164#else
    124165{ long *n;long *d=(long*)s; d--;
    125166  n=(long*)malloc(*d+sizeof(long));
     
    128169  return n;
    129170}
     171#endif
    130172
    131173/* #define omSizeWOfBin(bin_ptr) ((bin_ptr)->sizeW) */
Note: See TracChangeset for help on using the changeset viewer.