Changeset dafbde8 for libcfa/src/stdlib.hfa
- Timestamp:
- Jan 20, 2021, 4:49:40 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 454f478
- Parents:
- 92bfda0 (diff), fd54fef (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
-
libcfa/src/stdlib.hfa
r92bfda0 rdafbde8 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Dec 12 13:52:34 202013 // Update Count : 5 3612 // Last Modified On : Sat Jan 16 09:07:10 2021 13 // Update Count : 568 14 14 // 15 15 … … 48 48 else return (T *)alignment( _Alignof(T), dim, sizeof(T) ) 49 49 50 static inline forall( dtype T| sized(T) ) {50 static inline forall( 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( dtype T| sized(T) ) {110 forall( 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( dtype T) {153 forall( 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( dtype T| sized(T) ) {161 static inline forall( 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)) { printf("ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n"); exit(1); } 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 166 168 memcpy( &ret.t, &t, size ); 167 169 return ret; … … 173 175 S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; } 174 176 175 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {177 T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) { 176 178 T * ptr = NULL; 177 179 size_t size = sizeof(T); … … 181 183 ptr = (T*) (void *) resize( (void *)Resize, Align, Dim * size ); 182 184 } else if ( Realloc ) { 183 if ( Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);184 ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size );185 if ( Fill.tag != '0' ) copy_end = min(malloc_size( Realloc ), Dim * size ); 186 ptr = (T *) (void *) realloc( (void *)Realloc, Align, Dim * size ); 185 187 } else { 186 ptr = (T *) (void *) memalign( Align, Dim * size );187 } 188 189 if (Fill.tag == 'c') {188 ptr = (T *) (void *) memalign( Align, Dim * size ); 189 } 190 191 if ( Fill.tag == 'c' ) { 190 192 memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end ); 191 } else if (Fill.tag == 't') {193 } else if ( Fill.tag == 't' ) { 192 194 for ( int i = copy_end; i < Dim * size; i += size ) { 193 #pragma GCC diagnostic push 194 #pragma GCC diagnostic ignored "-Warray-bounds" 195 #pragma GCC diagnostic push 196 #pragma GCC diagnostic ignored "-Wstringop-overflow=" 197 memcpy( (char *)ptr + i, &Fill.t, size ); 198 #pragma GCC diagnostic pop 199 #pragma GCC diagnostic pop 195 #pragma GCC diagnostic push 196 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 197 memcpy( (char *)ptr + i, &Fill.t, sizeof(Fill.t) ); 198 #pragma GCC diagnostic pop 200 199 } 201 } else if (Fill.tag == 'a') {200 } else if ( Fill.tag == 'a' ) { 202 201 memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) ); 203 } else if(Fill.tag == 'T') { 204 for ( int i = copy_end; i < Dim * size; i += size ) { 205 memcpy( (char *)ptr + i, Fill.at, size ); 206 } 202 } else if ( Fill.tag == 'T' ) { 203 memcpy( (char *)ptr + copy_end, Fill.at, Dim * size ); 207 204 } 208 205 … … 210 207 } // $alloc_internal 211 208 212 forall( ttype TT| { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {209 forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 213 210 214 211 T * $alloc_internal( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { … … 239 236 } // distribution T 240 237 241 static inline forall( dtype T| sized(T) ) {238 static inline forall( T & | sized(T) ) { 242 239 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 243 240 T * memset( T * dest, char fill ) { … … 260 257 261 258 // CFA deallocation for multiple objects 262 static inline forall( dtype T) // FIX ME, problems with 0p in list259 static inline forall( T & ) // FIX ME, problems with 0p in list 263 260 void free( T * ptr ) { 264 261 free( (void *)ptr ); // C free 265 262 } // free 266 static inline forall( dtype T, ttype TT| { void free( TT ); } )263 static inline forall( T &, TT... | { void free( TT ); } ) 267 264 void free( T * ptr, TT rest ) { 268 265 free( ptr ); … … 271 268 272 269 // CFA allocation/deallocation and constructor/destructor, non-array types 273 static inline forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } )270 static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) 274 271 T * new( TT p ) { 275 272 return &(*(T *)malloc()){ p }; // run constructor 276 273 } // new 277 274 278 static inline forall( dtype T| { void ^?{}( T & ); } )275 static inline forall( T & | { void ^?{}( T & ); } ) 279 276 void delete( T * ptr ) { 280 277 // special case for 0-sized object => always call destructor … … 284 281 free( ptr ); // always call free 285 282 } // delete 286 static inline forall( dtype T, ttype TT| { void ^?{}( T & ); void delete( TT ); } )283 static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } ) 287 284 void delete( T * ptr, TT rest ) { 288 285 delete( ptr ); … … 291 288 292 289 // CFA allocation/deallocation and constructor/destructor, array types 293 forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );294 forall( dtype T| sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );295 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT| { void adelete( TT ); } ) void adelete( T arr[], TT rest );290 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p ); 291 forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); 292 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest ); 296 293 297 294 //--------------------------------------- … … 333 330 //--------------------------------------- 334 331 335 forall( otypeE | { int ?<?( E, E ); } ) {332 forall( E | { int ?<?( E, E ); } ) { 336 333 E * bsearch( E key, const E * vals, size_t dim ); 337 334 size_t bsearch( E key, const E * vals, size_t dim ); … … 342 339 } // distribution 343 340 344 forall( otype K, otypeE | { int ?<?( K, K ); K getKey( const E & ); } ) {341 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) { 345 342 E * bsearch( K key, const E * vals, size_t dim ); 346 343 size_t bsearch( K key, const E * vals, size_t dim ); … … 351 348 } // distribution 352 349 353 forall( otypeE | { int ?<?( E, E ); } ) {350 forall( E | { int ?<?( E, E ); } ) { 354 351 void qsort( E * vals, size_t dim ); 355 352 } // distribution
Note: See TracChangeset
for help on using the changeset viewer.