Changeset f3ddc21
 Timestamp:
 May 13, 2017, 11:56:45 AM (7 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 07846d8
 Parents:
 b65a9fc
 Location:
 src/libcfa
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/libcfa/stdlib
rb65a9fc rf3ddc21 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 1 17:35:24 201713 // Update Count : 10 412 // Last Modified On : Tue May 9 08:42:44 2017 13 // Update Count : 107 14 14 // 15 15 … … 84 84 forall( otype T  { int ?<?( T, T ); } ) 85 85 T * bsearch( T key, const T * arr, size_t dimension ); 86 86 87 forall( otype T  { int ?<?( T, T ); } ) 87 88 unsigned int bsearch( T key, const T * arr, size_t dimension ); 89 88 90 89 91 forall( otype T  { int ?<?( T, T ); } ) … … 107 109 double abs( double _Complex ); 108 110 long double abs( long double _Complex ); 111 forall ( otype T  { void ?{}( T *, zero_t ); int ?<?( T, T ); T ?( T ); } ) 112 T abs( T ); 109 113 110 114 // 
src/libcfa/stdlib.c
rb65a9fc rf3ddc21 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Apr 16 10:41:05201713 // Update Count : 1 8912 // Last Modified On : Tue May 9 08:43:00 2017 13 // Update Count : 191 14 14 // 15 15 … … 27 27 } // extern "C" 28 28 29 forall( dtype T  sized(T) ) T * malloc( void ) { 30 //printf( "malloc1\n" ); 31 return (T *)(void*)malloc( (size_t)sizeof(T) ); 29 forall( dtype T  sized(T) ) T * malloc( void ) { // typesafe 30 return (T *)(void *)malloc( (size_t)sizeof(T) ); 32 31 } // malloc 33 forall( dtype T  sized(T) ) T * malloc( char fill ) { 34 //printf( "malloc3\n" ); 35 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );32 33 forall( dtype T  sized(T) ) T * malloc( char fill ) { // initial with fill value (like calloc) 34 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); 36 35 return memset( ptr, (int)fill, sizeof(T) ); 37 36 } // malloc 38 37 39 forall( dtype T  sized(T) ) T * calloc( size_t nmemb ) { 40 //printf( "calloc\n" ); 38 forall( dtype T  sized(T) ) T * malloc( T * ptr, size_t size ) { // alternative realloc 39 return (T *)realloc( ptr, size ); 40 } // malloc 41 42 forall( dtype T  sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill ) { // alternative realloc with fill value 43 return (T *)realloc( ptr, size, fill ); 44 } // malloc 45 46 47 forall( dtype T  sized(T) ) T * calloc( size_t nmemb ) { // typesafe array initialization with fill 0 41 48 return (T *)calloc( nmemb, sizeof(T) ); 42 49 } // calloc 43 50 44 forall( dtype T  sized(T) ) T * realloc( T * ptr, size_t size ) { 45 //printf( "realloc1\n" ); 51 52 forall( dtype T  sized(T) ) T * realloc( T * ptr, size_t size ) { // typesafe 46 53 return (T *)(void *)realloc( (void *)ptr, size ); 47 54 } // realloc 48 forall( dtype T  sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill ) { 49 //printf( "realloc2\n" ); 55 56 forall( dtype T  sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill ) { // alternative realloc with fill value 50 57 char * nptr = (T *)(void *)realloc( (void *)ptr, size ); 51 58 size_t unused = malloc_usable_size( nptr ); … … 54 61 } // realloc 55 62 56 forall( dtype T  sized(T) ) T * malloc( T * ptr, size_t size ) { 57 //printf( "malloc4\n" ); 58 return (T *)realloc( ptr, size ); 59 } // malloc 60 forall( dtype T  sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill ) { 61 //printf( "malloc5\n" ); 62 return (T *)realloc( ptr, size, fill ); 63 } // malloc 64 65 forall( dtype T  sized(T) ) T * aligned_alloc( size_t alignment ) { 66 //printf( "aligned_alloc\n" ); 63 64 forall( dtype T  sized(T) ) T * aligned_alloc( size_t alignment ) { // aligned allocation 67 65 return (T *)memalign( alignment, sizeof(T) ); 68 66 } // aligned_alloc 69 67 70 68 forall( dtype T  sized(T) ) T * memalign( size_t alignment ) { 71 //printf( "memalign\n" );72 69 return (T *)memalign( alignment, sizeof(T) ); 73 70 } // memalign 74 71 75 72 forall( dtype T  sized(T) ) int posix_memalign( T ** ptr, size_t alignment ) { 76 //printf( "posix_memalign\n" );77 73 return posix_memalign( (void **)ptr, alignment, sizeof(T) ); 78 74 } // posix_memalign 79 75 80 forall( dtype T, ttype Params  sized(T)  { void ?{}( T *, Params ); } ) 76 77 forall( dtype T, ttype Params  sized(T)  { void ?{}( T *, Params ); } ) // new 81 78 T * new( Params p ) { 82 79 return ((T *)malloc()){ p }; 83 } 84 85 forall( dtype T  { void ^?{}(T *); } ) 80 } // new 81 82 forall( dtype T  { void ^?{}(T *); } ) // delete 86 83 void delete( T * ptr ) { 87 88 89 90 91 } 84 if ( ptr ) { 85 ^ptr{}; 86 free( ptr ); 87 } 88 } // delete 92 89 93 90 forall( dtype T, ttype Params  { void ^?{}(T *); void delete(Params); } ) … … 98 95 } 99 96 delete( rest ); 100 } 97 } // delete 101 98 102 99 // … … 106 103 if ( sscanf( ptr, "%d", &i ) == EOF ) {} 107 104 return i; 108 } 105 } // ato 106 109 107 unsigned int ato( const char * ptr ) { 110 108 unsigned int ui; 111 109 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} 112 110 return ui; 113 } 111 } // ato 112 114 113 long int ato( const char * ptr ) { 115 114 long int li; 116 115 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} 117 116 return li; 118 } 117 } // ato 118 119 119 unsigned long int ato( const char * ptr ) { 120 120 unsigned long int uli; 121 121 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} 122 122 return uli; 123 } 123 } // ato 124 124 125 long long int ato( const char * ptr ) { 125 126 long long int lli; 126 127 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} 127 128 return lli; 128 } 129 } // ato 130 129 131 unsigned long long int ato( const char * ptr ) { 130 132 unsigned long long int ulli; 131 133 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} 132 134 return ulli; 133 } 135 } // ato 136 134 137 135 138 float ato( const char * ptr ) { … … 137 140 if ( sscanf( ptr, "%f", &f ) == EOF ) {} 138 141 return f; 139 } 142 } // ato 143 140 144 double ato( const char * ptr ) { 141 145 double d; 142 146 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} 143 147 return d; 144 } 148 } // ato 149 145 150 long double ato( const char * ptr ) { 146 151 long double ld; 147 152 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} 148 153 return ld; 149 } 154 } // ato 155 150 156 151 157 float _Complex ato( const char * ptr ) { … … 153 159 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} 154 160 return re + im * _Complex_I; 155 } 161 } // ato 162 156 163 double _Complex ato( const char * ptr ) { 157 164 double re, im; 158 165 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} 159 166 return re + im * _Complex_I; 160 } 167 } // ato 168 161 169 long double _Complex ato( const char * ptr ) { 162 170 long double re, im; 163 171 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} 164 172 return re + im * _Complex_I; 165 } 173 } // ato 174 166 175 167 176 int strto( const char * sptr, char ** eptr, int base ) { 168 177 return (int)strtol( sptr, eptr, base ); 169 } 178 } // strto 179 170 180 unsigned int strto( const char * sptr, char ** eptr, int base ) { 171 181 return (unsigned int)strtoul( sptr, eptr, base ); 172 } 182 } // strto 183 173 184 long int strto( const char * sptr, char ** eptr, int base ) { 174 185 return strtol( sptr, eptr, base ); 175 } 186 } // strto 187 176 188 unsigned long int strto( const char * sptr, char ** eptr, int base ) { 177 189 return strtoul( sptr, eptr, base ); 178 } 190 } // strto 191 179 192 long long int strto( const char * sptr, char ** eptr, int base ) { 180 193 return strtoll( sptr, eptr, base ); 181 } 194 } // strto 195 182 196 unsigned long long int strto( const char * sptr, char ** eptr, int base ) { 183 197 return strtoull( sptr, eptr, base ); 184 } 198 } // strto 199 185 200 186 201 float strto( const char * sptr, char ** eptr ) { 187 202 return strtof( sptr, eptr ); 188 } 203 } // strto 204 189 205 double strto( const char * sptr, char ** eptr ) { 190 206 return strtod( sptr, eptr ); 191 } 207 } // strto 208 192 209 long double strto( const char * sptr, char ** eptr ) { 193 210 return strtold( sptr, eptr ); 194 } 211 } // strto 212 195 213 196 214 float _Complex strto( const char * sptr, char ** eptr ) { … … 201 219 if ( sptr == *eptr ) return 0.0; 202 220 return re + im * _Complex_I; 203 } 221 } // strto 222 204 223 double _Complex strto( const char * sptr, char ** eptr ) { 205 224 double re, im; … … 209 228 if ( sptr == *eptr ) return 0.0; 210 229 return re + im * _Complex_I; 211 } 230 } // strto 231 212 232 long double _Complex strto( const char * sptr, char ** eptr ) { 213 233 long double re, im; … … 217 237 if ( sptr == *eptr ) return 0.0; 218 238 return re + im * _Complex_I; 219 } 239 } // strto 220 240 221 241 //
Note: See TracChangeset
for help on using the changeset viewer.