Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib.c

    r45161b4d r52f85e0  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 14:49:58 2016
    13 // Update Count     : 155
     12// Last Modified On : Wed Feb 10 15:45:56 2016
     13// Update Count     : 140
    1414//
    1515
     
    2727} // extern "C"
    2828
    29 forall( otype T ) T * malloc( void ) {
    30         //printf( "malloc1\n" );
     29forall( type T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
     30        printf( "memset1\n" );
     31    return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
     32} // memset
     33forall( type T ) T * memset( T * ptr ) {                                // remove when default value available
     34        printf( "memset2\n" );
     35    return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
     36} // memset
     37
     38forall( type T ) T * malloc( void ) {
     39        printf( "malloc1\n" );
    3140    return (T *)malloc( sizeof(T) );
    3241} // malloc
    33 forall( otype T ) T * malloc( char fill ) {
    34         //printf( "malloc3\n" );
     42forall( type T ) T * malloc( size_t size ) {
     43        printf( "malloc2\n" );
     44    return (T *)(void *)malloc( size );
     45} // malloc
     46forall( type T ) T * malloc( char fill ) {
     47        printf( "malloc3\n" );
    3548        T * ptr = (T *)malloc( sizeof(T) );
    3649    return memset( ptr );
    3750} // malloc
    3851
    39 forall( otype T ) T * calloc( size_t nmemb ) {
    40         //printf( "calloc\n" );
    41     return (T *)calloc( nmemb, sizeof(T) );
     52forall( type T ) T * calloc( size_t size ) {
     53        printf( "calloc\n" );
     54    return (T *)calloc( size, sizeof(T) );
    4255} // calloc
    4356
    44 forall( otype T ) T * realloc( T * ptr, size_t size ) {
    45         //printf( "realloc1\n" );
     57forall( type T ) T * realloc( T * ptr, size_t size ) {
     58        printf( "realloc1\n" );
    4659    return (T *)(void *)realloc( (void *)ptr, size );
    4760} // realloc
    48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
    49         //printf( "realloc2\n" );
     61forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
     62        printf( "realloc2\n" );
    5063    char * nptr = (T *)(void *)realloc( (void *)ptr, size );
    5164    size_t unused = malloc_usable_size( nptr );
     
    5467} // realloc
    5568
    56 forall( otype T ) T * malloc( T * ptr, size_t size ) {
    57         //printf( "malloc4\n" );
     69forall( type T ) T * malloc( T * ptr, size_t size ) {
     70        printf( "malloc4\n" );
    5871    return (T *)realloc( ptr, size );
    5972} // malloc
    60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
    61         //printf( "malloc5\n" );
     73forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
     74        printf( "malloc5\n" );
    6275    return (T *)realloc( ptr, size, fill );
    6376} // malloc
    6477
    65 forall( otype T ) T * aligned_alloc( size_t alignment ) {
    66         //printf( "aligned_alloc\n" );
     78forall( type T ) T * aligned_alloc( size_t alignment ) {
     79        printf( "aligned_alloc\n" );
    6780    return (T *)memalign( alignment, sizeof(T) );
    6881} // aligned_alloc
    6982
    70 forall( otype T ) T * memalign( size_t alignment ) {
    71         //printf( "memalign\n" );
     83forall( type T ) T * memalign( size_t alignment ) {
     84        printf( "memalign\n" );
    7285    return (T *)memalign( alignment, sizeof(T) );
    7386} // memalign
    7487
    75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {
    76         //printf( "posix_memalign\n" );
     88forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {
     89        printf( "posix_memalign\n" );
    7790    return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    7891} // posix_memalign
    79 
    80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
    81         //printf( "memset1\n" );
    82     return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
    83 } // memset
    84 forall( otype T ) T * memset( T * ptr ) {                               // remove when default value available
    85         //printf( "memset2\n" );
    86     return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
    87 } // memset
    8892
    8993//---------------------------------------
     
    119123        return ulli;
    120124}
    121 
    122125float ato( const char * ptr ) {
    123126        float f;
     
    135138        return ld;
    136139}
    137 
    138140float _Complex ato( const char * ptr ) {
    139141        float re, im;
     
    170172        return strtoull( sptr, eptr, base );
    171173}
    172 
    173174float strto( const char * sptr, char ** eptr ) {
    174175        return strtof( sptr, eptr );
     
    180181        return strtold( sptr, eptr );
    181182}
    182 
    183183float _Complex strto( const char * sptr, char ** eptr ) {
    184184        float re, im;
     
    208208//---------------------------------------
    209209
    210 forall( otype T | { int ?<?( T, T ); } )
     210forall( type T | { int ?<?( T, T ); } )
    211211T * bsearch( const T key, const T * arr, size_t dimension ) {
    212212        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    214214} // bsearch
    215215
    216 forall( otype T | { int ?<?( T, T ); } )
     216forall( type T | { int ?<?( T, T ); } )
    217217void qsort( const T * arr, size_t dimension ) {
    218218        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     
    222222//---------------------------------------
    223223
    224 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
     224forall( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
    225225[ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ }
    226226
     
    239239//---------------------------------------
    240240
    241 float floor( float v ) { return floorf( v ); }
    242 long double floor( long double v ) { return floorl( v ); }
    243 
    244 float ceil( float v ) { return ceilf( v ); }
    245 long double ceil( long double v ) { return ceill( v ); }
    246 
    247 //---------------------------------------
    248 
    249 void rand48seed( long int s ) { srand48( s ); }
    250 char rand48() { return mrand48(); }
    251 int rand48() { return mrand48(); }
    252 unsigned int rand48() { return lrand48(); }
    253 long int rand48() { return mrand48(); }
    254 unsigned long int rand48() { return lrand48(); }
    255 float rand48() { return (float)drand48(); }                             // otherwise float uses lrand48
    256 double rand48() { return drand48(); }
    257 float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
    258 double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
    259 long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
    260 
    261 //---------------------------------------
    262 
    263 forall( otype T | { int ?<?( T, T ); } )
     241void randseed( long int s ) { srand48( s ); }
     242char random() { return lrand48(); }
     243int random() { return mrand48(); }
     244unsigned int random() { return lrand48(); }
     245long int random() { return mrand48(); }
     246unsigned long int random() { return lrand48(); }
     247float random() { return (float)drand48(); }                             // otherwise float uses lrand48
     248double random() { return drand48(); }
     249float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     250double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     251long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     252
     253//---------------------------------------
     254
     255forall( type T | { int ?<?( T, T ); } )
    264256T min( const T t1, const T t2 ) {
    265257        return t1 < t2 ? t1 : t2;
    266258} // min
    267259
    268 forall( otype T | { int ?>?( T, T ); } )
     260forall( type T | { int ?>?( T, T ); } )
    269261T max( const T t1, const T t2 ) {
    270262        return t1 > t2 ? t1 : t2;
    271263} // max
    272264
    273 forall( otype T )
     265forall( type T )
    274266void swap( T * t1, T * t2 ) {
    275267        T temp = *t1;
Note: See TracChangeset for help on using the changeset viewer.