Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    re3fea42 r2026bb6  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 08:27:08 2020
    13 // Update Count     : 486
     12// Last Modified On : Mon Jun 24 17:34:44 2019
     13// Update Count     : 462
    1414//
    1515
     
    2121#include <string.h>                                                                             // memcpy, memset
    2222#include <malloc.h>                                                                             // malloc_usable_size
    23 //#include <math.h>                                                                             // fabsf, fabs, fabsl
     23#include <math.h>                                                                               // fabsf, fabs, fabsl
    2424#include <complex.h>                                                                    // _Complex_I
    2525#include <assert.h>
     
    2727//---------------------------------------
    2828
    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
     30forall( 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
    5139
    5240// allocation/deallocation and constructor/destructor, non-array types
    5341forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    5442T * new( Params p ) {
    55         return &(*malloc()){ p };                                                       // run constructor
     43        return &(*malloc()){ p };                                                               // run constructor
    5644} // new
    5745
     
    5947void delete( T * ptr ) {
    6048        if ( ptr ) {                                                                            // ignore null
    61                 ^(*ptr){};                                                                              // run destructor
     49                ^(*ptr){};                                                                                      // run destructor
    6250                free( ptr );
    6351        } // if
     
    6755void delete( T * ptr, Params rest ) {
    6856        if ( ptr ) {                                                                            // ignore null
    69                 ^(*ptr){};                                                                              // run destructor
     57                ^(*ptr){};                                                                                      // run destructor
    7058                free( ptr );
    7159        } // if
     
    10795//---------------------------------------
    10896
    109 float _Complex strto( const char sptr[], char ** eptr ) {
     97float _Complex strto( const char * sptr, char ** eptr ) {
    11098        float re, im;
    11199        char * eeptr;
     
    118106} // strto
    119107
    120 double _Complex strto( const char sptr[], char ** eptr ) {
     108double _Complex strto( const char * sptr, char ** eptr ) {
    121109        double re, im;
    122110        char * eeptr;
     
    129117} // strto
    130118
    131 long double _Complex strto( const char sptr[], char ** eptr ) {
     119long double _Complex strto( const char * sptr, char ** eptr ) {
    132120        long double re, im;
    133121        char * eeptr;
Note: See TracChangeset for help on using the changeset viewer.