Changeset b1e63ac5 for src/libcfa/stdlib
- Timestamp:
- Jul 4, 2017, 9:40:16 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 208e5be
- Parents:
- 9c951e3 (diff), f7cb0bc (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
-
src/libcfa/stdlib
r9c951e3 rb1e63ac5 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 9 08:42:44201713 // Update Count : 10712 // Last Modified On : Fri Jun 2 15:51:03 2017 13 // Update Count : 218 14 14 // 15 15 … … 28 28 //--------------------------------------- 29 29 30 extern "C" { void * malloc( size_t ); } // use default C routine for void * 31 forall( dtype T | sized(T) ) T * malloc( void ); 32 forall( dtype T | sized(T) ) T * malloc( char fill ); 33 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size ); 34 forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill ); 35 extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void * 36 forall( dtype T | sized(T) ) T * calloc( size_t nmemb ); 37 extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void * 38 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ); 39 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill ); 40 41 forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment ); 42 forall( dtype T | sized(T) ) T * memalign( size_t alignment ); // deprecated 43 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment ); 44 45 extern "C" { 46 void * memset( void * ptr, int fill, size_t size ); 47 void free( void * ptr ); 48 } // extern "C" 49 50 forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p ); 51 forall( dtype T | { void ^?{}(T *); } ) void delete( T * ptr ); 52 forall( dtype T, ttype Params | { void ^?{}(T *); void delete(Params); } ) void delete( T * ptr, Params rest ); 30 // allocation, non-array types 31 static inline forall( dtype T | sized(T) ) T * malloc( void ) { 32 //printf( "X1\n" ); 33 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 34 } // malloc 35 36 extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine 37 static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) { 38 //printf( "X2\n" ); 39 return (T *)(void *)calloc( dim, sizeof(T) ); // C cmalloc 40 } 41 42 extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void * 43 static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) { 44 //printf( "X3\n" ); 45 return (T *)(void *)realloc( (void *)ptr, size ); 46 } 47 48 extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void * 49 static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) { 50 //printf( "X4\n" ); 51 return (T *)memalign( align, sizeof(T) ); 52 } // memalign 53 54 static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) { 55 //printf( "X5\n" ); 56 return (T *)memalign( align, sizeof(T) ); 57 } // aligned_alloc 58 59 extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void * 60 static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ) { 61 //printf( "X6\n" ); 62 return posix_memalign( (void **)ptr, align, sizeof(T) ); 63 } // posix_memalign 64 65 66 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void * 67 68 static inline forall( dtype T | sized(T) ) T * alloc( void ) { 69 //printf( "X7\n" ); 70 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 71 } // alloc 72 static inline forall( dtype T | sized(T) ) T * alloc( char fill ) { 73 //printf( "X8\n" ); 74 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 75 return memset( ptr, (int)fill, sizeof(T) ); // initial with fill value 76 } // alloc 77 78 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) { 79 //printf( "X9\n" ); 80 return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 81 } // alloc 82 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) { 83 //printf( "X10\n" ); 84 T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 85 return memset( ptr, (int)fill, dim * sizeof(T) ); 86 } // alloc 87 88 static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) { 89 //printf( "X11\n" ); 90 return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 91 } // alloc 92 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 93 94 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align ) { 95 //printf( "X13\n" ); 96 return (T *)memalign( align, sizeof(T) ); 97 } // align_alloc 98 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ) { 99 //printf( "X14\n" ); 100 T * ptr = (T *)memalign( align, sizeof(T) ); 101 return memset( ptr, (int)fill, sizeof(T) ); 102 } // align_alloc 103 104 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) { 105 //printf( "X15\n" ); 106 return (T *)memalign( align, dim * sizeof(T) ); 107 } // align_alloc 108 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) { 109 //printf( "X16\n" ); 110 T * ptr = (T *)memalign( align, dim * sizeof(T) ); 111 return memset( ptr, (int)fill, dim * sizeof(T) ); 112 } // align_alloc 113 114 115 // data, non-array types 116 static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) { 117 //printf( "X17\n" ); 118 return memset( dest, c, sizeof(T) ); 119 } // memset 120 extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void * 121 static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) { 122 //printf( "X18\n" ); 123 return memcpy( dest, src, sizeof(T) ); 124 } // memcpy 125 126 // data, array types 127 static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) { 128 //printf( "X19\n" ); 129 return (void *)memset( dest, c, dim * sizeof(T) ); // C memset 130 } // memset 131 static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) { 132 //printf( "X20\n" ); 133 return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy 134 } // memcpy 135 136 // allocation/deallocation and constructor/destructor, non-array types 137 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p ); 138 forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr ); 139 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 140 141 // allocation/deallocation and constructor/destructor, array types 142 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p ); 143 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] ); 144 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest ); 53 145 54 146 //--------------------------------------- … … 83 175 84 176 forall( otype T | { int ?<?( T, T ); } ) 85 T * bsearch( T key, const T * arr, size_t dim ension);86 87 forall( otype T | { int ?<?( T, T ); } ) 88 unsigned int bsearch( T key, const T * arr, size_t dim ension);89 90 91 forall( otype T | { int ?<?( T, T ); } ) 92 void qsort( const T * arr, size_t dim ension);177 T * bsearch( T key, const T * arr, size_t dim ); 178 179 forall( otype T | { int ?<?( T, T ); } ) 180 unsigned int bsearch( T key, const T * arr, size_t dim ); 181 182 183 forall( otype T | { int ?<?( T, T ); } ) 184 void qsort( const T * arr, size_t dim ); 93 185 94 186 //--------------------------------------- … … 109 201 double abs( double _Complex ); 110 202 long double abs( long double _Complex ); 111 forall 203 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } ) 112 204 T abs( T ); 113 205 … … 115 207 116 208 void rand48seed( long int s ); 117 char rand48( );118 int rand48( );119 unsigned int rand48( );120 long int rand48( );121 unsigned long int rand48( );122 float rand48( );123 double rand48( );124 float _Complex rand48( );125 double _Complex rand48( );126 long double _Complex rand48( );209 char rand48( void ); 210 int rand48( void ); 211 unsigned int rand48( void ); 212 long int rand48( void ); 213 unsigned long int rand48( void ); 214 float rand48( void ); 215 double rand48( void ); 216 float _Complex rand48( void ); 217 double _Complex rand48( void ); 218 long double _Complex rand48( void ); 127 219 128 220 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.