Changes in libcfa/src/stdlib.hfa [09ee131:d1b70d4]
- File:
-
- 1 edited
-
libcfa/src/stdlib.hfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r09ee131 rd1b70d4 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 18 21:51:13 202113 // Update Count : 5 6912 // Last Modified On : Thu Jan 21 22:02:13 2021 13 // Update Count : 574 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' }; … … 195 195 #pragma GCC diagnostic push 196 196 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 197 memcpy( (char *)ptr + i, &Fill.t, sizeof(Fill.t) ); 197 assert( size <= sizeof(Fill.t) ); 198 memcpy( (char *)ptr + i, &Fill.t, size ); 198 199 #pragma GCC diagnostic pop 199 200 } … … 207 208 } // $alloc_internal 208 209 209 forall( ttype TT| { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {210 forall( TT... | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 210 211 211 212 T * $alloc_internal( void * , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) { … … 236 237 } // distribution T 237 238 238 static inline forall( dtype T| sized(T) ) {239 static inline forall( T & | sized(T) ) { 239 240 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 240 241 T * memset( T * dest, char fill ) { … … 257 258 258 259 // CFA deallocation for multiple objects 259 static inline forall( dtype T) // FIX ME, problems with 0p in list260 static inline forall( T & ) // FIX ME, problems with 0p in list 260 261 void free( T * ptr ) { 261 262 free( (void *)ptr ); // C free 262 263 } // free 263 static inline forall( dtype T, ttype TT| { void free( TT ); } )264 static inline forall( T &, TT... | { void free( TT ); } ) 264 265 void free( T * ptr, TT rest ) { 265 266 free( ptr ); … … 268 269 269 270 // CFA allocation/deallocation and constructor/destructor, non-array types 270 static inline forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } )271 static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) 271 272 T * new( TT p ) { 272 273 return &(*(T *)malloc()){ p }; // run constructor 273 274 } // new 274 275 275 static inline forall( dtype T| { void ^?{}( T & ); } )276 static inline forall( T & | { void ^?{}( T & ); } ) 276 277 void delete( T * ptr ) { 277 278 // special case for 0-sized object => always call destructor … … 281 282 free( ptr ); // always call free 282 283 } // delete 283 static inline forall( dtype T, ttype TT| { void ^?{}( T & ); void delete( TT ); } )284 static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } ) 284 285 void delete( T * ptr, TT rest ) { 285 286 delete( ptr ); … … 288 289 289 290 // CFA allocation/deallocation and constructor/destructor, array types 290 forall( dtype T | sized(T), ttype TT| { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );291 forall( dtype T| sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );292 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT| { void adelete( TT ); } ) void adelete( T arr[], TT rest );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 ); 293 294 294 295 //--------------------------------------- … … 330 331 //--------------------------------------- 331 332 332 forall( otypeE | { int ?<?( E, E ); } ) {333 forall( E | { int ?<?( E, E ); } ) { 333 334 E * bsearch( E key, const E * vals, size_t dim ); 334 335 size_t bsearch( E key, const E * vals, size_t dim ); … … 339 340 } // distribution 340 341 341 forall( otype K, otypeE | { int ?<?( K, K ); K getKey( const E & ); } ) {342 forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) { 342 343 E * bsearch( K key, const E * vals, size_t dim ); 343 344 size_t bsearch( K key, const E * vals, size_t dim ); … … 348 349 } // distribution 349 350 350 forall( otypeE | { int ?<?( E, E ); } ) {351 forall( E | { int ?<?( E, E ); } ) { 351 352 void qsort( E * vals, size_t dim ); 352 353 } // distribution
Note:
See TracChangeset
for help on using the changeset viewer.