Changes in libcfa/src/stdlib.cfa [e3fea42:2026bb6]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
re3fea42 r2026bb6 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 4 08:27:08 202013 // Update Count : 4 8612 // Last Modified On : Mon Jun 24 17:34:44 2019 13 // Update Count : 462 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 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 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 51 39 52 40 // allocation/deallocation and constructor/destructor, non-array types 53 41 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) 54 42 T * new( Params p ) { 55 return &(*malloc()){ p }; // run constructor43 return &(*malloc()){ p }; // run constructor 56 44 } // new 57 45 … … 59 47 void delete( T * ptr ) { 60 48 if ( ptr ) { // ignore null 61 ^(*ptr){}; // run destructor49 ^(*ptr){}; // run destructor 62 50 free( ptr ); 63 51 } // if … … 67 55 void delete( T * ptr, Params rest ) { 68 56 if ( ptr ) { // ignore null 69 ^(*ptr){}; // run destructor57 ^(*ptr){}; // run destructor 70 58 free( ptr ); 71 59 } // if … … 107 95 //--------------------------------------- 108 96 109 float _Complex strto( const char sptr[], char ** eptr ) {97 float _Complex strto( const char * sptr, char ** eptr ) { 110 98 float re, im; 111 99 char * eeptr; … … 118 106 } // strto 119 107 120 double _Complex strto( const char sptr[], char ** eptr ) {108 double _Complex strto( const char * sptr, char ** eptr ) { 121 109 double re, im; 122 110 char * eeptr; … … 129 117 } // strto 130 118 131 long double _Complex strto( const char sptr[], char ** eptr ) {119 long double _Complex strto( const char * sptr, char ** eptr ) { 132 120 long double re, im; 133 121 char * eeptr;
Note:
See TracChangeset
for help on using the changeset viewer.