Changeset 366350 in git
- Timestamp:
- Mar 21, 2017, 1:46:42 PM (7 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- a271160a1532d13b51fd4fe8bcf0dd9b02490b5b
- Parents:
- 8acf08c8c3f734aad67eab7e7b403203224fb8d0
- Location:
- xalloc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
xalloc/configure.ac
r8acf08 r366350 66 66 AC_CHECK_HEADERS(unistd.h sys/mman.h fcntl.h /usr/include/malloc.h) 67 67 68 AC_CHECK_FUNCS(popen mmap sbrk random )68 AC_CHECK_FUNCS(popen mmap sbrk random malloc_usable_size) 69 69 70 70 dnl llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll -
xalloc/omalloc.h
r8acf08 r366350 68 68 69 69 static 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 71 76 else return NULL; 72 77 } 73 78 static inline void * omAlloc(size_t s) 79 #ifdef HAVE_MALLOC_USABLE_SIZE 80 { return malloc(s); } 81 #else 74 82 { long *d=(long*)malloc(s+sizeof(long)); *d=s;d++;return d; } 83 #endif 75 84 static inline void * omAlloc0(size_t s) 76 85 { void *d=omAlloc(s);memset(d,0,s); return d; } … … 81 90 { if (d==NULL) return omAlloc(ns); 82 91 else 92 #ifdef HAVE_MALLOC_USABLE_SIZE 93 return realloc(d,ns); 94 #else 83 95 { 84 96 long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long)); 85 97 *dd=ns+sizeof(long);dd++; return dd; 86 98 } 99 #endif 87 100 } 88 101 #define omReallocAligned(A,B) omRealloc(A,B) … … 90 103 { if (d==NULL) return omAlloc(ns); 91 104 else 105 #ifdef HAVE_MALLOC_USABLE_SIZE 106 return realloc(d,ns); 107 #else 92 108 { 93 109 long *dd=(long*)d; dd--; dd=(long*)realloc(dd,ns+sizeof(long)); 94 110 *dd=ns+sizeof(long);dd++; return dd; 95 111 } 112 #endif 96 113 } 97 114 static inline long omSizeOfAddr(void *d) 115 #ifdef HAVE_MALLOC_USABLE_SIZE 116 { return malloc_usable_size(d); } 117 #else 98 118 { long *dd=(long*)d; dd--; return *dd;} 119 #endif 99 120 100 121 static inline void omFree(void *d) 122 #ifdef HAVE_MALLOC_USABLE_SIZE 123 { free(d); } 124 #else 101 125 { if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}} 126 #endif 102 127 103 128 static inline void *omRealloc0(void *d, size_t ns) 104 129 { 130 #ifdef HAVE_MALLOC_USABLE_SIZE 131 void *n=realloc(d,ns); 132 memset(n,0,ns); 133 #else 105 134 void *n=omAlloc0(ns); 106 135 if (d!=NULL) … … 112 141 omFree(d); 113 142 } 143 #endif 114 144 return n; 115 145 } 116 146 static inline void omFreeSize(void *d, __attribute__((unused)) size_t s) 147 #ifdef HAVE_MALLOC_USABLE_SIZE 148 { free(d); } 149 #else 117 150 { if (d!=NULL) { long *dd=(long*)d; dd--; free(dd);}} 151 #endif 118 152 119 153 static inline char * omStrDup(const char *s) … … 122 156 } 123 157 static 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 124 165 { long *n;long *d=(long*)s; d--; 125 166 n=(long*)malloc(*d+sizeof(long)); … … 128 169 return n; 129 170 } 171 #endif 130 172 131 173 /* #define omSizeWOfBin(bin_ptr) ((bin_ptr)->sizeW) */
Note: See TracChangeset
for help on using the changeset viewer.