Changeset 71dfe49 for libcfa/src/stdlib.hfa
- Timestamp:
- Aug 4, 2020, 12:53:48 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 954821df
- Parents:
- 8395152 (diff), 2ff42f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r8395152 r71dfe49 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jul 21 07:58:05202013 // Update Count : 4 7512 // Last Modified On : Thu Jul 30 16:14:58 2020 13 // Update Count : 490 14 14 // 15 15 … … 71 71 T * resize( T * ptr, size_t size ) { // CFA resize, eliminate return-type cast 72 72 $RE_SPECIALS( ptr, size, malloc, memalign ); 73 return (T *)(void *)resize( (void *)ptr, size ); // CFA resize 73 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)resize( (void *)ptr, size ); // CFA resize 74 else return (T *)(void *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize 74 75 } // resize 75 76 76 77 T * realloc( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 77 78 $RE_SPECIALS( ptr, size, malloc, memalign ); 78 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc 79 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)realloc( (void *)ptr, size ); // C realloc 80 else return (T *)(void *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc 79 81 } // realloc 80 82 … … 121 123 forall( dtype S | sized(S) ) 122 124 T * alloc( S ptr[], size_t dim = 1 ) { // singleton/array resize 123 size_t len = malloc_usable_size( ptr ); // current bucket size 124 if ( sizeof(T) * dim > len ) { // not enough space ? 125 T * temp = alloc( dim ); // new storage 126 free( ptr ); // free old storage 127 return temp; 128 } else { 129 return (T *)ptr; 130 } // if 131 } // alloc 132 133 T * alloc( T ptr[], size_t dim, bool copy = true ) { 125 return resize( (T *)ptr, dim * sizeof(T) ); // CFA resize 126 } // alloc 127 128 T * alloc( T ptr[], size_t dim = 1, bool copy = true ) { 134 129 if ( copy ) { 135 130 return realloc( ptr, dim * sizeof(T) ); // CFA realloc … … 168 163 memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage 169 164 } // if 170 return (T *)nptr;165 return nptr; 171 166 } // alloc_set 172 167 … … 181 176 } // for 182 177 } // if 183 return (T *)nptr;178 return nptr; 184 179 } // alloc_align_set 185 180 } // distribution … … 195 190 196 191 T * alloc_align( T * ptr, size_t align ) { // aligned realloc array 197 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc192 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA C realloc 198 193 } // alloc_align 199 194 … … 232 227 size_t osize = malloc_size( ptr ); // current allocation 233 228 size_t nsize = dim * sizeof(T); // new allocation 234 T * nptr = alloc_align( ptr, align, nsize ); // CFA alloc_align229 T * nptr = alloc_align( ptr, align, nsize ); 235 230 if ( nsize > osize ) { // larger ? 236 231 memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage 237 232 } // if 238 return (T *)nptr;233 return nptr; 239 234 } // alloc_align_set 240 235 … … 243 238 size_t nsize = dim * sizeof(T); // new allocation 244 239 size_t ndim = nsize / sizeof(T); // new dimension 245 T * nptr = alloc_align( ptr, align, nsize ); // CFA alloc_align240 T * nptr = alloc_align( ptr, align, nsize ); 246 241 if ( ndim > odim ) { // larger ? 247 242 for ( i; odim ~ ndim ) { … … 249 244 } // for 250 245 } // if 251 return (T *)nptr;246 return nptr; 252 247 } // alloc_align_set 253 248 } // distribution
Note: See TracChangeset
for help on using the changeset viewer.