Changeset 59239b8


Ignore:
Timestamp:
Jan 30, 2017, 12:29:29 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
1e6e231a
Parents:
f97b614
Message:

new, delete, malloc, etc. no longer require an otype, only a sized dtype

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib

    rf97b614 r59239b8  
    2929
    3030extern "C" { void * malloc( size_t ); }                                 // use default C routine for void *
    31 forall( otype T ) T * malloc( void );
    32 forall( otype T ) T * malloc( char fill );
    33 forall( otype T ) T * malloc( T * ptr, size_t size );
    34 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
     31forall( dtype T | sized(T) ) T * malloc( void );
     32forall( dtype T | sized(T) ) T * malloc( char fill );
     33forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );
     34forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill );
    3535extern "C" { void * calloc( size_t nmemb, size_t size ); } // use default C routine for void *
    36 forall( otype T ) T * calloc( size_t nmemb );
     36forall( dtype T | sized(T) ) T * calloc( size_t nmemb );
    3737extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
    38 forall( otype T ) T * realloc( T * ptr, size_t size );
    39 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
     38forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
     39forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill );
    4040
    41 forall( otype T ) T * aligned_alloc( size_t alignment );
    42 forall( otype T ) T * memalign( size_t alignment );             // deprecated
    43 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     41forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );
     42forall( dtype T | sized(T) ) T * memalign( size_t alignment );          // deprecated
     43forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );
    4444
    4545extern "C" {
     
    4848} // extern "C"
    4949
    50 forall( otype T, ttype Params | { void ?{}(T *, Params); } ) T * new( Params p );
     50forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
    5151forall( dtype T | { void ^?{}(T *); } ) void delete( T * ptr );
    5252
  • src/libcfa/stdlib.c

    rf97b614 r59239b8  
    2727} // extern "C"
    2828
    29 forall( otype T ) T * malloc( void ) {
     29forall( dtype T | sized(T) ) T * malloc( void ) {
    3030        //printf( "malloc1\n" );
    3131    return (T *)malloc( sizeof(T) );
    3232} // malloc
    33 forall( otype T ) T * malloc( char fill ) {
     33forall( dtype T | sized(T) ) T * malloc( char fill ) {
    3434        //printf( "malloc3\n" );
    3535        T * ptr = (T *)malloc( sizeof(T) );
     
    3737} // malloc
    3838
    39 forall( otype T ) T * calloc( size_t nmemb ) {
     39forall( dtype T | sized(T) ) T * calloc( size_t nmemb ) {
    4040        //printf( "calloc\n" );
    4141    return (T *)calloc( nmemb, sizeof(T) );
    4242} // calloc
    4343
    44 forall( otype T ) T * realloc( T * ptr, size_t size ) {
     44forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
    4545        //printf( "realloc1\n" );
    4646    return (T *)(void *)realloc( (void *)ptr, size );
    4747} // realloc
    48 forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
     48forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill ) {
    4949        //printf( "realloc2\n" );
    5050    char * nptr = (T *)(void *)realloc( (void *)ptr, size );
     
    5454} // realloc
    5555
    56 forall( otype T ) T * malloc( T * ptr, size_t size ) {
     56forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size ) {
    5757        //printf( "malloc4\n" );
    5858    return (T *)realloc( ptr, size );
    5959} // malloc
    60 forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
     60forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill ) {
    6161        //printf( "malloc5\n" );
    6262    return (T *)realloc( ptr, size, fill );
    6363} // malloc
    6464
    65 forall( otype T ) T * aligned_alloc( size_t alignment ) {
     65forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment ) {
    6666        //printf( "aligned_alloc\n" );
    6767    return (T *)memalign( alignment, sizeof(T) );
    6868} // aligned_alloc
    6969
    70 forall( otype T ) T * memalign( size_t alignment ) {
     70forall( dtype T | sized(T) ) T * memalign( size_t alignment ) {
    7171        //printf( "memalign\n" );
    7272    return (T *)memalign( alignment, sizeof(T) );
    7373} // memalign
    7474
    75 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ) {
     75forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment ) {
    7676        //printf( "posix_memalign\n" );
    7777    return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    7878} // posix_memalign
    7979
    80 forall( otype T, ttype Params | { void ?{}(T *, Params); } )
     80forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } )
    8181T * new( Params p ) {
    8282        return ((T*)malloc()){ p };
  • src/tests/dtor-early-exit.c

    rf97b614 r59239b8  
    2828// don't want these called
    2929void ?{}(A * a) { assert( false ); }
    30 void ?{}(A * a, char * name) { a->name = name; sout | "construct " | name | endl; a->x = malloc(); }
     30void ?{}(A * a, char * name) { a->name = name; sout | "construct " | name | endl; a->x = (int*)malloc(); }
    3131void ?{}(A * a, char * name, int * ptr) { assert( false ); }
    3232
    3333A ?=?(A * a, A a) {  sout | "assign " | a->name | " " | a.name; return a; }
    34 void ?{}(A * a, A a) { sout | "copy construct " | a.name | endl; a->x = malloc(); }
     34void ?{}(A * a, A a) { sout | "copy construct " | a.name | endl; a->x = (int*)malloc(); }
    3535void ^?{}(A * a) { sout | "destruct " | a->name | endl; free(a->x); }
    3636
  • src/tests/tupleVariadic.c

    rf97b614 r59239b8  
    2929}
    3030
    31 forall(otype T, ttype Params | { void ?{}(T *, Params); })
     31forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } )
    3232T * new(Params p);
    3333
Note: See TracChangeset for help on using the changeset viewer.