Ignore:
Timestamp:
Apr 15, 2016, 12:03:11 PM (9 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
29ad0ac
Parents:
c5833e8 (diff), 37f0da8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into gc_noraii

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib.c

    rc5833e8 r0f9e4403  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 10 15:45:56 2016
    13 // Update Count     : 140
     12// Last Modified On : Wed Apr 13 14:49:58 2016
     13// Update Count     : 155
    1414//
    1515
     
    2727} // extern "C"
    2828
    29 forall( 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
    33 forall( 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 
    38 forall( type T ) T * malloc( void ) {
    39         printf( "malloc1\n" );
     29forall( otype T ) T * malloc( void ) {
     30        //printf( "malloc1\n" );
    4031    return (T *)malloc( sizeof(T) );
    4132} // malloc
    42 forall( type T ) T * malloc( size_t size ) {
    43         printf( "malloc2\n" );
    44     return (T *)(void *)malloc( size );
    45 } // malloc
    46 forall( type T ) T * malloc( char fill ) {
    47         printf( "malloc3\n" );
     33forall( otype T ) T * malloc( char fill ) {
     34        //printf( "malloc3\n" );
    4835        T * ptr = (T *)malloc( sizeof(T) );
    4936    return memset( ptr );
    5037} // malloc
    5138
    52 forall( type T ) T * calloc( size_t size ) {
    53         printf( "calloc\n" );
    54     return (T *)calloc( size, sizeof(T) );
     39forall( otype T ) T * calloc( size_t nmemb ) {
     40        //printf( "calloc\n" );
     41    return (T *)calloc( nmemb, sizeof(T) );
    5542} // calloc
    5643
    57 forall( type T ) T * realloc( T * ptr, size_t size ) {
    58         printf( "realloc1\n" );
     44forall( otype T ) T * realloc( T * ptr, size_t size ) {
     45        //printf( "realloc1\n" );
    5946    return (T *)(void *)realloc( (void *)ptr, size );
    6047} // realloc
    61 forall( type T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
    62         printf( "realloc2\n" );
     48forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
     49        //printf( "realloc2\n" );
    6350    char * nptr = (T *)(void *)realloc( (void *)ptr, size );
    6451    size_t unused = malloc_usable_size( nptr );
     
    6754} // realloc
    6855
    69 forall( type T ) T * malloc( T * ptr, size_t size ) {
    70         printf( "malloc4\n" );
     56forall( otype T ) T * malloc( T * ptr, size_t size ) {
     57        //printf( "malloc4\n" );
    7158    return (T *)realloc( ptr, size );
    7259} // malloc
    73 forall( type T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
    74         printf( "malloc5\n" );
     60forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
     61        //printf( "malloc5\n" );
    7562    return (T *)realloc( ptr, size, fill );
    7663} // malloc
    7764
    78 forall( type T ) T * aligned_alloc( size_t alignment ) {
    79         printf( "aligned_alloc\n" );
     65forall( otype T ) T * aligned_alloc( size_t alignment ) {
     66        //printf( "aligned_alloc\n" );
    8067    return (T *)memalign( alignment, sizeof(T) );
    8168} // aligned_alloc
    8269
    83 forall( type T ) T * memalign( size_t alignment ) {
    84         printf( "memalign\n" );
     70forall( otype T ) T * memalign( size_t alignment ) {
     71        //printf( "memalign\n" );
    8572    return (T *)memalign( alignment, sizeof(T) );
    8673} // memalign
    8774
    88 forall( type T ) int posix_memalign( T ** ptr, size_t alignment ) {
    89         printf( "posix_memalign\n" );
     75forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {
     76        //printf( "posix_memalign\n" );
    9077    return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    9178} // posix_memalign
     79
     80forall( 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
     84forall( 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
    9288
    9389//---------------------------------------
     
    123119        return ulli;
    124120}
     121
    125122float ato( const char * ptr ) {
    126123        float f;
     
    138135        return ld;
    139136}
     137
    140138float _Complex ato( const char * ptr ) {
    141139        float re, im;
     
    172170        return strtoull( sptr, eptr, base );
    173171}
     172
    174173float strto( const char * sptr, char ** eptr ) {
    175174        return strtof( sptr, eptr );
     
    181180        return strtold( sptr, eptr );
    182181}
     182
    183183float _Complex strto( const char * sptr, char ** eptr ) {
    184184        float re, im;
     
    208208//---------------------------------------
    209209
    210 forall( type T | { int ?<?( T, T ); } )
     210forall( otype 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( type T | { int ?<?( T, T ); } )
     216forall( otype 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( type T | { T ?/?( T, T ); T ?%?( T, T ); } )
     224forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    225225[ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ }
    226226
     
    239239//---------------------------------------
    240240
    241 void randseed( long int s ) { srand48( s ); }
    242 char random() { return lrand48(); }
    243 int random() { return mrand48(); }
    244 unsigned int random() { return lrand48(); }
    245 long int random() { return mrand48(); }
    246 unsigned long int random() { return lrand48(); }
    247 float random() { return (float)drand48(); }                             // otherwise float uses lrand48
    248 double random() { return drand48(); }
    249 float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
    250 double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
    251 long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
    252 
    253 //---------------------------------------
    254 
    255 forall( type T | { int ?<?( T, T ); } )
     241float floor( float v ) { return floorf( v ); }
     242long double floor( long double v ) { return floorl( v ); }
     243
     244float ceil( float v ) { return ceilf( v ); }
     245long double ceil( long double v ) { return ceill( v ); }
     246
     247//---------------------------------------
     248
     249void rand48seed( long int s ) { srand48( s ); }
     250char rand48() { return mrand48(); }
     251int rand48() { return mrand48(); }
     252unsigned int rand48() { return lrand48(); }
     253long int rand48() { return mrand48(); }
     254unsigned long int rand48() { return lrand48(); }
     255float rand48() { return (float)drand48(); }                             // otherwise float uses lrand48
     256double rand48() { return drand48(); }
     257float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     258double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     259long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     260
     261//---------------------------------------
     262
     263forall( otype T | { int ?<?( T, T ); } )
    256264T min( const T t1, const T t2 ) {
    257265        return t1 < t2 ? t1 : t2;
    258266} // min
    259267
    260 forall( type T | { int ?>?( T, T ); } )
     268forall( otype T | { int ?>?( T, T ); } )
    261269T max( const T t1, const T t2 ) {
    262270        return t1 > t2 ? t1 : t2;
    263271} // max
    264272
    265 forall( type T )
     273forall( otype T )
    266274void swap( T * t1, T * t2 ) {
    267275        T temp = *t1;
Note: See TracChangeset for help on using the changeset viewer.