Changeset 856fe3e for libcfa/src
- Timestamp:
- May 13, 2020, 6:33:04 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:
- 2223c80
- Parents:
- 0e7e3c17
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r0e7e3c17 r856fe3e 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 16 22:44:05202013 // Update Count : 43 212 // Last Modified On : Wed May 13 17:23:51 2020 13 // Update Count : 435 14 14 // 15 15 … … 23 23 // Reduce includes by explicitly defining these routines. 24 24 extern "C" { 25 void * aalloc( size_t dim, size_t elemSize ); // CFA heap 26 void * resize( void * oaddr, size_t size ); // CFA heap 25 27 void * memalign( size_t align, size_t size ); // malloc.h 28 void * amemalign( size_t align, size_t dim, size_t elemSize ); // CFA heap 29 void * cmemalign( size_t align, size_t noOfElems, size_t elemSize ); // CFA heap 30 size_t malloc_size( void * addr ); // CFA heap 26 31 size_t malloc_usable_size( void * ptr ); // malloc.h 27 size_t malloc_size( void * addr ); // CFA heap28 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA heap29 32 void * memset( void * dest, int fill, size_t size ); // string.h 30 33 void * memcpy( void * dest, const void * src, size_t size ); // string.h 31 void * resize( void * oaddr, size_t size ); // CFA heap32 34 } // extern "C" 33 35 … … 52 54 } // malloc 53 55 56 T * aalloc( size_t dim ) { 57 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)aalloc( dim, (size_t)sizeof(T) ); // CFA aalloc 58 else return (T *)amemalign( _Alignof(T), dim, sizeof(T) ); 59 } // aalloc 60 54 61 T * calloc( size_t dim ) { 55 62 if ( _Alignof(T) <= libAlign() )return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc … … 57 64 } // calloc 58 65 66 T * resize( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 67 return (T *)(void *)resize( (void *)ptr, size ); // C realloc 68 } // resize 69 59 70 T * realloc( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 60 71 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc … … 65 76 } // memalign 66 77 78 T * amemalign( size_t align, size_t dim ) { 79 return (T *)amemalign( align, dim, sizeof(T) ); // CFA amemalign 80 } // amemalign 81 67 82 T * cmemalign( size_t align, size_t dim ) { 68 83 return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign … … 86 101 87 102 T * alloc( size_t dim ) { 88 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); 89 else return (T *)memalign( _Alignof(T), dim * sizeof(T) ); 103 return aalloc( dim ); 90 104 } // alloc 91 105 … … 106 120 return (T *)(void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc 107 121 } else { 108 struct __Unknown {}; 109 return alloc( (__Unknown *)ptr, dim ); // reuse, cheat making T/S different types 122 return resize( ptr, dim * sizeof(T) ); // resize 110 123 } // if 111 124 } // alloc … … 148 161 } // alloc_align 149 162 150 T * alloc_align( T ptr[], size_t align ) { // aligned realloc array163 T * alloc_align( T * ptr, size_t align ) { // aligned realloc array 151 164 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc 152 165 } // alloc_align
Note: See TracChangeset
for help on using the changeset viewer.