Changes in libcfa/src/stdlib.cfa [2026bb6:e3fea42]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r2026bb6 re3fea42 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 24 17:34:44 201913 // Update Count : 4 6212 // Last Modified On : Tue Feb 4 08:27:08 2020 13 // Update Count : 486 14 14 // 15 15 … … 21 21 #include <string.h> // memcpy, memset 22 22 #include <malloc.h> // malloc_usable_size 23 #include <math.h> // fabsf, fabs, fabsl23 //#include <math.h> // fabsf, fabs, fabsl 24 24 #include <complex.h> // _Complex_I 25 25 #include <assert.h> … … 27 27 //--------------------------------------- 28 28 29 // resize, non-array types 30 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ) { 31 size_t olen = malloc_usable_size( ptr ); // current allocation 32 char * nptr = (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 33 size_t nlen = malloc_usable_size( nptr ); // new allocation 34 if ( nlen > olen ) { // larger ? 35 memset( nptr + olen, (int)fill, nlen - olen ); // initialize added storage 36 } // 37 return (T *)nptr; 38 } // alloc 29 forall( dtype T | sized(T) ) { 30 T * alloc_set( T ptr[], size_t dim, char fill ) { // realloc array with fill 31 size_t olen = malloc_usable_size( ptr ); // current allocation 32 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc 33 size_t nlen = malloc_usable_size( nptr ); // new allocation 34 if ( nlen > olen ) { // larger ? 35 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage 36 } // if 37 return (T *)nptr; 38 } // alloc_set 39 40 T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill 41 size_t olen = malloc_usable_size( ptr ); // current allocation 42 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc 43 // char * nptr = alloc_align( ptr, align ); 44 size_t nlen = malloc_usable_size( nptr ); // new allocation 45 if ( nlen > olen ) { // larger ? 46 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage 47 } // if 48 return (T *)nptr; 49 } // alloc_align_set 50 } // distribution 39 51 40 52 // allocation/deallocation and constructor/destructor, non-array types 41 53 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 42 54 T * new( Params p ) { 43 return &(*malloc()){ p }; // run constructor55 return &(*malloc()){ p }; // run constructor 44 56 } // new 45 57 … … 47 59 void delete( T * ptr ) { 48 60 if ( ptr ) { // ignore null 49 ^(*ptr){}; // run destructor61 ^(*ptr){}; // run destructor 50 62 free( ptr ); 51 63 } // if … … 55 67 void delete( T * ptr, Params rest ) { 56 68 if ( ptr ) { // ignore null 57 ^(*ptr){}; // run destructor69 ^(*ptr){}; // run destructor 58 70 free( ptr ); 59 71 } // if … … 95 107 //--------------------------------------- 96 108 97 float _Complex strto( const char * sptr, char ** eptr ) {109 float _Complex strto( const char sptr[], char ** eptr ) { 98 110 float re, im; 99 111 char * eeptr; … … 106 118 } // strto 107 119 108 double _Complex strto( const char * sptr, char ** eptr ) {120 double _Complex strto( const char sptr[], char ** eptr ) { 109 121 double re, im; 110 122 char * eeptr; … … 117 129 } // strto 118 130 119 long double _Complex strto( const char * sptr, char ** eptr ) {131 long double _Complex strto( const char sptr[], char ** eptr ) { 120 132 long double re, im; 121 133 char * eeptr;
Note:
See TracChangeset
for help on using the changeset viewer.