Changes in / [49c9773:b1d4d60]


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r49c9773 rb1d4d60  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Jun  1 22:46:09 2017
    14 %% Update Count     : 2126
     13%% Last Modified On : Tue May 30 11:45:46 2017
     14%% Update Count     : 2098
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    52425242\begin{description}
    52435243\item[fill]
    5244 after allocation the storage is filled with a specified character.
     5244after allocation the storage is or is not filled with a specified character.
    52455245\item[resize]
    52465246an existing allocation is decreased or increased in size.
    52475247In either case, new storage may or may not be allocated and, if there is a new allocation, as much data from the existing allocation is copied.
    5248 For an increase in storage size, new storage after the copied data may be filled.
     5248For an increase in storage size, new storage after the copied data may or may not be filled.
    52495249\item[alignment]
    52505250an allocation starts on a specified memory boundary, e.g., an address multiple of 64 or 128 for cache-line purposes.
    52515251\item[array]
    52525252the allocation size is scaled to the specified number of array elements.
    5253 An array may be filled, resized, or aligned.
     5253An array may or not be filled, resized, or aligned.
    52545254\end{description}
    5255 The table shows allocation routines supporting different combinations of storage-management capabilities:
     5255
     5256The following table show the allocation routines supporting different combinations of storage-management capabilities:
    52565257\begin{center}
    5257 \begin{tabular}{@{}lr|l|l|l|l@{}}
    5258                 &                                       & \multicolumn{1}{c|}{fill}     & resize        & alignment     & array \\
     5258\begin{tabular}{@{}r|l|l|l|l@{}}
     5259                                        & fill                          & resize        & alignment     & array \\
    52595260\hline
    5260 C               & ©malloc©                      & no                    & no            & no            & no    \\
    5261                 & ©calloc©                      & yes (0 only)  & no            & no            & yes   \\
    5262                 & ©realloc©                     & no/copy               & yes           & no            & no    \\
    5263                 & ©memalign©            & no                    & no            & yes           & no    \\
    5264                 & ©posix_memalign©      & no                    & no            & yes           & no    \\
    5265 C11             & ©aligned_alloc©       & no                    & no            & yes           & no    \\
    5266 \CFA    & ©alloc©                       & no/copy/yes   & no/yes        & no            & yes   \\
    5267                 & ©align_alloc©         & no/yes                & no            & yes           & yes   \\
     5261©malloc©                        & no/yes                        & no/yes        & no            & no    \\
     5262©amalloc©                       & no/copy data/yes      & no/yes        & no            & yes   \\
     5263©calloc©                        & yes (0 only)          & no            & no            & yes   \\
     5264©realloc©                       & no/copy data          & yes           & no            & no    \\
     5265©memalign©                      & no/yes                        & no            & yes           & no    \\
     5266©amemalign©                     & no/yes                        & no            & yes           & yes   \\
     5267©align_alloc©           & no                            & no            & yes           & no    \\
     5268©posix_memalign©        & no                            & no            & yes           & no    \\
    52685269\end{tabular}
    52695270\end{center}
     5271% When ©amalloc© resizes and fills, the space after the copied data from the source is set to the fill character.
    52705272It is impossible to resize with alignment because the underlying ©realloc© allocates storage if more space is needed, and it does not honour alignment from the original allocation.
    52715273
    52725274\leavevmode
    52735275\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    5274 // C unsafe allocation
    5275 extern "C" { void * mallac( size_t size ); }§\indexc{memset}§
    5276 extern "C" { void * calloc( size_t dim, size_t size ); }§\indexc{calloc}§
    5277 extern "C" { void * realloc( void * ptr, size_t size ); }§\indexc{realloc}§
    5278 extern "C" { void * memalign( size_t align, size_t size ); }§\indexc{memalign}§
    5279 extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); }§\indexc{posix_memalign}§
    5280 
    5281 // §\CFA§ safe equivalents, i.e., implicit size specification
    5282 forall( dtype T | sized(T) ) T * malloc( void );
    5283 forall( dtype T | sized(T) ) T * calloc( size_t dim );
    5284 forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );
    5285 forall( dtype T | sized(T) ) T * memalign( size_t align );
    5286 forall( dtype T | sized(T) ) T * aligned_alloc( size_t align );
    5287 forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align );
    5288 
    5289 // §\CFA§ safe general allocation, fill, resize, array
    5290 forall( dtype T | sized(T) ) T * alloc( void );§\indexc{alloc}§
    5291 forall( dtype T | sized(T) ) T * alloc( char fill );
    5292 forall( dtype T | sized(T) ) T * alloc( size_t dim );
    5293 forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill );
    5294 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim );
    5295 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    5296 
    5297 // §\CFA§ safe general allocation, align, fill, array
    5298 forall( dtype T | sized(T) ) T * align_alloc( size_t align );
    5299 forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill );
    5300 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim );
    5301 forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill );
    5302 
    5303 // C unsafe initialization/copy
    5304 extern "C" { void * memset( void * dest, int c, size_t size ); }
    5305 extern "C" { void * memcpy( void * dest, const void * src, size_t size ); }
    5306 
    5307 // §\CFA§ safe initialization/copy
     5276// allocation, non-array types
     5277forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§
     5278forall( dtype T | sized(T) ) T * malloc( char fill );
     5279
     5280// allocation, array types
     5281forall( dtype T | sized(T) ) T * calloc( size_t dim );§\indexc{cmalloc}§
     5282forall( dtype T | sized(T) ) T * amalloc( size_t dim );§\indexc{amalloc}§  // alternate name for calloc
     5283forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill );
     5284
     5285// resize, non-array types
     5286forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{realloc}§
     5287forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
     5288forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );  // alternate name for realloc
     5289forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, char fill );
     5290
     5291// resize, array types
     5292forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim );
     5293forall( dtype T | sized(T) ) T * amalloc( T * ptr, size_t dim, char fill );
     5294
     5295// alignment, non-array types
     5296forall( dtype T | sized(T) ) T * memalign( size_t alignment );§\indexc{memalign}§
     5297forall( dtype T | sized(T) ) T * memalign( size_t alignment, char fill );
     5298forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{aligned_alloc}§
     5299forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );§\indexc{posix_memalign}§
     5300
     5301// alignment, array types
     5302forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim );§\indexc{amemalign}§
     5303forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill );
     5304
     5305// data, non-array types
    53085306forall( dtype T | sized(T) ) T * memset( T * dest, char c );§\indexc{memset}§
    53095307forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
    53105308
    5311 // §\CFA§ safe initialization/copy array
    5312 forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c );
    5313 forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim );
    5314 
    5315 // §\CFA§ allocation/deallocation and constructor/destructor
    5316 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );§\indexc{new}§
     5309// data, array types
     5310forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c );§\indexc{amemset}§
     5311forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim );§\indexc{amemcpy}§
     5312
     5313// allocation/deallocation and constructor/destructor
     5314forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );§\indexc{new}§
    53175315forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );§\indexc{delete}§
    5318 forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    5319   void delete( T * ptr, Params rest );
    5320 
    5321 // §\CFA§ allocation/deallocation and constructor/destructor, array
    5322 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
    5323 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    5324 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
    5325   void adelete( size_t dim, T arr[], Params rest );
     5316forall( dtype T, ttype Params | { void ^?{}( T * ); void delete(Params); } ) void delete( T * ptr, Params rest );
    53265317\end{cfa}
    53275318
  • src/Parser/lex.ll

    r49c9773 rb1d4d60  
    55 * file "LICENCE" distributed with Cforall.
    66 *
    7  * lex.ll --
     7 * lex.l --
    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 : Tue May 30 22:00:48 2017
    13  * Update Count     : 527
     12 * Last Modified On : Mon May 22 07:46:30 2017
     13 * Update Count     : 525
    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

    r49c9773 rb1d4d60  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  1 22:46:43 2017
    13 // Update Count     : 216
     12// Last Modified On : Tue May 30 09:07:35 2017
     13// Update Count     : 164
    1414//
    1515
     
    2828//---------------------------------------
    2929
     30extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
     31
    3032// allocation, non-array types
    3133static inline forall( dtype T | sized(T) ) T * malloc( void ) {
     
    3335        return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    3436} // malloc
    35 
    36 extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
     37static inline forall( dtype T | sized(T) ) T * malloc( char fill ) {
     38        //printf( "X2\n" );
     39        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
     40    return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
     41} // malloc
     42
     43// allocation, array types
     44extern "C" { void * calloc( size_t dim, size_t size ); } // use default C routine for void *
    3745static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
    38         //printf( "X2\n" );
     46        //printf( "X3\n" );
    3947        return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
    4048}
    41 
    42 extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void *
     49static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim ) { // alternative name
     50        //printf( "X4\n" );
     51        return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     52} // amalloc
     53static inline forall( dtype T | sized(T) ) T * amalloc( size_t dim, char fill ) { // alternative name
     54        //printf( "X5\n" );
     55        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     56    return memset( ptr, (int)fill, dim * sizeof(T) );
     57} // amalloc
     58
     59// resize, non-array types
     60extern "C" { void * realloc( void * ptr, size_t size ); } // use default C routine for void *
    4361static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
    44         //printf( "X3\n" );
     62        //printf( "X5.5\n" );
    4563        return (T *)(void *)realloc( (void *)ptr, size );
    4664}
    47 
    48 extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
    49 static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) {
    50         //printf( "X4\n" );
    51         return (T *)memalign( align, sizeof(T) );
     65forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill );
     66static 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
     70static 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
     76static 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
     80static 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
     86extern "C" { void * memalign( size_t alignment, size_t size ); } // use default C routine for void *
     87static inline forall( dtype T | sized(T) ) T * memalign( size_t alignment ) {
     88        //printf( "X11\n" );
     89        return (T *)memalign( alignment, sizeof(T) );
    5290} // memalign
    53 
    54 static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) {
    55         //printf( "X5\n" );
    56         return (T *)memalign( align, sizeof(T) );
     91static 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) );
     94    return memset( ptr, (int)fill, sizeof(T) );
     95} // memalign
     96static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment ) {
     97        //printf( "X13\n" );
     98        return (T *)memalign( alignment, sizeof(T) );
    5799} // aligned_alloc
    58 
    59 extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void *
    60 static 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) );
     100extern "C" { int posix_memalign( void ** ptr, size_t alignment, size_t size ); } // use default C routine for void *
     101static 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) );
    63104} // posix_memalign
    64105
    65 
    66 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
    67 
    68 static 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
    72 static inline forall( dtype T | sized(T) ) T * alloc( char fill ) {
    73         //printf( "X8\n" );
    74         T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    75     return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
    76 } // alloc
    77 
    78 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) {
    79         //printf( "X9\n" );
    80         return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    81 } // alloc
    82 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) {
    83         //printf( "X10\n" );
    84         T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     106// alignment, array types
     107static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim ) {
     108        //printf( "X15\n" );
     109        return (T *)memalign( alignment, dim * sizeof(T) );
     110} // amemalign
     111static inline forall( dtype T | sized(T) ) T * amemalign( size_t alignment, size_t dim, char fill ) {
     112        //printf( "X16\n" );
     113    T * ptr = (T *)memalign( alignment, dim * sizeof(T) );
    85114    return memset( ptr, (int)fill, dim * sizeof(T) );
    86 } // alloc
    87 
    88 static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    89         //printf( "X11\n" );
    90         return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    91 } // alloc
    92 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    93 
    94 static 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
    98 static 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) );
    101     return memset( ptr, (int)fill, sizeof(T) );
    102 } // align_alloc
    103 
    104 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) {
    105         //printf( "X15\n" );
    106         return (T *)memalign( align, dim * sizeof(T) );
    107 } // align_alloc
    108 static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) {
    109         //printf( "X16\n" );
    110     T * ptr = (T *)memalign( align, dim * sizeof(T) );
    111     return memset( ptr, (int)fill, dim * sizeof(T) );
    112 } // align_alloc
    113 
     115} // amemalign
    114116
    115117// data, non-array types
     
    125127
    126128// data, array types
    127 static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
     129static inline forall( dtype T | sized(T) ) T * amemset( T * dest, size_t dim, char c ) {
    128130        //printf( "X19\n" );
    129131        return memset( dest, c, dim * sizeof(T) );
    130 } // memset
    131 static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
     132} // amemset
     133static inline forall( dtype T | sized(T) ) T * amemcpy( T * dest, const T * src, size_t dim ) {
    132134        //printf( "X20\n" );
    133         return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
    134 } // memcpy
    135 
    136 // allocation/deallocation and constructor/destructor, non-array types
    137 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * new( Params p );
     135        return memcpy( dest, src, dim * sizeof(T) );
     136} // amemcpy
     137
     138// allocation/deallocation and constructor/destructor
     139forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
    138140forall( dtype T | { void ^?{}( T * ); } ) void delete( T * ptr );
    139141forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    140 
    141 // allocation/deallocation and constructor/destructor, array types
    142 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } ) T * anew( size_t dim, Params p );
    143 forall( dtype T | sized(T) | { void ^?{}( T * ); } ) void adelete( size_t dim, T arr[] );
    144 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } ) void adelete( size_t dim, T arr[], Params rest );
    145142
    146143//---------------------------------------
  • src/libcfa/stdlib.c

    r49c9773 rb1d4d60  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  1 21:52:57 2017
    13 // Update Count     : 280
     12// Last Modified On : Tue May 30 09:07:56 2017
     13// Update Count     : 237
    1414//
    1515
     
    2828
    2929// resize, non-array types
    30 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ) {
     30forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, char fill ) { // alternative realloc with fill value
     31        //printf( "X6\n" );
    3132        size_t olen = malloc_usable_size( ptr );                        // current allocation
    32     char * nptr = (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     33    char * nptr = (void *)realloc( (void *)ptr, size ); // C realloc
    3334        size_t nlen = malloc_usable_size( nptr );                       // new allocation
    3435        if ( nlen > olen ) {                                                            // larger ?
     
    3637        } //
    3738    return (T *)nptr;
    38 } // alloc
    39 
    40 // allocation/deallocation and constructor/destructor, non-array types
    41 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
     39} // realloc
     40
     41// allocation/deallocation and constructor/destructor
     42forall( dtype T, ttype Params | sized(T) | { void ?{}( T *, Params ); } )
    4243T * new( Params p ) {
    43         return (malloc()){ p };                                                         // run constructor
     44        return ((T *)malloc()){ p };
    4445} // new
    4546
    4647forall( dtype T | { void ^?{}( T * ); } )
    4748void delete( T * ptr ) {
    48         if ( ptr ) {                                                                            // ignore null
     49        if ( ptr ) {
    4950                ^ptr{};                                                                                 // run destructor
    5051                free( ptr );
     
    5455forall( dtype T, ttype Params | { void ^?{}( T * ); void delete( Params ); } )
    5556void delete( T * ptr, Params rest ) {
    56         if ( ptr ) {                                                                            // ignore null
     57        if ( ptr ) {
    5758                ^ptr{};                                                                                 // run destructor
    5859                free( ptr );
     
    6061        delete( rest );
    6162} // delete
    62 
    63 
    64 // allocation/deallocation and constructor/destructor, array types
    65 forall( dtype T | sized(T), ttype Params | { void ?{}( T *, Params ); } )
    66 T * 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 
    74 forall( dtype T | sized(T) | { void ^?{}( T * ); } )
    75 void 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 
    84 forall( dtype T | sized(T) | { void ^?{}( T * ); }, ttype Params | { void adelete( Params ); } )
    85 void 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
    9463
    9564//---------------------------------------
  • src/tests/.expect/alloc.txt

    r49c9773 rb1d4d60  
    1 C   malloc 0xdeadbeef
    2 CFA malloc 0xdeadbeef
    3 CFA alloc 0xdeadbeef
    4 CFA alloc, fill 01010101
     1C   malloc deadbeef
     2CFA malloc 0
     3CFA malloc, fill 01010101
    54
    6 C   array calloc, fill 0
     5C   calloc
    760 0 0 0 0 0 0 0 0 0
    8 CFA array calloc, fill 0
     7CFA calloc
    980 0 0 0 0 0 0 0 0 0
    10 CFA array alloc, no fill
    11 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    12 CFA array alloc, fill 0x1
    13 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     9CFA array malloc
     100 0 deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     11CFA array malloc
     121010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
    1413
    15 C   realloc 40
    16 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    17 CFA realloc 88
    18 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     14C   realloc
     15deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     16CFA realloc
     17deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
     18CFA realloc
     19deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     20CFA resize malloc
     21deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     22CFA resize malloc, fill
     23deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
     24CFA resize malloc, fill
     25deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    1926
    20 CFA resize alloc 40
    21 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    22 CFA resize array alloc 88
    23 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    24 CFA resize array alloc 40
    25 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    26 CFA resize array alloc 40, fill
    27 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    28 CFA resize array alloc 88, fill
    29 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    30 CFA resize array alloc 40, fill
    31 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     27CFA resize array malloc
     28deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 0 0 0 0 0 0 0 0 0 0
     29CFA resize array malloc
     30deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
     31CFA resize array malloc, fill
     32deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101 1010101
     33CFA resize array malloc, fill
     34deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef deadbeef
    3235
    33 C   memalign 42 42.5
     36CFA aligned_alloc 42 42.5
    3437CFA memalign 42 42.5
    3538CFA posix_memalign 42 42.5
    36 CFA posix_memalign 42 42.5
    37 CFA aligned_alloc 42 42.5
    38 CFA align_alloc 42 42.5
    39 CFA align_alloc fill 0x1010101 0x1.1010101010101p-1007
     39CFA memalign fill 16843009 7.7486e-304
    4040
    41 CFA array align_alloc
    42 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, 42 42.5,
    43 CFA array align_alloc, fill
    44 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, 0x1010101 0x1.1010101010101p-1007,
     41CFA memalign array
     420 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,
     43CFA memalign array
     441010101 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,
    4545
    46 CFA memset 0x1010101 0x1.1010101010101p-1007
    47 CFA memcpy 0x1010101 0x1.1010101010101p-1007
     46CFA memset ffffffff -nan
     47CFA memcpy ffffffff -nan
    4848
    4949CFA array memset
    50 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, 0x1010101 0x1.1010101010101p-1007,
     50ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan, ffffffff -nan,
    5151CFA memcpy
    52 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, 0x1010101 0x1.1010101010101p-1007,
    53 
    54 CFA new initialize
    55 42 42.5 42 42.5
    56 CFA array new initialize
    57 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, 42 42.5,
    58 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, 42 42.5,
    59 
     52deadbeef -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,
    6053pointer arithmetic 0
    61 CFA deep malloc 0xdeadbeef
     54CFA deep malloc deadbeef
    6255
    6356SHOULD FAIL
  • src/tests/alloc.c

    r49c9773 rb1d4d60  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  1 21:33:49 2017
    13 // Update Count     : 315
     12// Last Modified On : Mon May 29 11:33:15 2017
     13// Update Count     : 228
    1414//
    1515
     
    1818#include <malloc.h>                                                                             // malloc_usable_size
    1919#include <stdint.h>                                                                             // uintptr_t
    20 #include <stdlib.h>                                                                             // posix_memalign
    2120} // extern
    2221#include <fstream>
     
    2928int main( void ) {
    3029    size_t dim = 10;
     30    struct S { int x; double y; } * s;
    3131    int * p;
    32         char fill = '\1';
    3332
    3433        // allocation, non-array types
     
    3635    p = (void *)malloc( sizeof(*p) );                                   // C malloc, type unsafe
    3736        *p = 0xdeadbeef;
    38         printf( "C   malloc %#x\n", *p );
     37        printf( "C   malloc %x\n", *p );
    3938    free( p );
    4039
    4140    p = malloc();                                                                               // CFA malloc, type safe
    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 );
     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 );
    5346
    5447
     
    5750
    5851    p = calloc( dim, sizeof( *p ) );                                    // C array calloc, type unsafe
    59         printf( "C   array calloc, fill 0\n" );
    60         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     52        printf( "C   calloc\n" );
     53        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    6154        printf( "\n" );
    6255    free( p );
    6356
    6457    p = calloc( dim );                                                                  // CFA array calloc, type safe
    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] ); }
     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; }
    8072        printf( "\n" );
    8173        // do not free
     
    8577        printf( "\n" );
    8678
    87     p = (void *)realloc( p, dim * sizeof(*p) );                 // C realloc
    88         for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    89         printf( "C   realloc %ld\n", malloc_usable_size( p ) );
    90         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     79    p = (void *)realloc( p, dim * sizeof(*p) );                 // CFA realloc
     80        printf( "C   realloc\n" );
     81        for ( int i = 0; i < dim; i += 1 ) { printf( "%x ", p[i] ); p[i] = 0Xdeadbeef; }
    9182        printf( "\n" );
    9283
    9384    p = realloc( p, 2 * dim * sizeof(*p) );                             // CFA realloc
    94         for ( int i = dim; i < 2 * dim; i += 1 ) { p[i] = 0x1010101; }
    95         printf( "CFA realloc %ld\n", malloc_usable_size( p ) );
    96         for ( int i = 0; i < 2 * dim; i += 1 ) { printf( "%#x ", p[i] ); }
     85        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; }
    97107        printf( "\n" );
    98108        // do not free
     
    102112        printf( "\n" );
    103113
    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 %ld\n", malloc_usable_size( p ) );
    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 %ld\n", malloc_usable_size( p ) );
    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 %ld\n", malloc_usable_size( p ) );
    118         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
    119         printf( "\n" );
    120 
     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; }
    121132        free( p );
    122         p = 0;
    123 
    124     p = alloc( p, dim, fill );                                                  // CFA array alloc, fill
    125         printf( "CFA resize array alloc %ld, fill\n", malloc_usable_size( p ) );
    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 %ld, fill\n", malloc_usable_size( p ) );
    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 %ld, fill\n", malloc_usable_size( p ) );
    136         for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] );; }
    137         printf( "\n" );
    138         free( p );
    139 
     133        printf( "\n" );
    140134
    141135    struct Struct { int x; double y; };
    142     Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
     136    Struct st, st1, sta[dim], sta1[dim], * stp;
     137
    143138
    144139        // alignment, non-array types
    145140        printf( "\n" );
     141
    146142        enum { Alignment = 128 };
    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
     143    stp = aligned_alloc( Alignment );                                   // CFA aligned_alloc
     144        *stp = (Struct){ 42, 42.5 };
     145        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 };
    154151        assert( (uintptr_t)stp % Alignment == 0 );
    155152        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
    159         *stp = (Struct){ 42, 42.5 };
    160         assert( (uintptr_t)stp % Alignment == 0 );
    161         printf( "CFA posix_memalign %d %g\n", stp->x, stp->y );
    162153    free( stp );
    163154
     
    168159    free( stp );
    169160
    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 );
     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 );
    183164    free( stp );
    184165
     
    187168        printf( "\n" );
    188169
    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 ); }
     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; }
    201181        printf( "\n" );
    202182    free( stp );
     
    206186        printf( "\n" );
    207187
    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 );
     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 );
    212192
    213193
     
    215195        printf( "\n" );
    216196
    217     memset( sta, dim, fill );                                                   // CFA array memset, type safe
     197    stp = amemset( sta, dim, '\xff' );                                  // CFA array memset, type safe
    218198        printf( "CFA array memset\n" );
    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
     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
    223203        printf( "CFA memcpy\n" );
    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
     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; }
    247205        printf( "\n" );
    248206
     
    253211    p = foo( bar( baz( malloc(), 0 ), 0 ), 0 );
    254212        *p = 0xdeadbeef;
    255         printf( "CFA deep malloc %#x\n", *p );
     213        printf( "CFA deep malloc %x\n", *p );
    256214    free( p );
    257215
    258216        stp = malloc();
    259217        printf( "\nSHOULD FAIL\n" );
    260     p = alloc( stp, dim * sizeof(*stp) );
     218    p = malloc( stp, dim * sizeof(*stp) );
    261219    p = memset( stp, 10 );
    262220    p = memcpy( &st1, &st );
Note: See TracChangeset for help on using the changeset viewer.