Changes in / [3d02803:78bc398]


Ignore:
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r3d02803 r78bc398  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep 24 18:14:20 2025
    13 // Update Count     : 760
     12// Last Modified On : Sun Apr 21 16:17:22 2024
     13// Update Count     : 700
    1414//
    1515
     
    3333forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } )
    3434T * anew( size_t dim, Parms p ) {
    35         T * arr;
    36         if ( sizeof( T ) == 0 ) {                                                       // empty element size ?
    37                 arr = (T *)(size_t *)alloc();                                   // create fake array
    38                 *((size_t *)arr) = dim;                                                 // remember dimension
    39         } else arr = alloc( dim );
     35        T * arr = alloc( dim );
    4036        for ( i; dim ) {
    4137                (arr[i]){ p };                                                                  // run constructor
     
    4642forall( T & | sized(T) | { void ^?{}( T & ); } )
    4743void adelete( T arr[] ) {
    48   if ( arr == 0p ) return;                                                              // 0p ? special case
    49         size_t dim = sizeof( T ) == 0 ? (size_t)(*(size_t *)arr) : malloc_size( arr ) / sizeof( T ); // compute dimension
    50         for ( i; 0 -~= dim - 1 ) {                                                      // reverse allocation order, must be signed
    51                 ^(arr[i]){};                                                                    // run destructor
    52         } // for
    53         if ( sizeof( T ) == 0 ) free( (size_t *)arr ); else free( arr );
     44        if ( arr ) {                                                                            // ignore null
     45                size_t dim = malloc_size( arr ) / sizeof( T );
     46                for ( i; 0 -~= dim - 1 ) {                                              // reverse allocation order, must be unsigned
     47                        ^(arr[i]){};                                                            // run destructor
     48                } // for
     49                free( arr );
     50        } // if
    5451} // adelete
    5552
    5653forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } )
    5754void adelete( T arr[], List rest ) {
    58         adelete( arr );
     55        if ( arr ) {                                                                            // ignore null
     56                size_t dim = malloc_size( arr ) / sizeof( T );
     57                for ( i; 0 -~= dim - 1 ) {                                              // reverse allocation order, must be unsigned
     58                        ^(arr[i]){};                                                            // run destructor
     59                } // for
     60                free( arr );
     61        } // if
    5962        adelete( rest );
    6063} // adelete
     
    6568
    6669bool checkif( const char s[], int (* kind)( int ) ) {
    67         for () {                                                                                        // at least 1 character '\0'
    68           if ( *s == '\0' ) return true;
    69           if ( ! kind( *s ) ) return false;
     70        for () {
     71                if ( *s == '\0' ) return true;
     72                if ( ! kind( *s ) ) return false;
    7073                s += 1;
    7174        } // for
     
    7376
    7477bool checkif( const char s[], int (* kind)( int, locale_t ), locale_t locale ) {
    75         for () {                                                                                        // at least 1 character '\0'
    76           if ( *s == '\0' ) return true;
    77           if ( ! kind( *s, locale ) ) return false;
     78        for () {
     79                if ( *s == '\0' ) return true;
     80                if ( ! kind( *s, locale ) ) return false;
    7881                s += 1;
    7982        } // for
  • tests/.expect/alloc.txt

    r3d02803 r78bc398  
    767642 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,
    777742 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,
    78 ctor
    79 ctor
    80 ctor
    81 ctor
    82 ctor
    83 ctor
    84 ctor
    85 ctor
    86 ctor
    87 ctor
    88 ctor
    89 ctor
    90 ctor
    91 ctor
    92 ctor
    93 dtor
    94 dtor
    95 dtor
    96 dtor
    97 dtor
    98 dtor
    99 dtor
    100 dtor
    101 dtor
    102 dtor
    103 dtor
    104 dtor
    105 dtor
    106 dtor
    107 dtor
    10878
    10979pointer arithmetic 0
  • tests/alloc.cfa

    r3d02803 r78bc398  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep 24 18:21:09 2025
    13 // Update Count     : 493
     12// Last Modified On : Tue Apr 23 14:04:11 2024
     13// Update Count     : 492
    1414//
    1515
     
    362362        assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing
    363363
    364         struct Empty {};
    365         void ?{}( Empty & ) { sout | "ctor"; }
    366         void ^?{}( Empty & ) { sout | "dtor"; }
    367         Empty * ea1 = anew( 5 );
    368         Empty * ea2 = anew( 5 );
    369         Empty * ea3 = anew( 5 );
    370         adelete( ea1, ea2, ea3 );
    371 
    372364        // extras
    373365        sout | nl;
Note: See TracChangeset for help on using the changeset viewer.