Changes in src/libcfa/stdlib.c [8bc4ef8:3cfe27f]
- File:
-
- 1 edited
-
src/libcfa/stdlib.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib.c
r8bc4ef8 r3cfe27f 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 28 07:54:21201613 // Update Count : 1 6612 // Last Modified On : Wed Mar 23 13:26:42 2016 13 // Update Count : 146 14 14 // 15 15 … … 24 24 #include <malloc.h> // malloc_usable_size 25 25 #include <math.h> // fabsf, fabs, fabsl 26 #include <complex.h> // _Complex_I 26 #include <complex.h> // _Complex_I, cabsf, cabs, cabsl 27 27 } // extern "C" 28 28 29 29 forall( otype T ) T * malloc( void ) { 30 //printf( "malloc1\n" );30 printf( "malloc1\n" ); 31 31 return (T *)malloc( sizeof(T) ); 32 32 } // malloc 33 forall( otype T ) T * malloc( size_t size ) { 34 printf( "malloc2\n" ); 35 return (T *)(void *)malloc( size ); 36 } // malloc 33 37 forall( otype T ) T * malloc( char fill ) { 34 //printf( "malloc3\n" );38 printf( "malloc3\n" ); 35 39 T * ptr = (T *)malloc( sizeof(T) ); 36 return memset( ptr , (int)fill, sizeof(T));37 } // malloc 38 39 forall( otype T ) T * calloc( size_t nmemb) {40 //printf( "calloc\n" );41 return (T *)calloc( nmemb, sizeof(T) );40 return memset( ptr ); 41 } // malloc 42 43 forall( otype T ) T * calloc( size_t size ) { 44 printf( "calloc\n" ); 45 return (T *)calloc( size, sizeof(T) ); 42 46 } // calloc 43 47 44 48 forall( otype T ) T * realloc( T * ptr, size_t size ) { 45 //printf( "realloc1\n" );49 printf( "realloc1\n" ); 46 50 return (T *)(void *)realloc( (void *)ptr, size ); 47 51 } // realloc 48 52 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 49 //printf( "realloc2\n" );53 printf( "realloc2\n" ); 50 54 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 51 55 size_t unused = malloc_usable_size( nptr ); … … 55 59 56 60 forall( otype T ) T * malloc( T * ptr, size_t size ) { 57 //printf( "malloc4\n" );61 printf( "malloc4\n" ); 58 62 return (T *)realloc( ptr, size ); 59 63 } // malloc 60 64 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 61 //printf( "malloc5\n" );65 printf( "malloc5\n" ); 62 66 return (T *)realloc( ptr, size, fill ); 63 67 } // malloc 64 68 65 69 forall( otype T ) T * aligned_alloc( size_t alignment ) { 66 //printf( "aligned_alloc\n" );70 printf( "aligned_alloc\n" ); 67 71 return (T *)memalign( alignment, sizeof(T) ); 68 72 } // aligned_alloc 69 73 70 74 forall( otype T ) T * memalign( size_t alignment ) { 71 //printf( "memalign\n" );75 printf( "memalign\n" ); 72 76 return (T *)memalign( alignment, sizeof(T) ); 73 77 } // memalign 74 78 75 79 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) { 76 //printf( "posix_memalign\n" );80 printf( "posix_memalign\n" ); 77 81 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 78 82 } // posix_memalign 79 83 84 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 85 printf( "memset1\n" ); 86 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 87 } // memset 88 forall( otype T ) T * memset( T * ptr ) { // remove when default value available 89 printf( "memset2\n" ); 90 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 91 } // memset 92 80 93 //--------------------------------------- 81 94 82 95 int ato( const char * ptr ) { 83 96 int i; 84 if ( sscanf( ptr, "%d", &i ) == EOF ) {} 97 if ( sscanf( ptr, "%d", &i ) == EOF ) {} // check return code 85 98 return i; 86 99 } 87 100 unsigned int ato( const char * ptr ) { 88 101 unsigned int ui; 89 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} 102 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} // check return code 90 103 return ui; 91 104 } 92 105 long int ato( const char * ptr ) { 93 106 long int li; 94 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} 107 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} // check return code 95 108 return li; 96 109 } 97 110 unsigned long int ato( const char * ptr ) { 98 111 unsigned long int uli; 99 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} 112 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} // check return code 100 113 return uli; 101 114 } 102 115 long long int ato( const char * ptr ) { 103 116 long long int lli; 104 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} 117 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} // check return code 105 118 return lli; 106 119 } 107 120 unsigned long long int ato( const char * ptr ) { 108 121 unsigned long long int ulli; 109 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} 122 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} // check return code 110 123 return ulli; 111 124 } … … 113 126 float ato( const char * ptr ) { 114 127 float f; 115 if ( sscanf( ptr, "%f", &f ) == EOF ) {} 128 if ( sscanf( ptr, "%f", &f ) == EOF ) {} // check return code 116 129 return f; 117 130 } 118 131 double ato( const char * ptr ) { 119 132 double d; 120 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} 133 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} // check return code 121 134 return d; 122 135 } 123 136 long double ato( const char * ptr ) { 124 137 long double ld; 125 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} 138 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} // check return code 126 139 return ld; 127 140 } … … 129 142 float _Complex ato( const char * ptr ) { 130 143 float re, im; 131 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} 144 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} // check return code 132 145 return re + im * _Complex_I; 133 146 } 134 147 double _Complex ato( const char * ptr ) { 135 148 double re, im; 136 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} 149 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code 137 150 return re + im * _Complex_I; 138 151 } 139 152 long double _Complex ato( const char * ptr ) { 140 153 long double re, im; 141 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} 154 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} // check return code 142 155 return re + im * _Complex_I; 143 156 } … … 213 226 //--------------------------------------- 214 227 215 //forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )216 // [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2 ];}228 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 229 [ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ } 217 230 218 231 //--------------------------------------- … … 221 234 long int abs( long int v ) { return labs( v ); } 222 235 long long int abs( long long int v ) { return llabs( v ); } 223 float abs( float x ) { return fabsf( x); }224 double abs( double x ) { return fabs( x); }225 long double abs( long double x ) { return fabsl( x); }226 float abs( float _Complex x ) { return cabsf( x); }227 double abs( double _Complex x ) { return cabs( x); }228 long double abs( long double _Complex x ) { return cabsl( x); }236 float abs( float v ) { return fabsf( v ); } 237 double abs( double v ) { return fabs( v ); } 238 long double abs( long double v ) { return fabsl( v ); } 239 float _Complex abs( float _Complex v ) { return cabsf( v ); } 240 double _Complex abs( double _Complex v ) { return cabs( v ); } 241 long double _Complex abs( long double _Complex v ) { return cabsl( v ); } 229 242 230 243 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.