Changes in libcfa/src/stdlib.hfa [d1b70d4:09da82d]
- File:
-
- 1 edited
-
libcfa/src/stdlib.hfa (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
rd1b70d4 r09da82d 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 21 22:02:13 202113 // Update Count : 5 7412 // Last Modified On : Sat Dec 12 13:52:34 2020 13 // Update Count : 536 14 14 // 15 15 … … 48 48 else return (T *)alignment( _Alignof(T), dim, sizeof(T) ) 49 49 50 static inline forall( T &| sized(T) ) {50 static inline forall( dtype T | sized(T) ) { 51 51 // CFA safe equivalents, i.e., implicit size specification 52 52 … … 108 108 109 109 1. Replace the current forall-block that contains defintions of S_fill and S_realloc with following: 110 forall( T &| sized(T) ) {110 forall( dtype T | sized(T) ) { 111 111 union U_fill { char c; T * a; T t; }; 112 112 struct S_fill { char tag; U_fill(T) fill; }; … … 151 151 typedef struct S_resize { inline void *; } T_resize; 152 152 153 forall( T &) {153 forall( dtype T ) { 154 154 struct S_fill { char tag; char c; size_t size; T * at; char t[50]; }; 155 155 struct S_realloc { inline T *; }; … … 159 159 static inline T_resize ?`resize ( void * a ) { return (T_resize){a}; } 160 160 161 static inline forall( T &| sized(T) ) {161 static inline forall( dtype T | sized(T) ) { 162 162 S_fill(T) ?`fill ( T t ) { 163 163 S_fill(T) ret = { 't' }; 164 164 size_t size = sizeof(T); 165 if ( size > sizeof(ret.t) ) { 166 abort( "ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n" ); 167 } // if 165 if(size > sizeof(ret.t)) { printf("ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n"); exit(1); } 168 166 memcpy( &ret.t, &t, size ); 169 167 return ret; … … 175 173 S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; } 176 174 177 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {175 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) { 178 176 T * ptr = NULL; 179 177 size_t size = sizeof(T); … … 183 181 ptr = (T*) (void *) resize( (void *)Resize, Align, Dim * size ); 184 182 } else if ( Realloc ) { 185 if ( Fill.tag != '0' ) copy_end = min(malloc_size( Realloc ), Dim * size);186 ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size );183 if (Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size); 184 ptr = (T*) (void *) realloc( (void *)Realloc, Align, Dim * size ); 187 185 } else { 188 ptr = (T *) (void *) memalign( Align, Dim * size );189 } 190 191 if ( Fill.tag == 'c') {186 ptr = (T*) (void *) memalign( Align, Dim * size ); 187 } 188 189 if(Fill.tag == 'c') { 192 190 memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end ); 193 } else if ( Fill.tag == 't') {191 } else if(Fill.tag == 't') { 194 192 for ( int i = copy_end; i < Dim * size; i += size ) { 195 #pragma GCC diagnostic push196 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"197 assert( size <= sizeof(Fill.t) );198 193 memcpy( (char *)ptr + i, &Fill.t, size ); 199 #pragma GCC diagnostic pop200 194 } 201 } else if ( Fill.tag == 'a') {195 } else if(Fill.tag == 'a') { 202 196 memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) ); 203 } else if ( Fill.tag == 'T' ) { 204 memcpy( (char *)ptr + copy_end, Fill.at, Dim * size ); 197 } else if(Fill.tag == 'T') { 198 for ( int i = copy_end; i < Dim * size; i += size ) { 199 memcpy( (char *)ptr + i, Fill.at, size ); 200 } 205 201 } 206 202 … … 208 204 } // $alloc_internal 209 205 210 forall( TT...| { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {206 forall( ttype TT | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 211 207 212 208 T * $alloc_internal( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { … … 237 233 } // distribution T 238 234 239 static inline forall( T &| sized(T) ) {235 static inline forall( dtype T | sized(T) ) { 240 236 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 241 237 T * memset( T * dest, char fill ) { … … 258 254 259 255 // CFA deallocation for multiple objects 260 static inline forall( T &) // FIX ME, problems with 0p in list256 static inline forall( dtype T ) // FIX ME, problems with 0p in list 261 257 void free( T * ptr ) { 262 258 free( (void *)ptr ); // C free 263 259 } // free 264 static inline forall( T &, TT...| { void free( TT ); } )260 static inline forall( dtype T, ttype TT | { void free( TT ); } ) 265 261 void free( T * ptr, TT rest ) { 266 262 free( ptr ); … … 269 265 270 266 // CFA allocation/deallocation and constructor/destructor, non-array types 271 static inline forall( T & | sized(T), TT...| { void ?{}( T &, TT ); } )267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) 272 268 T * new( TT p ) { 273 return &(*(T *)malloc()){ p }; // run constructor269 return &(*(T *)malloc()){ p }; // run constructor 274 270 } // new 275 271 276 static inline forall( T &| { void ^?{}( T & ); } )272 static inline forall( dtype T | { void ^?{}( T & ); } ) 277 273 void delete( T * ptr ) { 278 274 // special case for 0-sized object => always call destructor … … 282 278 free( ptr ); // always call free 283 279 } // delete 284 static inline forall( T &, TT...| { void ^?{}( T & ); void delete( TT ); } )280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } ) 285 281 void delete( T * ptr, TT rest ) { 286 282 delete( ptr ); … … 289 285 290 286 // CFA allocation/deallocation and constructor/destructor, array types 291 forall( T & | sized(T), TT...| { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );292 forall( T &| sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );293 forall( T & | sized(T) | { void ^?{}( T & ); }, TT...| { void adelete( TT ); } ) void adelete( T arr[], TT rest );287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p ); 288 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); 289 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest ); 294 290 295 291 //--------------------------------------- … … 331 327 //--------------------------------------- 332 328 333 forall( E | { int ?<?( E, E ); } ) {329 forall( otype E | { int ?<?( E, E ); } ) { 334 330 E * bsearch( E key, const E * vals, size_t dim ); 335 331 size_t bsearch( E key, const E * vals, size_t dim ); … … 340 336 } // distribution 341 337 342 forall( K,E | { int ?<?( K, K ); K getKey( const E & ); } ) {338 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) { 343 339 E * bsearch( K key, const E * vals, size_t dim ); 344 340 size_t bsearch( K key, const E * vals, size_t dim ); … … 349 345 } // distribution 350 346 351 forall( E | { int ?<?( E, E ); } ) {347 forall( otype E | { int ?<?( E, E ); } ) { 352 348 void qsort( E * vals, size_t dim ); 353 349 } // distribution
Note:
See TracChangeset
for help on using the changeset viewer.