Changes in libcfa/src/stdlib.hfa [94429f8:55acc3a]
- File:
-
- 1 edited
-
libcfa/src/stdlib.hfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r94429f8 r55acc3a 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Nov 12 08:12:08202013 // Update Count : 5 1512 // Last Modified On : Tue Sep 1 20:32:34 2020 13 // Update Count : 505 14 14 // 15 15 16 16 #pragma once 17 17 18 #include "bits/defs.hfa" // OPTIONAL_THREAD19 #include "bits/align.hfa" // libAlign18 #include "bits/defs.hfa" 19 #include "bits/align.hfa" 20 20 21 21 #include <stdlib.h> // *alloc, strto*, ato* … … 107 107 } // distribution 108 108 109 static inline forall( ttype TT | { void free( TT ); } ) { 110 // T* does not take void* and vice-versa 111 112 void free( void * addr, TT rest ) { 113 free( addr ); 114 free( rest ); 115 } // free 116 117 forall( dtype T | sized(T) ) 118 void free( T * addr, TT rest ) { 119 free( addr ); 120 free( rest ); 121 } // free 122 } // distribution 123 109 124 /* 110 125 FIX ME : fix alloc interface after Ticker Number 214 is resolved, define and add union to S_fill. Then, modify postfix-fill functions to support T * with nmemb, char, and T object of any size. Finally, change alloc_internal. … … 114 129 forall( dtype T | sized(T) ) { 115 130 union U_fill { char c; T * a; T t; }; 116 struct S_fill { char tag; U_fill(T) fill; };131 struct S_fill { char tag; char c; size_t size; T * at; char t[50]; }; 117 132 struct S_realloc { inline T *; }; 118 133 } … … 162 177 static inline T_align ?`align ( size_t a ) { return (T_align){a}; } 163 178 static inline T_resize ?`resize ( void * a ) { return (T_resize){a}; } 164 165 179 static inline forall( dtype T | sized(T) ) { 180 166 181 S_fill(T) ?`fill ( T t ) { 167 182 S_fill(T) ret = { 't' }; … … 235 250 236 251 } // distribution TT 252 237 253 } // distribution T 238 254 … … 246 262 return (T *)memcpy( dest, src, sizeof(T) ); 247 263 } // memcpy 248 264 } // distribution 265 266 static inline forall( dtype T | sized(T) ) { 249 267 // Cforall safe initialization/copy, i.e., implicit size specification, array types 250 268 T * amemset( T dest[], char fill, size_t dim ) { … … 257 275 } // distribution 258 276 259 // Cforall deallocation for multiple objects260 static inline forall( dtype T, ttype TT | { void free( TT ); } )261 void free( T * addr, TT rest ) {262 free( addr );263 free( rest );264 } // free265 266 277 // Cforall allocation/deallocation and constructor/destructor, non-array types 267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) 268 T * new( TT p ) { 269 return &(*malloc()){ p }; // run constructor 270 } // new 271 272 static inline forall( dtype T | { void ^?{}( T & ); } ) 273 void delete( T * ptr ) { 274 if ( ptr ) { // ignore null 275 ^(*ptr){}; // run destructor 276 free( ptr ); 277 } // if 278 } // delete 279 280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } ) 281 void delete( T * ptr, TT rest ) { 282 delete( ptr ); 283 delete( rest ); 284 } // delete 278 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p ); 279 forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr ); 280 forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest ); 285 281 286 282 // Cforall allocation/deallocation and constructor/destructor, array types 287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TTp );283 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p ); 288 284 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[], TTrest );285 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) void adelete( T arr[], Params rest ); 290 286 291 287 //--------------------------------------- … … 383 379 //--------------------------------------- 384 380 385 extern bool threading_enabled( void) OPTIONAL_THREAD;381 extern bool threading_enabled(void) OPTIONAL_THREAD; 386 382 387 383 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.