Changeset 0f9e4403 for src/libcfa/stdlib.c
- Timestamp:
- Apr 15, 2016, 12:03:11 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 29ad0ac
- Parents:
- c5833e8 (diff), 37f0da8 (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.c
rc5833e8 r0f9e4403 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 10 15:45:56201613 // Update Count : 1 4012 // Last Modified On : Wed Apr 13 14:49:58 2016 13 // Update Count : 155 14 14 // 15 15 … … 27 27 } // extern "C" 28 28 29 forall( type T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 30 printf( "memset1\n" ); 31 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 32 } // memset 33 forall( type T ) T * memset( T * ptr ) { // remove when default value available 34 printf( "memset2\n" ); 35 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 36 } // memset 37 38 forall( type T ) T * malloc( void ) { 39 printf( "malloc1\n" ); 29 forall( otype T ) T * malloc( void ) { 30 //printf( "malloc1\n" ); 40 31 return (T *)malloc( sizeof(T) ); 41 32 } // malloc 42 forall( type T ) T * malloc( size_t size ) { 43 printf( "malloc2\n" ); 44 return (T *)(void *)malloc( size ); 45 } // malloc 46 forall( type T ) T * malloc( char fill ) { 47 printf( "malloc3\n" ); 33 forall( otype T ) T * malloc( char fill ) { 34 //printf( "malloc3\n" ); 48 35 T * ptr = (T *)malloc( sizeof(T) ); 49 36 return memset( ptr ); 50 37 } // malloc 51 38 52 forall( type T ) T * calloc( size_t size) {53 printf( "calloc\n" );54 return (T *)calloc( size, sizeof(T) );39 forall( otype T ) T * calloc( size_t nmemb ) { 40 //printf( "calloc\n" ); 41 return (T *)calloc( nmemb, sizeof(T) ); 55 42 } // calloc 56 43 57 forall( type T ) T * realloc( T * ptr, size_t size ) {58 printf( "realloc1\n" );44 forall( otype T ) T * realloc( T * ptr, size_t size ) { 45 //printf( "realloc1\n" ); 59 46 return (T *)(void *)realloc( (void *)ptr, size ); 60 47 } // realloc 61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {62 printf( "realloc2\n" );48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 49 //printf( "realloc2\n" ); 63 50 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 64 51 size_t unused = malloc_usable_size( nptr ); … … 67 54 } // realloc 68 55 69 forall( type T ) T * malloc( T * ptr, size_t size ) {70 printf( "malloc4\n" );56 forall( otype T ) T * malloc( T * ptr, size_t size ) { 57 //printf( "malloc4\n" ); 71 58 return (T *)realloc( ptr, size ); 72 59 } // malloc 73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {74 printf( "malloc5\n" );60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 61 //printf( "malloc5\n" ); 75 62 return (T *)realloc( ptr, size, fill ); 76 63 } // malloc 77 64 78 forall( type T ) T * aligned_alloc( size_t alignment ) {79 printf( "aligned_alloc\n" );65 forall( otype T ) T * aligned_alloc( size_t alignment ) { 66 //printf( "aligned_alloc\n" ); 80 67 return (T *)memalign( alignment, sizeof(T) ); 81 68 } // aligned_alloc 82 69 83 forall( type T ) T * memalign( size_t alignment ) {84 printf( "memalign\n" );70 forall( otype T ) T * memalign( size_t alignment ) { 71 //printf( "memalign\n" ); 85 72 return (T *)memalign( alignment, sizeof(T) ); 86 73 } // memalign 87 74 88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {89 printf( "posix_memalign\n" );75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) { 76 //printf( "posix_memalign\n" ); 90 77 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 91 78 } // posix_memalign 79 80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 81 //printf( "memset1\n" ); 82 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 83 } // memset 84 forall( otype T ) T * memset( T * ptr ) { // remove when default value available 85 //printf( "memset2\n" ); 86 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 87 } // memset 92 88 93 89 //--------------------------------------- … … 123 119 return ulli; 124 120 } 121 125 122 float ato( const char * ptr ) { 126 123 float f; … … 138 135 return ld; 139 136 } 137 140 138 float _Complex ato( const char * ptr ) { 141 139 float re, im; … … 172 170 return strtoull( sptr, eptr, base ); 173 171 } 172 174 173 float strto( const char * sptr, char ** eptr ) { 175 174 return strtof( sptr, eptr ); … … 181 180 return strtold( sptr, eptr ); 182 181 } 182 183 183 float _Complex strto( const char * sptr, char ** eptr ) { 184 184 float re, im; … … 208 208 //--------------------------------------- 209 209 210 forall( type T | { int ?<?( T, T ); } )210 forall( otype T | { int ?<?( T, T ); } ) 211 211 T * bsearch( const T key, const T * arr, size_t dimension ) { 212 212 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } … … 214 214 } // bsearch 215 215 216 forall( type T | { int ?<?( T, T ); } )216 forall( otype T | { int ?<?( T, T ); } ) 217 217 void qsort( const T * arr, size_t dimension ) { 218 218 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } … … 222 222 //--------------------------------------- 223 223 224 forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )224 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 225 225 [ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ } 226 226 … … 239 239 //--------------------------------------- 240 240 241 void randseed( long int s ) { srand48( s ); } 242 char random() { return lrand48(); } 243 int random() { return mrand48(); } 244 unsigned int random() { return lrand48(); } 245 long int random() { return mrand48(); } 246 unsigned long int random() { return lrand48(); } 247 float random() { return (float)drand48(); } // otherwise float uses lrand48 248 double random() { return drand48(); } 249 float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); } 250 double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); } 251 long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); } 252 253 //--------------------------------------- 254 255 forall( type T | { int ?<?( T, T ); } ) 241 float floor( float v ) { return floorf( v ); } 242 long double floor( long double v ) { return floorl( v ); } 243 244 float ceil( float v ) { return ceilf( v ); } 245 long double ceil( long double v ) { return ceill( v ); } 246 247 //--------------------------------------- 248 249 void rand48seed( long int s ) { srand48( s ); } 250 char rand48() { return mrand48(); } 251 int rand48() { return mrand48(); } 252 unsigned int rand48() { return lrand48(); } 253 long int rand48() { return mrand48(); } 254 unsigned long int rand48() { return lrand48(); } 255 float rand48() { return (float)drand48(); } // otherwise float uses lrand48 256 double rand48() { return drand48(); } 257 float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); } 258 double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); } 259 long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); } 260 261 //--------------------------------------- 262 263 forall( otype T | { int ?<?( T, T ); } ) 256 264 T min( const T t1, const T t2 ) { 257 265 return t1 < t2 ? t1 : t2; 258 266 } // min 259 267 260 forall( type T | { int ?>?( T, T ); } )268 forall( otype T | { int ?>?( T, T ); } ) 261 269 T max( const T t1, const T t2 ) { 262 270 return t1 > t2 ? t1 : t2; 263 271 } // max 264 272 265 forall( type T )273 forall( otype T ) 266 274 void swap( T * t1, T * t2 ) { 267 275 T temp = *t1;
Note:
See TracChangeset
for help on using the changeset viewer.