Changeset 58e97d9


Ignore:
Timestamp:
Apr 24, 2022, 10:45:07 AM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
19e5d65d
Parents:
31a5f418
git-author:
Peter A. Buhr <pabuhr@…> (04/24/22 10:44:01)
git-committer:
Peter A. Buhr <pabuhr@…> (04/24/22 10:45:07)
Message:

formatting

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r31a5f418 r58e97d9  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 12 17:22:25 2022
    13 // Update Count     : 643
     12// Last Modified On : Mon Apr 18 17:57:36 2022
     13// Update Count     : 644
    1414//
    1515
     
    209209
    210210        forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    211                 T * alloc_internal$( void *       , T *        , size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
     211                T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest ) {
    212212                return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest);
    213213                }
    214214
    215                 T * alloc_internal$( void *        , T *        , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) {
     215                T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest ) {
    216216                return alloc_internal$( (void*)0p, Realloc, Align, Dim, Fill, rest);
    217217                }
    218218
    219                 T * alloc_internal$( void * Resize, T * Realloc, size_t      , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) {
     219                T * alloc_internal$( void * Resize, T * Realloc, size_t, size_t Dim, S_fill(T) Fill, T_align Align, TT rest ) {
    220220                return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest);
    221221                }
    222222
    223                 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T)     , S_fill(T) Fill, TT rest) {
    224                 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest);
     223                T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T), S_fill(T) Fill, TT rest ) {
     224                return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest );
    225225                }
    226226
    227227            T * alloc( TT all ) {
    228                 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);
     228                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all );
    229229            }
    230230
    231231            T * alloc( size_t dim, TT all ) {
    232                 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
     232                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all );
    233233            }
    234234        } // distribution TT
  • tests/alloc.cfa

    r31a5f418 r58e97d9  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 12 10:02:18 2020
    13 // Update Count     : 432
     12// Last Modified On : Mon Apr 18 17:13:52 2022
     13// Update Count     : 433
    1414//
    1515
     
    4747        free( ip );
    4848
    49         ip = alloc( fill`fill );                                                                // CFA alloc, fill
     49        ip = alloc( fill`fill );                                                        // CFA alloc, fill
    5050        printf( "CFA alloc, fill %08x\n", *ip );
    5151        free( ip );
     
    8484        free( ip );
    8585
    86         ip = alloc( 2 * dim, ((int)0xdeadbeef)`fill );                          // CFA array alloc, fill
     86        ip = alloc( 2 * dim, ((int)0xdeadbeef)`fill );          // CFA array alloc, fill
    8787        printf( "CFA array alloc, fill %#hhx\n", 0xdeadbeef );
    8888        for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); }
     
    9090        // do not free
    9191
    92         ip1 = alloc( 2 * dim, [ip, 2 * dim]`fill );                             // CFA array alloc, fill
     92        ip1 = alloc( 2 * dim, [ip, 2 * dim]`fill );                     // CFA array alloc, fill
    9393        printf( "CFA array alloc, fill from array\n" );
    9494        for ( i; 2 * dim ) { printf( "%#x %#x, ", ip[i], ip1[i] ); }
     
    117117        printf( "\n" );
    118118
    119         ip = alloc( dim, ip`realloc );                                                          // CFA realloc array alloc
     119        ip = alloc( dim, ip`realloc );                                          // CFA realloc array alloc
    120120        for ( i; dim ) { ip[i] = 0xdeadbeef; }
    121121        printf( "CFA realloc array alloc\n" );
     
    124124        // do not free
    125125
    126         ip = alloc( 2 * dim, ip`realloc );                                                      // CFA realloc array alloc
     126        ip = alloc( 2 * dim, ip`realloc );                                      // CFA realloc array alloc
    127127        for ( i; dim ~ 2 * dim ) { ip[i] = 0x1010101; }         // fill upper part
    128128        printf( "CFA realloc array alloc\n" );
     
    131131        // do not free
    132132
    133         ip = alloc( dim, ip`realloc );                                                          // CFA realloc array alloc
     133        ip = alloc( dim, ip`realloc );                                          // CFA realloc array alloc
    134134        printf( "CFA realloc array alloc\n" );
    135135        for ( i; dim ) { printf( "%#x ", ip[i] ); }
     
    137137        // do not free
    138138
    139         ip = alloc( 3 * dim, ip`realloc, fill`fill );                           // CFA realloc array alloc, fill
     139        ip = alloc( 3 * dim, ip`realloc, fill`fill );           // CFA realloc array alloc, fill
    140140        printf( "CFA realloc array alloc, fill\n" );
    141141        for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); }
     
    143143        // do not free
    144144
    145         ip = alloc( dim, ip`realloc, fill`fill );                                       // CFA realloc array alloc, fill
     145        ip = alloc( dim, ip`realloc, fill`fill );                       // CFA realloc array alloc, fill
    146146        printf( "CFA realloc array alloc, fill\n" );
    147147        for ( i; dim ) { printf( "%#x ", ip[i] ); }
     
    149149        // do not free
    150150
    151         ip = alloc( 3 * dim, ip`realloc, fill`fill );                           // CFA realloc array alloc, fill
     151        ip = alloc( 3 * dim, ip`realloc, fill`fill );           // CFA realloc array alloc, fill
    152152        printf( "CFA realloc array alloc, fill\n" );
    153153        for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); }
     
    155155        // do not free
    156156#if 0 // FIX ME
    157         ip = alloc( 5 * dim, ip`realloc, 5`fill );                                      // CFA realloc array alloc, 5
     157        ip = alloc( 5 * dim, ip`realloc, 5`fill );                      // CFA realloc array alloc, 5
    158158        printf( "CFA realloc array alloc, 5\n" );
    159159        for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); }
     
    161161        // do not free
    162162
    163         ip = alloc( dim, ip`realloc, 5`fill );                                          // CFA realloc array alloc, 5
     163        ip = alloc( dim, ip`realloc, 5`fill );                          // CFA realloc array alloc, 5
    164164        printf( "CFA realloc array alloc, 5\n" );
    165165        for ( i; dim ) { printf( "%#x ", ip[i] ); }
     
    167167        // do not free
    168168
    169         ip = alloc( 5 * dim, ip`realloc, 5`fill );                                      // CFA realloc array alloc, 5
     169        ip = alloc( 5 * dim, ip`realloc, 5`fill );                      // CFA realloc array alloc, 5
    170170        printf( "CFA realloc array alloc, 5\n" );
    171171        for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); }
     
    210210        int const_count, dest_count;
    211211        struct Struct { int x; double y; };
    212         void  ?{}( Struct & a ) {                                       // construct
     212        void  ?{}( Struct & a ) {                                                       // construct
    213213                a.[ x, y ] = [ -1, -1.0 ];
    214214        }
    215         void  ?{}( Struct & a, int x, double y ) {      // initialize
     215        void  ?{}( Struct & a, int x, double y ) {                      // initialize
    216216                a.[ x, y ] = [ x, y ];
    217217                const_count++;
    218218        }
    219         void ^?{}( Struct & a ) {  dest_count++; }      // destruct
     219        void ^?{}( Struct & a ) {  dest_count++; }                      // destruct
    220220        Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
    221221
     
    266266        // do not free
    267267
    268         stp = &(*alloc( stp`realloc, 4096`align )){ 42, 42.5 };         // CFA realign
     268        stp = &(*alloc( stp`realloc, 4096`align )){ 42, 42.5 }; // CFA realign
    269269        assert( (uintptr_t)stp % 4096 == 0 );
    270270        printf( "CFA alloc_align %d %g\n", stp->x, stp->y );
     
    304304        free( stp1 );
    305305
    306         stp = alloc( dim, stp`realloc, 4096`align );                            // CFA aligned realloc array
     306        stp = alloc( dim, stp`realloc, 4096`align );            // CFA aligned realloc array
    307307        assert( (uintptr_t)stp % 4096 == 0 );
    308308        for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; }
     
    340340        const_count = dest_count = 0;
    341341        stp = new( 42, 42.5 );
    342         assert( const_count == 1 && dest_count == 0 );                                          // assertion for testing
     342        assert( const_count == 1 && dest_count == 0 );          // assertion for testing
    343343        stp1 = new( 42, 42.5 );
    344         assert( const_count == 2 && dest_count == 0 );                                          // assertion for testing
     344        assert( const_count == 2 && dest_count == 0 );          // assertion for testing
    345345
    346346        printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y );
    347347        delete( stp, stp1 );
    348         assert( const_count == 2 && dest_count == 2 );                                          // assertion for testing
     348        assert( const_count == 2 && dest_count == 2 );          // assertion for testing
    349349
    350350        // new, array types
    351351        stp = anew( dim, 42, 42.5 );
    352         assert( const_count == 2 + dim && dest_count == 2 );                            // assertion for testing
     352        assert( const_count == 2 + dim && dest_count == 2 ); // assertion for testing
    353353        printf( "CFA array new initialize\n" );
    354354        for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
     
    356356
    357357        stp1 = anew( dim, 42, 42.5 );
    358         assert( const_count == 2 + 2 * dim && dest_count == 2 );                        // assertion for testing
     358        assert( const_count == 2 + 2 * dim && dest_count == 2 ); // assertion for testing
    359359        for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
    360360        printf( "\n" );
    361361        adelete( stp, stp1 );
    362         assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim);       // assertion for testing
     362        assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing
    363363
    364364        // extras
     
    373373        printf( "CFA deep malloc %#x\n", *ip );
    374374
    375         dp = alloc(5.0`fill); // just for testing multiple free
     375        dp = alloc(5.0`fill);                                                           // just for testing multiple free
    376376        assert(*dp == 5.0);
    377377        free( ip, dp, 0p );
Note: See TracChangeset for help on using the changeset viewer.