Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r2026bb6 re3fea42  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 24 17:34:44 2019
    13 // Update Count     : 462
     12// Last Modified On : Tue Feb  4 08:27:08 2020
     13// Update Count     : 486
    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 // 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
     29forall( 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
    3951
    4052// allocation/deallocation and constructor/destructor, non-array types
    4153forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } )
    4254T * new( Params p ) {
    43         return &(*malloc()){ p };                                                               // run constructor
     55        return &(*malloc()){ p };                                                       // run constructor
    4456} // new
    4557
     
    4759void delete( T * ptr ) {
    4860        if ( ptr ) {                                                                            // ignore null
    49                 ^(*ptr){};                                                                                      // run destructor
     61                ^(*ptr){};                                                                              // run destructor
    5062                free( ptr );
    5163        } // if
     
    5567void delete( T * ptr, Params rest ) {
    5668        if ( ptr ) {                                                                            // ignore null
    57                 ^(*ptr){};                                                                                      // run destructor
     69                ^(*ptr){};                                                                              // run destructor
    5870                free( ptr );
    5971        } // if
     
    95107//---------------------------------------
    96108
    97 float _Complex strto( const char * sptr, char ** eptr ) {
     109float _Complex strto( const char sptr[], char ** eptr ) {
    98110        float re, im;
    99111        char * eeptr;
     
    106118} // strto
    107119
    108 double _Complex strto( const char * sptr, char ** eptr ) {
     120double _Complex strto( const char sptr[], char ** eptr ) {
    109121        double re, im;
    110122        char * eeptr;
     
    117129} // strto
    118130
    119 long double _Complex strto( const char * sptr, char ** eptr ) {
     131long double _Complex strto( const char sptr[], char ** eptr ) {
    120132        long double re, im;
    121133        char * eeptr;
Note: See TracChangeset for help on using the changeset viewer.