Changeset f94ca7e for src


Ignore:
Timestamp:
Jun 2, 2017, 5:42:10 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0db6fc0
Parents:
2164637 (diff), 2c6c893 (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' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.impl.h

    r2164637 rf94ca7e  
    11#pragma once
     2
     3#define VISIT_START( node )  \
     4        call_previsit( node ); \
     5
     6#define VISIT_END( node )                \
     7        return call_postvisit( node ); \
    28
    39#define MUTATE_START( node )  \
    410        call_premutate( node ); \
    511
    6 
    712#define MUTATE_END( type, node )                \
    813        return call_postmutate< type * >( node ); \
     
    1015
    1116#define VISIT_BODY( node )    \
    12         call_previsit( node );  \
     17        VISIT_START( node );  \
    1318        Visitor::visit( node ); \
    14         call_postvisit( node ); \
     19        VISIT_END( node ); \
    1520
    1621
     
    3944                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    4045                try {
    41                         *i = (*i)->accept( *this );
     46                        (*i)->accept( *this );
    4247                } catch ( SemanticError &e ) {
    4348                        errors.append( e );
     
    7883        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    7984
    80         Statement *newStmt = maybeVisit( stmt, *this );
     85        maybeAccept( stmt, *this );
    8186
    8287        StmtList_t* beforeStmts = get_beforeStmts();
    8388        StmtList_t* afterStmts  = get_afterStmts();
    8489
    85         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
     90        if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
    8691
    8792        CompoundStmt *compound = new CompoundStmt( noLabels );
    8893        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    89         compound->get_kids().push_back( newStmt );
     94        compound->get_kids().push_back( stmt );
    9095        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    9196        return compound;
     
    187192}
    188193
     194//--------------------------------------------------------------------------
     195// CompoundStmt
    189196template< typename pass_type >
    190197void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
    191         VISIT_BODY( node );
     198        VISIT_START( node );
     199        call_beginScope();
     200
     201        visitStatementList( node->get_kids() );
     202
     203        call_endScope();
     204        VISIT_END( node );
    192205}
    193206
     
    203216}
    204217
     218//--------------------------------------------------------------------------
     219// ExprStmt
    205220template< typename pass_type >
    206221void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    207         VISIT_BODY( node );
     222        VISIT_START( node );
     223        call_beginScope();
     224
     225        visitExpression( node->get_expr() );
     226
     227        call_endScope();
     228        VISIT_END( node );
    208229}
    209230
     
    222243}
    223244
     245//--------------------------------------------------------------------------
     246// IfStmt
    224247template< typename pass_type >
    225248void PassVisitor< pass_type >::visit( IfStmt * node ) {
    226         VISIT_BODY( node );
     249        VISIT_START( node );
     250
     251        visitExpression( node->get_condition() );
     252        node->set_thenPart ( visitStatement( node->get_thenPart() ) );
     253        node->set_elsePart ( visitStatement( node->get_elsePart() ) );
     254
     255        VISIT_END( node );
    227256}
    228257
     
    238267}
    239268
     269//--------------------------------------------------------------------------
     270// WhileStmt
    240271template< typename pass_type >
    241272void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    242         VISIT_BODY( node );
     273        VISIT_START( node );
     274
     275        visitExpression( node->get_condition() );
     276        node->set_body( visitStatement( node->get_body() ) );
     277
     278        VISIT_END( node );
    243279}
    244280
     
    253289}
    254290
    255 
     291//--------------------------------------------------------------------------
     292// WhileStmt
    256293template< typename pass_type >
    257294void PassVisitor< pass_type >::visit( ForStmt * node ) {
    258         VISIT_BODY( node );
     295        VISIT_START( node );
     296
     297        acceptAll( node->get_initialization(), *this );
     298        visitExpression( node->get_condition() );
     299        visitExpression( node->get_increment() );
     300        node->set_body( visitStatement( node->get_body() ) );
     301
     302        VISIT_END( node );
    259303}
    260304
     
    264308
    265309        mutateAll( node->get_initialization(), *this );
    266         node->set_condition(  mutateExpression( node->get_condition() ) );
    267         node->set_increment(  mutateExpression( node->get_increment() ) );
    268         node->set_body(  mutateStatement( node->get_body() ) );
     310        node->set_condition( mutateExpression( node->get_condition() ) );
     311        node->set_increment( mutateExpression( node->get_increment() ) );
     312        node->set_body( mutateStatement( node->get_body() ) );
    269313
    270314        MUTATE_END( Statement, node );
    271315}
    272316
     317//--------------------------------------------------------------------------
     318// SwitchStmt
    273319template< typename pass_type >
    274320void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    275         VISIT_BODY( node );
     321        VISIT_START( node );
     322
     323        visitExpression( node->get_condition() );
     324        visitStatementList( node->get_statements() );
     325
     326        VISIT_END( node );
    276327}
    277328
     
    286337}
    287338
     339//--------------------------------------------------------------------------
     340// SwitchStmt
    288341template< typename pass_type >
    289342void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    290         VISIT_BODY( node );
     343        VISIT_START( node );
     344       
     345        visitExpression( node->get_condition() );
     346        visitStatementList( node->get_statements() );
     347       
     348        VISIT_END( node );
    291349}
    292350
     
    306364}
    307365
     366//--------------------------------------------------------------------------
     367// ReturnStmt
    308368template< typename pass_type >
    309369void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
    310         VISIT_BODY( node );
     370        VISIT_START( node );
     371
     372        visitExpression( node->get_expr() );
     373
     374        VISIT_END( node );
    311375}
    312376
     
    320384}
    321385
     386//--------------------------------------------------------------------------
     387// TryStmt
    322388template< typename pass_type >
    323389void PassVisitor< pass_type >::visit( TryStmt * node ) {
    324         VISIT_BODY( node );
     390        VISIT_START( node );
     391
     392        maybeAccept( node->get_block(), *this );
     393        acceptAll( node->get_catchers(), *this );
     394
     395        VISIT_END( node );
    325396}
    326397
     
    335406}
    336407
     408//--------------------------------------------------------------------------
     409// CatchStmt
    337410template< typename pass_type >
    338411void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    339         VISIT_BODY( node );
     412        VISIT_START( node );
     413
     414        node->set_body( visitStatement( node->get_body() ) );
     415        maybeAccept( node->get_decl(), *this );
     416
     417        VISIT_END( node );
    340418}
    341419
     
    375453}
    376454
     455//--------------------------------------------------------------------------
     456// UntypedExpr
    377457template< typename pass_type >
    378458void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
    379         VISIT_BODY( node );
     459        VISIT_START( node );
     460
     461        for ( auto expr : node->get_args() ) {
     462                visitExpression( expr );
     463        }
     464
     465        VISIT_END( node );
    380466}
    381467
     
    536622}
    537623
     624//--------------------------------------------------------------------------
     625// UntypedExpr
    538626template< typename pass_type >
    539627void PassVisitor< pass_type >::visit( StmtExpr * node ) {
    540         VISIT_BODY( node );
     628        VISIT_START( node );
     629
     630        // don't want statements from outer CompoundStmts to be added to this StmtExpr
     631        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     632        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
     633        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     634
     635        Visitor::visit( node );
     636
     637        VISIT_END( node );
    541638}
    542639
     
    640737}
    641738
     739//--------------------------------------------------------------------------
     740// UntypedExpr
    642741template< typename pass_type >
    643742void PassVisitor< pass_type >::visit( SingleInit * node ) {
    644         VISIT_BODY( node );
     743        VISIT_START( node );
     744
     745        visitExpression( node->get_value() );
     746
     747        VISIT_END( node );
    645748}
    646749
  • src/Makefile.am

    r2164637 rf94ca7e  
    4343driver_cfa_cpp_SOURCES = ${SRC}
    4444driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     45driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    4646driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    4747
  • src/Makefile.in

    r2164637 rf94ca7e  
    447447driver_cfa_cpp_SOURCES = ${SRC}
    448448driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    449 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     449driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    450450driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    451451all: $(BUILT_SOURCES)
  • src/Parser/lex.ll

    r2164637 rf94ca7e  
    55 * file "LICENCE" distributed with Cforall.
    66 *
    7  * lex.l --
     7 * lex.ll --
    88 *
    99 * Author           : Peter A. Buhr
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon May 22 07:46:30 2017
    13  * Update Count     : 525
     12 * Last Modified On : Tue May 30 22:00:48 2017
     13 * Update Count     : 527
    1414 */
    1515
     
    235235long                    { KEYWORD_RETURN(LONG); }
    236236lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
    237 monitor         { KEYWORD_RETURN(MONITOR); }                    // CFA
     237monitor                 { KEYWORD_RETURN(MONITOR); }                    // CFA
    238238mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
    239239_Noreturn               { KEYWORD_RETURN(NORETURN); }                   // C11
  • src/libcfa/stdlib

    r2164637 rf94ca7e  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 30 09:07:35 2017
    13 // Update Count     : 164
     12// Last Modified On : Fri Jun  2 15:51:03 2017
     13// Update Count     : 218
    1414//
    1515
     
    2828//---------------------------------------
    2929
    30 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
    31 
    3230// allocation, non-array types
    3331static inline forall( dtype T | sized(T) ) T * malloc( void ) {
     
    3533        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    3634} // malloc
    37 static inline forall( dtype T | sized(T) ) T * malloc( char fill ) {
     35
     36extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
     37static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
    3838        //printf( "X2\n" );
     39        return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
     40}
     41
     42extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void *
     43static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
     44        //printf( "X3\n" );
     45        return (T *)(void *)realloc( (void *)ptr, size );
     46}
     47
     48extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
     49static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) {
     50        //printf( "X4\n" );
     51        return (T *)memalign( align, sizeof(T) );
     52} // memalign
     53
     54static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) {
     55        //printf( "X5\n" );
     56        return (T *)memalign( align, sizeof(T) );
     57} // aligned_alloc
     58
     59extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void *
     60static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ) {
     61        //printf( "X6\n" );
     62        return posix_memalign( (void **)ptr, align, sizeof(T) );
     63} // posix_memalign
     64
     65
     66extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
     67
     68static inline forall( dtype T | sized(T) ) T * alloc( void ) {
     69        //printf( "X7\n" );
     70        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
     71} // alloc
     72static inline forall( dtype T | sized(T) ) T * alloc( char fill ) {
     73        //printf( "X8\n" );
    3974        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    4075    return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
    41 } // malloc
    42 
    43 // allocation, array types
    44 extern "C" { void * calloc( size_t dim, size_t size ); } // use default C routine for void *
    45 static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
    46         //printf( "X3\n" );
    47         return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
    48 }
    49 static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim ) { // alternative name
    50         //printf( "X4\n" );
     76} // alloc
     77
     78static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) {
     79        //printf( "X9\n" );
    5180        return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    52 } // amalloc
    53 static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill ) { // alternative name
    54         //printf( "X5\n" );
     81} // alloc
     82static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) {
     83        //printf( "X10\n" );
    5584        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    5685    return memset( ptr, (int)fill, dim * sizeof(T) );
    57 } // amalloc
    58 
    59 // resize, non-array types
    60 extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
    61 static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
    62         //printf( "X5.5\n" );
    63         return (T *)(void *)realloc( (void *)ptr, size );
    64 }
    65 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
    66 static inline forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size ) { // alternative name
    67         //printf( "X7\n" );
    68         return realloc( ptr, size );
    69 } // malloc
    70 static inline forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill ) { // alternative name
    71         //printf( "X8\n" );
    72         return realloc( ptr, size, fill );
    73 } // malloc
    74 
    75 // resize, array types
    76 static inline forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim ) {
    77         //printf( "X9\n" );
    78         return malloc( ptr, dim * (size_t)sizeof(T) );
    79 } // amalloc
    80 static inline forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill ) {
    81         //printf( "X10\n" );
    82         return malloc( ptr, dim * (size_t)sizeof(T), fill );
    83 } // amalloc
    84 
    85 // alignment, non-array types
    86 extern "C" { void * memalign( size_t alignment, size_t size ); } // use default C routine for void *
    87 static inline forall( dtype T | sized(T) ) T * memalign( size_t alignment ) {
     86} // alloc
     87
     88static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    8889        //printf( "X11\n" );
    89         return (T *)memalign( alignment, sizeof(T) );
    90 } // memalign
    91 static inline forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill ) {
    92         //printf( "X12\n" );
    93     T * ptr = (T *)memalign( alignment, sizeof(T) );
     90        return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     91} // alloc
     92forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     93
     94static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align ) {
     95        //printf( "X13\n" );
     96        return (T *)memalign( align, sizeof(T) );
     97} // align_alloc
     98static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ) {
     99        //printf( "X14\n" );
     100    T * ptr = (T *)memalign( align, sizeof(T) );
    94101    return memset( ptr, (int)fill, sizeof(T) );
    95 } // memalign
    96 static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment ) {
    97         //printf( "X13\n" );
    98         return (T *)memalign( alignment, sizeof(T) );
    99 } // aligned_alloc
    100 extern "C" { int posix_memalign( void ** ptr, size_t alignment, size_t size ); } // use default C routine for void *
    101 static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment ) {
    102         //printf( "X14\n" );
    103         return posix_memalign( (void **)ptr, alignment, sizeof(T) );
    104 } // posix_memalign
    105 
    106 // alignment, array types
    107 static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim ) {
     102} // align_alloc
     103
     104static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) {
    108105        //printf( "X15\n" );
    109         return (T *)memalign( alignment, dim * sizeof(T) );
    110 } // amemalign
    111 static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill ) {
     106        return (T *)memalign( align, dim * sizeof(T) );
     107} // align_alloc
     108static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) {
    112109        //printf( "X16\n" );
    113     T * ptr = (T *)memalign( alignment, dim * sizeof(T) );
     110    T * ptr = (T *)memalign( align, dim * sizeof(T) );
    114111    return memset( ptr, (int)fill, dim * sizeof(T) );
    115 } // amemalign
     112} // align_alloc
     113
    116114
    117115// data, non-array types
     
    127125
    128126// data, array types
    129 static inline forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c ) {
     127static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
    130128        //printf( "X19\n" );
    131         return memset( dest, c, dim * sizeof(T) );
    132 } // amemset
    133 static inline forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim ) {
     129        return (void *)memset( dest, c, dim * sizeof(T) );      // C memset
     130} // memset
     131static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
    134132        //printf( "X20\n" );
    135         return memcpy( dest, src, dim * sizeof(T) );
    136 } // amemcpy
    137 
    138 // allocation/deallocation and constructor/destructor
    139 forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
     133        return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
     134} // memcpy
     135
     136// allocation/deallocation and constructor/destructor, non-array types
     137forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
    140138forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
    141139forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
     140
     141// allocation/deallocation and constructor/destructor, array types
     142forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
     143forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
     144forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
    142145
    143146//---------------------------------------
  • src/libcfa/stdlib.c

    r2164637 rf94ca7e  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 30 09:07:56 2017
    13 // Update Count     : 237
     12// Last Modified On : Thu Jun  1 21:52:57 2017
     13// Update Count     : 280
    1414//
    1515
     
    2828
    2929// resize, non-array types
    30 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill ) { // alternative realloc with fill value
    31         //printf( "X6\n" );
     30forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ) {
    3231        size_t olen = malloc_usable_size( ptr );                        // current allocation
    33     char * nptr = (void *)realloc( (void *)ptr, size ); // C realloc
     32    char * nptr = (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    3433        size_t nlen = malloc_usable_size( nptr );                       // new allocation
    3534        if ( nlen > olen ) {                                                            // larger ?
     
    3736        } //
    3837    return (T *)nptr;
    39 } // realloc
    40 
    41 // allocation/deallocation and constructor/destructor
    42 forall( dtype T, ttype Params | sized(T) | { void ?{}( T *, Params ); } )
     38} // alloc
     39
     40// allocation/deallocation and constructor/destructor, non-array types
     41forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
    4342T * new( Params p ) {
    44         return ((T *)malloc()){ p };
     43        return (malloc()){ p };                                                         // run constructor
    4544} // new
    4645
    4746forall( dtype T | { void ^?{}( T * ); } )
    4847void delete( T * ptr ) {
    49         if ( ptr ) {
     48        if ( ptr ) {                                                                            // ignore null
    5049                ^ptr{};                                                                                 // run destructor
    5150                free( ptr );
     
    5554forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    5655void delete( T * ptr, Params rest ) {
    57         if ( ptr ) {
     56        if ( ptr ) {                                                                            // ignore null
    5857                ^ptr{};                                                                                 // run destructor
    5958                free( ptr );
     
    6160        delete( rest );
    6261} // delete
     62
     63
     64// allocation/deallocation and constructor/destructor, array types
     65forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     66T * anew( size_t dim, Params p ) {
     67        T *arr = alloc( dim );
     68        for ( unsigned int i = 0; i < dim; i += 1 ) {
     69                (&arr[i]){ p };                                                                 // run constructor
     70        } // for
     71        return arr;
     72} // anew
     73
     74forall( dtype T | sized(T) | { void ^?{}( T * ); } )
     75void adelete( size_t dim, T arr[] ) {
     76        if ( arr ) {                                                                            // ignore null
     77                for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
     78                        ^(&arr[i]){};                                                           // run destructor
     79                } // for
     80                free( arr );
     81        } // if
     82} // adelete
     83
     84forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
     85void adelete( size_t dim, T arr[], Params rest ) {
     86        if ( arr ) {                                                                            // ignore null
     87                for ( int i = dim - 1; i >= 0; i -= 1 ) {               // reverse allocation order, must be unsigned
     88                        ^(&arr[i]){};                                                           // run destructor
     89                } // for
     90                free( arr );
     91        } // if
     92        adelete( rest );
     93} // adelete
    6394
    6495//---------------------------------------
  • src/tests/.expect/alloc.txt

    r2164637 rf94ca7e  
    1 C   malloc deadbeef
    2 CFA malloc 0
    3 CFA malloc, fill 01010101
     1C   malloc 0xdeadbeef
     2CFA malloc 0xdeadbeef
     3CFA alloc 0xdeadbeef
     4CFA alloc, fill 01010101
    45
    5 C   calloc
     6C   array calloc, fill 0
    670 0 0 0 0 0 0 0 0 0
    7 CFA calloc
     8CFA array calloc, fill 0
    890 0 0 0 0 0 0 0 0 0
    9 CFA array malloc
    10 0 0 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    11 CFA array malloc
    12 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
     10CFA array alloc, no fill
     110xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
     12CFA array alloc, fill 0x1
     130x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    1314
    1415C   realloc
    15 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     160xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    1617CFA realloc
    17 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
    18 CFA realloc
    19 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    20 CFA resize malloc
    21 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    22 CFA resize malloc, fill
    23 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
    24 CFA resize malloc, fill
    25 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     180xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    2619
    27 CFA resize array malloc
    28 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
    29 CFA resize array malloc
    30 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    31 CFA resize array malloc, fill
    32 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
    33 CFA resize array malloc, fill
    34 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     20CFA resize alloc
     210xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
     22CFA resize array alloc
     230xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     24CFA resize array alloc
     250xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
     26CFA resize array alloc, fill
     270x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     28CFA resize array alloc, fill
     290x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     30CFA resize array alloc, fill
     310x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    3532
    36 CFA aligned_alloc 42 42.5
     33C   memalign 42 42.5
    3734CFA memalign 42 42.5
    3835CFA posix_memalign 42 42.5
    39 CFA memalign fill 16843009 7.7486e-304
     36CFA posix_memalign 42 42.5
     37CFA aligned_alloc 42 42.5
     38CFA align_alloc 42 42.5
     39CFA align_alloc fill 0x1010101 0x1.1010101010101p-1007
    4040
    41 CFA memalign array
    42 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0,
    43 CFA memalign array
    44 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304, 1010101 7.7486e-304,
     41CFA array align_alloc
     4242 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
     43CFA array align_alloc, fill
     440x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
    4545
    46 CFA memset ffffffff -nan
    47 CFA memcpy ffffffff -nan
     46CFA memset 0x1010101 0x1.1010101010101p-1007
     47CFA memcpy 0x1010101 0x1.1010101010101p-1007
    4848
    4949CFA array memset
    50 ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan,
     500x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
    5151CFA memcpy
    52 deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2, deadbeef -17.2,
     520x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007, 0x1010101 0x1.1010101010101p-1007,
     53
     54CFA new initialize
     5542 42.5 42 42.5
     56CFA array new initialize
     5742 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
     5842 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
     59
    5360pointer arithmetic 0
    54 CFA deep malloc deadbeef
     61CFA deep malloc 0xdeadbeef
    5562
    5663SHOULD FAIL
  • src/tests/alloc.c

    r2164637 rf94ca7e  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 29 11:33:15 2017
    13 // Update Count     : 228
     12// Last Modified On : Fri Jun  2 15:13:03 2017
     13// Update Count     : 316
    1414//
    1515
     
    1818#include <malloc.h>                                                                             // malloc_usable_size
    1919#include <stdint.h>                                                                             // uintptr_t
     20#include <stdlib.h>                                                                             // posix_memalign
    2021} // extern
    2122#include <fstream>
     
    2829int main( void ) {
    2930    size_t dim = 10;
    30     struct S { int x; double y; } * s;
    3131    int * p;
     32        char fill = '\1';
    3233
    3334        // allocation, non-array types
     
    3536    p = (void *)malloc( sizeof(*p) );                                   // C malloc, type unsafe
    3637        *p = 0xdeadbeef;
    37         printf( "C   malloc %x\n", *p );
     38        printf( "C   malloc %#x\n", *p );
    3839    free( p );
    3940
    4041    p = malloc();                                                                               // CFA malloc, type safe
    41         printf( "CFA malloc %d\n", *p );
    42     free( p );
    43 
    44     p = malloc( '\1' );                                                                 // CFA malloc, fill
    45         printf( "CFA malloc, fill %08x\n", *p );
     42        *p = 0xdeadbeef;
     43        printf( "CFA malloc %#x\n", *p );
     44    free( p );
     45
     46    p = alloc();                                                                                // CFA alloc, type safe
     47        *p = 0xdeadbeef;
     48        printf( "CFA alloc %#x\n", *p );
     49    free( p );
     50
     51    p = alloc( fill );                                                                  // CFA alloc, fill
     52        printf( "CFA alloc, fill %08x\n", *p );
    4653
    4754
     
    5057
    5158    p = calloc( dim, sizeof( *p ) );                                    // C array calloc, type unsafe
    52         printf( "C   calloc\n" );
    53         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     59        printf( "C   array calloc, fill 0\n" );
     60        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    5461        printf( "\n" );
    5562    free( p );
    5663
    5764    p = calloc( dim );                                                                  // CFA array calloc, type safe
    58         printf( "CFA calloc\n" );
    59         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    60         printf( "\n" );
    61     free( p );
    62 
    63     p = amalloc( dim );                                                                 // CFA array malloc, type safe
    64         printf( "CFA array malloc\n" );
    65         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    66         printf( "\n" );
    67     free( p );
    68 
    69     p = amalloc( 2 * dim, '\1' );                                               // CFA array malloc, fill
    70         printf( "CFA array malloc\n" );
    71         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     65        printf( "CFA array calloc, fill 0\n" );
     66        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     67        printf( "\n" );
     68    free( p );
     69
     70    p = alloc( dim );                                                                   // CFA array alloc, type safe
     71        for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
     72        printf( "CFA array alloc, no fill\n" );
     73        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     74        printf( "\n" );
     75    free( p );
     76
     77    p = alloc( 2 * dim, fill );                                                 // CFA array alloc, fill
     78        printf( "CFA array alloc, fill %#x\n", fill );
     79        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
    7280        printf( "\n" );
    7381        // do not free
     
    7785        printf( "\n" );
    7886
    79     p = (void *)realloc( p, dim * sizeof(*p) );                 // CFA realloc
     87    p = (void *)realloc( p, dim * sizeof(*p) );                 // C realloc
     88        for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    8089        printf( "C   realloc\n" );
    81         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     90        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    8291        printf( "\n" );
    8392
    8493    p = realloc( p, 2 * dim * sizeof(*p) );                             // CFA realloc
     94        for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; }
    8595        printf( "CFA realloc\n" );
    86         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    87         printf( "\n" );
    88 
    89     p = realloc( p, dim * sizeof(*p), '\1' );                   // CFA realloc
    90         printf( "CFA realloc\n" );
    91         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    92         printf( "\n" );
    93 
    94     p = malloc( p, dim * sizeof(*p) );                                  // CFA malloc
    95         printf( "CFA resize malloc\n" );
    96         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    97         printf( "\n" );
    98 
    99     p = malloc( p, 2 * dim * sizeof(*p), '\1' );                // CFA malloc, fill
    100         printf( "CFA resize malloc, fill\n" );
    101         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    102         printf( "\n" );
    103 
    104     p = malloc( p, dim * sizeof(*p), '\1' );                    // CFA malloc, fill
    105         printf( "CFA resize malloc, fill\n" );
    106         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     96        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
    10797        printf( "\n" );
    10898        // do not free
     
    112102        printf( "\n" );
    113103
    114     p = amalloc( p, 2 * dim );                                                  // CFA array malloc
    115         printf( "CFA resize array malloc\n" );
    116         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    117         printf( "\n" );
    118 
    119     p = amalloc( p, dim );                                                              // CFA array malloc
    120         printf( "CFA resize array malloc\n" );
    121         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    122         printf( "\n" );
    123 
    124     p = amalloc( p, 2 * dim, '\1' );                                    // CFA array malloc, fill
    125         printf( "CFA resize array malloc, fill\n" );
    126         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    127         printf( "\n" );
    128 
    129     p = amalloc( p, dim, '\1' );                                                // CFA array malloc, fill
    130         printf( "CFA resize array malloc, fill\n" );
    131         for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
     104    p = alloc( p, dim );                                                                // CFA resize array alloc
     105        for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
     106        printf( "CFA resize alloc\n" );
     107        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     108        printf( "\n" );
     109
     110    p = alloc( p, 2 * dim );                                                    // CFA resize array alloc
     111        for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; }
     112        printf( "CFA resize array alloc\n" );
     113        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
     114        printf( "\n" );
     115
     116    p = alloc( p, dim );                                                                // CFA array alloc
     117        printf( "CFA resize array alloc\n" );
     118        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     119        printf( "\n" );
     120
    132121        free( p );
    133         printf( "\n" );
     122        p = 0;
     123
     124    p = alloc( p, dim, fill );                                                  // CFA array alloc, fill
     125        printf( "CFA resize array alloc, fill\n" );
     126        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     127        printf( "\n" );
     128
     129    p = alloc( p, 2 * dim, fill );                                              // CFA array alloc, fill
     130        printf( "CFA resize array alloc, fill\n" );
     131        for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
     132        printf( "\n" );
     133
     134    p = alloc( p, dim, fill );                                                  // CFA array alloc, fill
     135        printf( "CFA resize array alloc, fill\n" );
     136        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] );; }
     137        printf( "\n" );
     138        free( p );
     139
    134140
    135141    struct Struct { int x; double y; };
    136     Struct st, st1, sta[dim], sta1[dim], * stp;
    137 
     142    Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
    138143
    139144        // alignment, non-array types
    140145        printf( "\n" );
    141 
    142146        enum { Alignment = 128 };
    143     stp = aligned_alloc( Alignment );                                   // CFA aligned_alloc
     147
     148    stp = (memalign( Alignment, sizeof( *stp ) ) ){ 42, 42.5 }; // C memalign
     149        assert( (uintptr_t)stp % Alignment == 0 );
     150        printf( "C   memalign %d %g\n", stp->x, stp->y );
     151    free( stp );
     152
     153    stp = (memalign( Alignment )){ 42, 42.5 };                  // CFA memalign
     154        assert( (uintptr_t)stp % Alignment == 0 );
     155        printf( "CFA memalign %d %g\n", stp->x, stp->y );
     156    free( stp );
     157
     158    posix_memalign( (void **)&stp, Alignment, sizeof( *stp ) ); // C posix_memalign
    144159        *stp = (Struct){ 42, 42.5 };
    145160        assert( (uintptr_t)stp % Alignment == 0 );
    146         printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y );
    147     free( stp );
    148 
    149     stp = memalign( Alignment );                                                // CFA memalign
    150         *stp = (Struct){ 42, 42.5 };
    151         assert( (uintptr_t)stp % Alignment == 0 );
    152         printf( "CFA memalign %d %g\n", stp->x, stp->y );
     161        printf( "CFA posix_memalign %d %g\n", stp->x, stp->y );
    153162    free( stp );
    154163
     
    159168    free( stp );
    160169
    161     stp = memalign( Alignment, '\1' );                                  // CFA memalign, fill
    162         assert( (uintptr_t)stp % Alignment == 0 );
    163         printf( "CFA memalign fill %d %g\n", stp->x, stp->y );
     170    stp = (aligned_alloc( Alignment )){ 42, 42.5 };             // CFA aligned_alloc
     171        assert( (uintptr_t)stp % Alignment == 0 );
     172        printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y );
     173    free( stp );
     174
     175    stp = (align_alloc( Alignment )){ 42, 42.5 };               // CFA align_alloc
     176        assert( (uintptr_t)stp % Alignment == 0 );
     177        printf( "CFA align_alloc %d %g\n", stp->x, stp->y );
     178    free( stp );
     179
     180    stp = align_alloc( Alignment, fill );                               // CFA memalign, fill
     181        assert( (uintptr_t)stp % Alignment == 0 );
     182        printf( "CFA align_alloc fill %#x %a\n", stp->x, stp->y );
    164183    free( stp );
    165184
     
    168187        printf( "\n" );
    169188
    170     stp = amemalign( Alignment, 2 * dim );                              // CFA array memalign
    171         assert( (uintptr_t)stp % Alignment == 0 );
    172         printf( "CFA memalign array\n" );
    173         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%x %g, ", stp[i].x, stp[i].y ); stp[i].x = 0Xdeadbeef, stp[i].y = -17.2; }
    174         printf( "\n" );
    175     free( stp );
    176 
    177     stp = amemalign( Alignment, dim, '\1' );                    // CFA array memalign, fill
    178         assert( (uintptr_t)stp % Alignment == 0 );
    179         printf( "CFA memalign array\n" );
    180         for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", stp[i].x, stp[i].y ); stp[i].x = 0Xdeadbeef, stp[i].y = -17.2; }
     189    stp = align_alloc( Alignment, dim );                                // CFA array memalign
     190        assert( (uintptr_t)stp % Alignment == 0 );
     191        for ( int i = 0; i < dim; i += 1 ) { stp[i] = (Struct){ 42, 42.5 }; }
     192        printf( "CFA array align_alloc\n" );
     193        for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
     194        printf( "\n" );
     195    free( stp );
     196
     197    stp = align_alloc( Alignment, dim, fill );                  // CFA array memalign, fill
     198        assert( (uintptr_t)stp % Alignment == 0 );
     199        printf( "CFA array align_alloc, fill\n" );
     200        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); }
    181201        printf( "\n" );
    182202    free( stp );
     
    186206        printf( "\n" );
    187207
    188     stp = memset( &st, '\xff' );                                                // CFA memset, type safe
    189         printf( "CFA memset %x %g\n", st.x, st.y );
    190     stp = memcpy( &st1, &st );                                                  // CFA memcpy, type safe
    191         printf( "CFA memcpy %x %g\n", st1.x, st1.y );
     208    memset( &st, fill );                                                                // CFA memset, type safe
     209        printf( "CFA memset %#x %a\n", st.x, st.y );
     210    memcpy( &st1, &st );                                                                // CFA memcpy, type safe
     211        printf( "CFA memcpy %#x %a\n", st1.x, st1.y );
    192212
    193213
     
    195215        printf( "\n" );
    196216
    197     stp = amemset( sta, dim, '\xff' );                                  // CFA array memset, type safe
     217    memset( sta, dim, fill );                                                   // CFA array memset, type safe
    198218        printf( "CFA array memset\n" );
    199         for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", sta[i].x, sta[i].y ); sta[i].x = 0Xdeadbeef, sta[i].y = -17.2; }
    200         printf( "\n" );
    201 
    202     stp = amemcpy( sta1, sta, dim );                                    // CFA array memcpy, type safe
     219        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta[i].x, sta[i].y ); }
     220        printf( "\n" );
     221
     222    memcpy( sta1, sta, dim );                                                   // CFA array memcpy, type safe
    203223        printf( "CFA memcpy\n" );
    204         for ( int i = 0; i < dim; i += 1 ) { printf( "%x %g, ", sta1[i].x, sta1[i].y ); sta1[i].x = 0Xdeadbeef, sta1[i].y = -17.2; }
     224        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta1[i].x, sta1[i].y ); }
     225        printf( "\n" );
     226
     227
     228        // new, non-array types
     229        printf( "\n" );
     230
     231        stp = new( 42, 42.5 );
     232        stp1 = new( 42, 42.5 );
     233        printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y );
     234        delete( stp, stp1 );
     235
     236        // new, array types
     237        stp = anew( dim, 42, 42.5 );
     238        printf( "CFA array new initialize\n" );
     239        for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
     240        printf( "\n" );
     241        stp1 = anew( dim, 42, 42.5 );
     242        for ( int i = 0; i < dim; i += 1 ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
     243        printf( "\n" );
     244        adelete( dim, stp, dim, stp1 );
     245
     246        // extras
    205247        printf( "\n" );
    206248
     
    211253    p = foo( bar( baz( malloc(), 0 ), 0 ), 0 );
    212254        *p = 0xdeadbeef;
    213         printf( "CFA deep malloc %x\n", *p );
     255        printf( "CFA deep malloc %#x\n", *p );
    214256    free( p );
    215257
    216258        stp = malloc();
    217259        printf( "\nSHOULD FAIL\n" );
    218     p = malloc( stp, dim * sizeof(*stp) );
     260    p = alloc( stp, dim * sizeof(*stp) );
    219261    p = memset( stp, 10 );
    220262    p = memcpy( &st1, &st );
Note: See TracChangeset for help on using the changeset viewer.