Changes in src/libcfa/stdlib.c [45161b4d:52f85e0]
- File:
-
- 1 edited
-
src/libcfa/stdlib.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib.c
r45161b4d r52f85e0 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 14:49:58201613 // Update Count : 1 5512 // Last Modified On : Wed Feb 10 15:45:56 2016 13 // Update Count : 140 14 14 // 15 15 … … 27 27 } // extern "C" 28 28 29 forall( otype T ) T * malloc( void ) { 30 //printf( "malloc1\n" ); 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" ); 31 40 return (T *)malloc( sizeof(T) ); 32 41 } // malloc 33 forall( otype T ) T * malloc( char fill ) { 34 //printf( "malloc3\n" ); 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" ); 35 48 T * ptr = (T *)malloc( sizeof(T) ); 36 49 return memset( ptr ); 37 50 } // malloc 38 51 39 forall( otype T ) T * calloc( size_t nmemb) {40 //printf( "calloc\n" );41 return (T *)calloc( nmemb, sizeof(T) );52 forall( type T ) T * calloc( size_t size ) { 53 printf( "calloc\n" ); 54 return (T *)calloc( size, sizeof(T) ); 42 55 } // calloc 43 56 44 forall( otype T ) T * realloc( T * ptr, size_t size ) {45 //printf( "realloc1\n" );57 forall( type T ) T * realloc( T * ptr, size_t size ) { 58 printf( "realloc1\n" ); 46 59 return (T *)(void *)realloc( (void *)ptr, size ); 47 60 } // realloc 48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {49 //printf( "realloc2\n" );61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 62 printf( "realloc2\n" ); 50 63 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 51 64 size_t unused = malloc_usable_size( nptr ); … … 54 67 } // realloc 55 68 56 forall( otype T ) T * malloc( T * ptr, size_t size ) {57 //printf( "malloc4\n" );69 forall( type T ) T * malloc( T * ptr, size_t size ) { 70 printf( "malloc4\n" ); 58 71 return (T *)realloc( ptr, size ); 59 72 } // malloc 60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {61 //printf( "malloc5\n" );73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 74 printf( "malloc5\n" ); 62 75 return (T *)realloc( ptr, size, fill ); 63 76 } // malloc 64 77 65 forall( otype T ) T * aligned_alloc( size_t alignment ) {66 //printf( "aligned_alloc\n" );78 forall( type T ) T * aligned_alloc( size_t alignment ) { 79 printf( "aligned_alloc\n" ); 67 80 return (T *)memalign( alignment, sizeof(T) ); 68 81 } // aligned_alloc 69 82 70 forall( otype T ) T * memalign( size_t alignment ) {71 //printf( "memalign\n" );83 forall( type T ) T * memalign( size_t alignment ) { 84 printf( "memalign\n" ); 72 85 return (T *)memalign( alignment, sizeof(T) ); 73 86 } // memalign 74 87 75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {76 //printf( "posix_memalign\n" );88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) { 89 printf( "posix_memalign\n" ); 77 90 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 78 91 } // posix_memalign 79 80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill81 //printf( "memset1\n" );82 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );83 } // memset84 forall( otype T ) T * memset( T * ptr ) { // remove when default value available85 //printf( "memset2\n" );86 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );87 } // memset88 92 89 93 //--------------------------------------- … … 119 123 return ulli; 120 124 } 121 122 125 float ato( const char * ptr ) { 123 126 float f; … … 135 138 return ld; 136 139 } 137 138 140 float _Complex ato( const char * ptr ) { 139 141 float re, im; … … 170 172 return strtoull( sptr, eptr, base ); 171 173 } 172 173 174 float strto( const char * sptr, char ** eptr ) { 174 175 return strtof( sptr, eptr ); … … 180 181 return strtold( sptr, eptr ); 181 182 } 182 183 183 float _Complex strto( const char * sptr, char ** eptr ) { 184 184 float re, im; … … 208 208 //--------------------------------------- 209 209 210 forall( otype T | { int ?<?( T, T ); } )210 forall( type 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( otype T | { int ?<?( T, T ); } )216 forall( type 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( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )224 forall( type 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 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 ); } ) 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 ); } ) 264 256 T min( const T t1, const T t2 ) { 265 257 return t1 < t2 ? t1 : t2; 266 258 } // min 267 259 268 forall( otype T | { int ?>?( T, T ); } )260 forall( type T | { int ?>?( T, T ); } ) 269 261 T max( const T t1, const T t2 ) { 270 262 return t1 > t2 ? t1 : t2; 271 263 } // max 272 264 273 forall( otype T )265 forall( type T ) 274 266 void swap( T * t1, T * t2 ) { 275 267 T temp = *t1;
Note:
See TracChangeset
for help on using the changeset viewer.